// Fixed combinations CSV import for PS 1.5
This commit is contained in:
1 parent
33faa2bb1d
commit
c306f8f17d
2 files changed
+60
-32
No files matched your search
@@ -113,10 +113,10 @@ class AdminImportControllerCore extends AdminController
|
|||||||
'no' => array('label' => $this->l('Ignore this column')),
|
'no' => array('label' => $this->l('Ignore this column')),
|
||||||
'id_product' => array('label' => $this->l('Product ID').'*'),
|
'id_product' => array('label' => $this->l('Product ID').'*'),
|
||||||
'group' => array(
|
'group' => array(
|
||||||
'label' => $this->l('Group (Name:Position)').'*'
|
'label' => $this->l('Attribute (Name:Type:Position)').'*'
|
||||||
),
|
),
|
||||||
'attribute' => array(
|
'attribute' => array(
|
||||||
'label' => $this->l('Attribute (Value:Position)').'*'
|
'label' => $this->l('Value (Value:Position)').'*'
|
||||||
),
|
),
|
||||||
'reference' => array('label' => $this->l('Reference')),
|
'reference' => array('label' => $this->l('Reference')),
|
||||||
'supplier_reference' => array('label' => $this->l('Supplier reference')),
|
'supplier_reference' => array('label' => $this->l('Supplier reference')),
|
||||||
@@ -1338,20 +1338,30 @@ class AdminImportControllerCore extends AdminController
|
|||||||
|
|
||||||
$id_attribute_group = 0;
|
$id_attribute_group = 0;
|
||||||
$group = '';
|
$group = '';
|
||||||
foreach (explode($fsep, $info['group']) as $group)
|
// groups
|
||||||
|
$groups_attributes = array();
|
||||||
|
foreach (explode($fsep, $info['group']) as $key => $group)
|
||||||
{
|
{
|
||||||
$tab_group = explode(':', $group);
|
$tab_group = explode(':', $group);
|
||||||
$group = $tab_group[0];
|
$group = $tab_group[0];
|
||||||
$id_attribute_group = $groups[$group];
|
if (!isset($tab_group[1]))
|
||||||
|
$type = 'select';
|
||||||
|
else
|
||||||
|
$type = $tab_group[1];
|
||||||
|
|
||||||
|
// sets group
|
||||||
|
$groups_attributes[$key]['group'] = $group;
|
||||||
|
|
||||||
// if position is filled
|
// if position is filled
|
||||||
if (isset($tab_group[1]))
|
if (isset($tab_group[2]))
|
||||||
$position = $tab_group[1];
|
$position = $tab_group[2];
|
||||||
else
|
else
|
||||||
$position = false;
|
$position = false;
|
||||||
if (!isset($groups[$group]))
|
if (!isset($groups[$group]))
|
||||||
{
|
{
|
||||||
$obj = new AttributeGroup();
|
$obj = new AttributeGroup();
|
||||||
$obj->is_color_group = false;
|
$obj->is_color_group = false;
|
||||||
|
$obj->group_type = pSQL($type);
|
||||||
$obj->name[$default_language] = $group;
|
$obj->name[$default_language] = $group;
|
||||||
$obj->public_name[$default_language] = $group;
|
$obj->public_name[$default_language] = $group;
|
||||||
$obj->position = (!$position) ? AttributeGroup::getHigherPosition() + 1 : $position;
|
$obj->position = (!$position) ? AttributeGroup::getHigherPosition() + 1 : $position;
|
||||||
@@ -1363,9 +1373,19 @@ class AdminImportControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '');
|
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '');
|
||||||
|
|
||||||
|
// fils groups attributes
|
||||||
|
$id_attribute_group = $obj->id;
|
||||||
|
$groups_attributes[$key]['id'] = $id_attribute_group;
|
||||||
|
}
|
||||||
|
else // alreay exists
|
||||||
|
{
|
||||||
|
$id_attribute_group = $groups[$group];
|
||||||
|
$groups_attributes[$key]['id'] = $id_attribute_group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (explode($fsep, $info['attribute']) as $attribute)
|
|
||||||
|
foreach (explode($fsep, $info['attribute']) as $key => $attribute)
|
||||||
{
|
{
|
||||||
$tab_attribute = explode(':', $attribute);
|
$tab_attribute = explode(':', $attribute);
|
||||||
$attribute = $tab_attribute[0];
|
$attribute = $tab_attribute[0];
|
||||||
@@ -1374,34 +1394,43 @@ class AdminImportControllerCore extends AdminController
|
|||||||
$position = $tab_attribute[1];
|
$position = $tab_attribute[1];
|
||||||
else
|
else
|
||||||
$position = false;
|
$position = false;
|
||||||
if (!isset($attributes[$group.'_'.$attribute]))
|
|
||||||
{
|
|
||||||
$obj = new Attribute();
|
|
||||||
$obj->id_attribute_group = $groups[$group];
|
|
||||||
$obj->name[$default_language] = str_replace('\n', '', str_replace('\r', '', $attribute));
|
|
||||||
$obj->position = (!$position) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;
|
|
||||||
if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true &&
|
|
||||||
($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
|
|
||||||
{
|
|
||||||
$obj->add();
|
|
||||||
$attributes[$group.'_'.$attribute] = $obj->id;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '');
|
|
||||||
|
|
||||||
|
if (isset($groups_attributes[$key]))
|
||||||
|
{
|
||||||
|
if (!isset($attributes[$group.'_'.$attribute]) && count($groups_attributes[$key]) == 2)
|
||||||
|
{
|
||||||
|
$group = $groups_attributes[$key]['group'];
|
||||||
|
$id_attribute_group = $groups_attributes[$key]['id'];
|
||||||
|
$obj = new Attribute();
|
||||||
|
// sets the proper id (corresponding to the right key)
|
||||||
|
$obj->id_attribute_group = $groups_attributes[$key]['id'];
|
||||||
|
$obj->name[$default_language] = str_replace('\n', '', str_replace('\r', '', $attribute));
|
||||||
|
$obj->position = (!$position) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position;
|
||||||
|
if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true &&
|
||||||
|
($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
|
||||||
|
{
|
||||||
|
$obj->add();
|
||||||
|
$attributes[$group.'_'.$attribute] = $obj->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Db::getInstance()->execute('
|
||||||
|
INSERT INTO '._DB_PREFIX_.'product_attribute_combination (id_attribute, id_product_attribute)
|
||||||
|
VALUES ('.(int)$attributes[$group.'_'.$attribute].','.(int)$id_product_attribute.')
|
||||||
|
');
|
||||||
|
|
||||||
|
// after insertion, we clean attribute position and group attribute position
|
||||||
|
$obj = new Attribute();
|
||||||
|
$obj->cleanPositions((int)$id_attribute_group, false);
|
||||||
|
AttributeGroup::cleanPositions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
$this->closeCsvFile($handle);
|
||||||
|
|
||||||
// after insertion, we clean attribute position and group attribute position
|
|
||||||
$obj = new Attribute();
|
|
||||||
$obj->cleanPositions((int)$id_attribute_group, false);
|
|
||||||
AttributeGroup::cleanPositions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function customerImport()
|
public function customerImport()
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
Product ID*;Options (Group:Value)*;Reference;Supplier reference;EAN13;UPC;Wholesale price;Price;Ecotax;Quantity;Weight;Default
|
1; Capacity:select:0, Color:color:1; 16Go:0, Bleu:1
|
||||||
1;"Color:Blue, Disk Space:16GO;";958456;254644;;;;41;;50;;
|
1; Capacity:select:0, Color:color:1; 16Go:0, Red:1
|
||||||
1;"Color:pINK, Disk Space:8GO;";958456;254644;;;;;;;;
|
|
||||||
|
Reference in new issue
Block a user