// Improvement #PSFV-550
This commit is contained in:
1 parent
850f89dfd6
commit
68f5c88b5f
2 files changed
+77
-35
No files matched your search
+35
-16
@@ -108,13 +108,15 @@ class CombinationCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if ($this->deleteAssociations())
|
if ($this->deleteAssociations())
|
||||||
{
|
{
|
||||||
$sqlValues = array();
|
$sql_values = array();
|
||||||
foreach ($ids_attribute as $value)
|
foreach ($ids_attribute as $value)
|
||||||
$sqlValues[] = '('.(int)$value.', '.(int)$this->id.')';
|
$sql_values[] = '('.(int)$value.', '.(int)$this->id.')';
|
||||||
|
|
||||||
$result = Db::getInstance()->execute('
|
$result = Db::getInstance()->execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'product_attribute_combination` (`id_attribute`, `id_product_attribute`)
|
INSERT INTO `'._DB_PREFIX_.'product_attribute_combination` (`id_attribute`, `id_product_attribute`)
|
||||||
VALUES '.implode(',', $sqlValues)
|
VALUES '.implode(',', $sql_values)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -130,16 +132,20 @@ class CombinationCore extends ObjectModel
|
|||||||
|
|
||||||
public function getWsProductOptionValues()
|
public function getWsProductOptionValues()
|
||||||
{
|
{
|
||||||
$result = Db::getInstance()->executeS('SELECT id_attribute AS id from `'._DB_PREFIX_.'product_attribute_combination` WHERE id_product_attribute = '.(int)$this->id);
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
|
SELECT id_attribute AS id
|
||||||
|
FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||||
|
WHERE id_product_attribute = '.(int)$this->id);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWsImages()
|
public function getWsImages()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->executeS('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT `id_image` as id
|
SELECT `id_image` as id
|
||||||
FROM `'._DB_PREFIX_.'product_attribute_image`
|
FROM `'._DB_PREFIX_.'product_attribute_image`
|
||||||
WHERE `id_product_attribute` = '.(int)($this->id).'
|
WHERE `id_product_attribute` = '.(int)$this->id.'
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,16 +153,17 @@ class CombinationCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (Db::getInstance()->execute('
|
if (Db::getInstance()->execute('
|
||||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_image`
|
DELETE FROM `'._DB_PREFIX_.'product_attribute_image`
|
||||||
WHERE `id_product_attribute` = '.(int)($this->id)) === false)
|
WHERE `id_product_attribute` = '.(int)$this->id) === false)
|
||||||
return false;
|
return false;
|
||||||
$sqlValues = array();
|
|
||||||
|
$sql_values = array();
|
||||||
|
|
||||||
foreach ($ids_image as $value)
|
foreach ($ids_image as $value)
|
||||||
$sqlValues[] = '('.(int)$this->id.', '.(int)$value.')';
|
$sql_values[] = '('.(int)$this->id.', '.(int)$value.')';
|
||||||
|
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`)
|
INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`)
|
||||||
VALUES '.implode(',', $sqlValues)
|
VALUES '.implode(',', $sql_values)
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -168,10 +175,11 @@ class CombinationCore extends ObjectModel
|
|||||||
|
|
||||||
public function getAttributesName($id_lang)
|
public function getAttributesName($id_lang)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->executeS('SELECT al.*
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
FROM '._DB_PREFIX_.'product_attribute_combination pac
|
SELECT al.*
|
||||||
JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang='.(int)$id_lang.')
|
FROM '._DB_PREFIX_.'product_attribute_combination pac
|
||||||
WHERE pac.id_product_attribute='.(int)$this->id);
|
JOIN '._DB_PREFIX_.'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang='.(int)$id_lang.')
|
||||||
|
WHERE pac.id_product_attribute='.(int)$this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,4 +203,15 @@ class CombinationCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
return parent::isCurrentlyUsed('product_attribute');
|
return parent::isCurrentlyUsed('product_attribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getIdByReference($id_product, $reference)
|
||||||
|
{
|
||||||
|
$query = new DbQuery();
|
||||||
|
$query->select('pa.id_product_attribute');
|
||||||
|
$query->from('product_attribute', 'pa');
|
||||||
|
$query->where('pa.reference LIKE \'%'.pSQL($reference).'%\'');
|
||||||
|
$query->where('pa.id_product = '.(int)$id_product);
|
||||||
|
|
||||||
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1320,19 +1320,43 @@ class AdminImportControllerCore extends AdminController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_product_attribute = $product->addAttribute(
|
$id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference']));
|
||||||
(float)$info['price'],
|
|
||||||
(float)$info['weight'],
|
if ($id_product_attribute > 0)
|
||||||
0,
|
{
|
||||||
(float)$info['ecotax'],
|
$product->updateAttribute(
|
||||||
$id_image,
|
$id_product_attribute,
|
||||||
strval($info['reference']),
|
(float)$info['wholesale_price'],
|
||||||
strval($info['ean13']),
|
(float)$info['price'],
|
||||||
(int)$info['default_on'],
|
(float)$info['weight'],
|
||||||
0,
|
0,
|
||||||
strval($info['upc']),
|
(float)$info['ecotax'],
|
||||||
(int)$info['quantity']
|
$id_image,
|
||||||
);
|
strval($info['reference']),
|
||||||
|
strval($info['ean13']),
|
||||||
|
(int)$info['default_on'],
|
||||||
|
0,
|
||||||
|
strval($info['upc']),
|
||||||
|
(int)$info['quantity'],
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$id_product_attribute = $product->addAttribute(
|
||||||
|
(float)$info['price'],
|
||||||
|
(float)$info['weight'],
|
||||||
|
0,
|
||||||
|
(float)$info['ecotax'],
|
||||||
|
$id_image,
|
||||||
|
strval($info['reference']),
|
||||||
|
strval($info['ean13']),
|
||||||
|
(int)$info['default_on'],
|
||||||
|
0,
|
||||||
|
strval($info['upc']),
|
||||||
|
(int)$info['quantity']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$id_attribute_group = 0;
|
$id_attribute_group = 0;
|
||||||
$group = '';
|
$group = '';
|
||||||
@@ -1395,9 +1419,9 @@ class AdminImportControllerCore extends AdminController
|
|||||||
|
|
||||||
if (isset($groups_attributes[$key]))
|
if (isset($groups_attributes[$key]))
|
||||||
{
|
{
|
||||||
|
$group = $groups_attributes[$key]['group'];
|
||||||
if (!isset($attributes[$group.'_'.$attribute]) && count($groups_attributes[$key]) == 2)
|
if (!isset($attributes[$group.'_'.$attribute]) && count($groups_attributes[$key]) == 2)
|
||||||
{
|
{
|
||||||
$group = $groups_attributes[$key]['group'];
|
|
||||||
$id_attribute_group = $groups_attributes[$key]['id'];
|
$id_attribute_group = $groups_attributes[$key]['id'];
|
||||||
$obj = new Attribute();
|
$obj = new Attribute();
|
||||||
// sets the proper id (corresponding to the right key)
|
// sets the proper id (corresponding to the right key)
|
||||||
@@ -1413,13 +1437,12 @@ 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 : '');
|
||||||
|
|
||||||
|
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.')
|
|
||||||
');
|
|
||||||
|
|
||||||
// after insertion, we clean attribute position and group attribute position
|
// after insertion, we clean attribute position and group attribute position
|
||||||
$obj = new Attribute();
|
$obj = new Attribute();
|
||||||
$obj->cleanPositions((int)$id_attribute_group, false);
|
$obj->cleanPositions((int)$id_attribute_group, false);
|
||||||
|
|||||||
Reference in new issue
Block a user