// import csv ok for product attribute position
This commit is contained in:
@@ -84,7 +84,8 @@ class AdminImport extends AdminTab
|
||||
$this->available_fields = array(
|
||||
'no' => array('label' => $this->l('Ignore this column')),
|
||||
'id_product' => array('label' => $this->l('Product ID').'*'),
|
||||
'options' => array('label' => $this->l('Options (Group:Value)').'*'),
|
||||
'options' => array('label' => $this->l('Options (Group:Value:Position)').'*',
|
||||
'help' => $this->l('Position of the attribute in the attribute group.')),
|
||||
'reference' => array('label' => $this->l('Reference')),
|
||||
'supplier_reference' => array('label' => $this->l('Supplier reference')),
|
||||
'ean13' => array('label' => $this->l('EAN13')),
|
||||
@@ -952,7 +953,8 @@ class AdminImport extends AdminTab
|
||||
$this->_warnings[] = $image->legend[$defaultLanguageId].(isset($image->id_product) ? ' ('.$image->id_product.')' : '').' '.Tools::displayError('Cannot be saved');
|
||||
$this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '').mysql_error();
|
||||
}
|
||||
} elseif (isset($info['image_position']) && $info['image_position'])
|
||||
}
|
||||
else if (isset($info['image_position']) && $info['image_position'])
|
||||
{
|
||||
$images = $product->getImages($defaultLanguage);
|
||||
|
||||
@@ -968,9 +970,16 @@ class AdminImport extends AdminTab
|
||||
}
|
||||
|
||||
$id_product_attribute = $product->addProductAttribute((float)($info['price']), (float)($info['weight']), 0, (float)($info['ecotax']), (int)($info['quantity']), $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int)($info['default_on']), strval($info['upc']));
|
||||
$id_attribute_group = 0;
|
||||
foreach (explode($fsep, $info['options']) as $option)
|
||||
{
|
||||
list($group, $attribute) = array_map('trim', explode(':', $option));
|
||||
$options = explode(':', $option);
|
||||
list($group, $attribute) = array_map('trim', $options);
|
||||
// if position is filled
|
||||
if (isset($options[2]))
|
||||
$position = $options[2];
|
||||
else
|
||||
$position = false;
|
||||
if (!isset($groups[$group]))
|
||||
{
|
||||
$obj = new AttributeGroup();
|
||||
@@ -985,11 +994,13 @@ class AdminImport extends AdminTab
|
||||
else
|
||||
$this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '');
|
||||
}
|
||||
$id_attribute_group = $groups[$group];
|
||||
if (!isset($attributes[$group.'_'.$attribute]))
|
||||
{
|
||||
$obj = new Attribute();
|
||||
$obj->id_attribute_group = $groups[$group];
|
||||
$obj->name[$defaultLanguage] = str_replace('\n', '', str_replace('\r', '', $attribute));
|
||||
$obj->position = (!$position) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;
|
||||
if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true AND ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
|
||||
{
|
||||
$obj->add();
|
||||
@@ -997,11 +1008,16 @@ class AdminImport extends AdminTab
|
||||
}
|
||||
else
|
||||
$this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '');
|
||||
|
||||
}
|
||||
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'product_attribute_combination (id_attribute, id_product_attribute) VALUES ('.(int)($attributes[$group.'_'.$attribute]).','.(int)($id_product_attribute).')');
|
||||
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'product_attribute_combination (id_attribute, id_product_attribute) VALUES ('.(int)($attributes[$group.'_'.$attribute]).','.(int)$id_product_attribute.')');
|
||||
}
|
||||
}
|
||||
$this->closeCsvFile($handle);
|
||||
|
||||
// after insertion, we clean attribute position
|
||||
$obj = new Attribute();
|
||||
$obj->cleanPositions((int)$id_attribute_group, false);
|
||||
}
|
||||
|
||||
public function customerImport()
|
||||
|
||||
+40
-18
@@ -58,9 +58,9 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
$fields['id_attribute_group'] = (int)($this->id_attribute_group);
|
||||
$fields['id_attribute_group'] = (int)$this->id_attribute_group;
|
||||
$fields['color'] = pSQL($this->color);
|
||||
$fields['position'] = (int)($this->position);
|
||||
$fields['position'] = (int)$this->position;
|
||||
|
||||
return $fields;
|
||||
}
|
||||
@@ -78,20 +78,20 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (($result = Db::getInstance()->ExecuteS('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)($this->id))) === false)
|
||||
if (($result = Db::getInstance()->ExecuteS('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false)
|
||||
return false;
|
||||
$combinationIds = array();
|
||||
if (Db::getInstance()->numRows())
|
||||
{
|
||||
foreach ($result AS $row)
|
||||
$combinationIds[] = (int)($row['id_product_attribute']);
|
||||
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)($this->id)) === false)
|
||||
$combinationIds[] = (int)$row['id_product_attribute'];
|
||||
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `'.$this->identifier.'` = '.(int)$this->id) === false)
|
||||
return false;
|
||||
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(', ', $combinationIds).')') === false)
|
||||
return false;
|
||||
}
|
||||
/* Reinitializing position */
|
||||
$this->cleanPositions((int)($this->id_attribute_group));
|
||||
$this->cleanPositions((int)$this->id_attribute_group);
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
@@ -110,9 +110,9 @@ class AttributeCore extends ObjectModel
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
|
||||
FROM `'._DB_PREFIX_.'attribute_group` ag
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group`
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
|
||||
'.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
|
||||
ORDER BY agl.`name` ASC, a.`position` ASC');
|
||||
}
|
||||
@@ -153,10 +153,10 @@ class AttributeCore extends ObjectModel
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT SUM(quantity) as quantity
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)($id_product));
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
|
||||
if ($row['quantity'] !== NULL)
|
||||
return (int)($row['quantity']);
|
||||
return (int)$row['quantity'];
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
|
||||
$id_product = (int)($arr['id_product']);
|
||||
$id_product = (int)$arr['id_product'];
|
||||
$qty = self::getAttributeQty($id_product);
|
||||
|
||||
if ($qty !== false)
|
||||
{
|
||||
$arr['quantity'] = (int)($qty);
|
||||
$arr['quantity'] = (int)$qty;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -256,22 +256,28 @@ class AttributeCore extends ObjectModel
|
||||
* Call it after deleting an attribute from a group.
|
||||
*
|
||||
* @param int $id_attribute_group
|
||||
* @param bool $use_last_attribute
|
||||
* @return bool $return
|
||||
*/
|
||||
public function cleanPositions($id_attribute_group)
|
||||
public function cleanPositions($id_attribute_group, $use_last_attribute = true)
|
||||
{
|
||||
$return = true;
|
||||
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
$sql = '
|
||||
SELECT `id_attribute`
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group.'
|
||||
AND `id_attribute` != '.(int)$this->id.'
|
||||
ORDER BY `position`');
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group;
|
||||
// when delete, you must use $use_last_attribute
|
||||
if($use_last_attribute)
|
||||
$sql .= '
|
||||
AND `id_attribute` != '.(int)$this->id;
|
||||
$sql .= '
|
||||
ORDER BY `position`';
|
||||
$result = Db::getInstance()->ExecuteS($sql);
|
||||
$sizeof = sizeof($result);
|
||||
|
||||
for ($i = 0; $i < $sizeof; $i++)
|
||||
$return &= Db::getInstance()->Execute('
|
||||
$return = Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group.'
|
||||
@@ -279,5 +285,21 @@ class AttributeCore extends ObjectModel
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* getHigherPosition
|
||||
*
|
||||
* Get the higher attribute position from a group attribute
|
||||
*
|
||||
* @param integer $id_attribute_group
|
||||
* @return integer $position
|
||||
*/
|
||||
public static function getHigherPosition($id_attribute_group)
|
||||
{
|
||||
$sql = 'SELECT `position`
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE id_attribute_group = '.(int)$id_attribute_group.'
|
||||
ORDER BY position DESC';
|
||||
return ((DB::getInstance()->getValue($sql)!==false)) ? DB::getInstance()->getValue($sql) : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1153,7 +1153,8 @@ $_LANGADM['AdminImport2377be3c2ad9b435ba277a73f0f1ca76'] = 'Fabricants';
|
||||
$_LANGADM['AdminImport1814d65a76028fdfbadab64a5a8076df'] = 'Fournisseurs';
|
||||
$_LANGADM['AdminImportb8495b50f5c172ebad1cc5c615548afa'] = 'Ignorer cette colonne';
|
||||
$_LANGADM['AdminImport97f08a40f22a625d0cbfe03db3349108'] = 'ID produit';
|
||||
$_LANGADM['AdminImport78d2b04f57eb3af4fbc20e169de7e6c6'] = 'Options (Groupe:Valeur)';
|
||||
$_LANGADM['AdminImport9608f36da60f49e9d5e203916de5f6e9'] = 'Options (Groupe:Valeur:Position)';
|
||||
$_LANGADM['AdminImport6ea61efe688b5afde35e1b11517d0e56'] = 'Position de l\'attribut dans le groupe d\'attribut.';
|
||||
$_LANGADM['AdminImport63d5049791d9d79d86e9a108b0a999ca'] = 'Référence';
|
||||
$_LANGADM['AdminImport8284ae5df53e6e7ffc1f2cc67ae68765'] = 'Référence fournisseur';
|
||||
$_LANGADM['AdminImport52eb5928a34db3e3da7ba52b0644273b'] = 'EAN13';
|
||||
|
||||
Reference in New Issue
Block a user