[-] BO: Allow only one default combination per product when using import
This commit is contained in:
+13
-2
@@ -617,7 +617,7 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function updateDefaultAttribute($id_product)
|
||||
{
|
||||
Db::getInstance()->update('product', array(
|
||||
Db::getInstance()->update('product_shop', array(
|
||||
'cache_default_attribute' => (int)Product::getDefaultAttribute($id_product),
|
||||
), 'id_product = '.(int)$id_product);
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ class ProductCore extends ObjectModel
|
||||
'ecotax' => !is_null($ecotax),
|
||||
'weight' => !is_null($weight),
|
||||
'unit_price_impact' => !is_null($unit),
|
||||
'default_on' => !is_null($ecotax),
|
||||
'default_on' => !is_null($default),
|
||||
'minimal_quantity' => !is_null($minimal_quantity),
|
||||
'available_date' => !is_null($available_date),
|
||||
));
|
||||
@@ -2897,6 +2897,17 @@ class ProductCore extends ObjectModel
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
if (Db::getInstance()->getValue('SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa').'
|
||||
WHERE product_attribute_shop.`default_on` = 1
|
||||
AND pa.`id_product` = '.(int)$this->id) > 1)
|
||||
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product_attribute_shop product_attribute_shop, '._DB_PREFIX_.'product_attribute pa
|
||||
SET product_attribute_shop.default_on=0, pa.default_on = 0
|
||||
WHERE product_attribute_shop.id_product_attribute=pa.id_product_attribute AND pa.id_product='.(int)$this->id
|
||||
.Shop::addSqlRestriction(false, 'product_attribute_shop'));
|
||||
|
||||
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT pa.id_product
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
|
||||
@@ -1548,7 +1548,7 @@ class AdminImportControllerCore extends AdminController
|
||||
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '').mysql_error();
|
||||
}
|
||||
}
|
||||
else if (isset($info['image_position']) && $info['image_position'])
|
||||
elseif (isset($info['image_position']) && $info['image_position'])
|
||||
{
|
||||
$images = $product->getImages($default_language);
|
||||
|
||||
@@ -1735,6 +1735,9 @@ class AdminImportControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
$product->checkDefaultAttributes();
|
||||
if (!$product->cache_default_attribute)
|
||||
Product::updateDefaultAttribute($product->id);
|
||||
if ($id_product_attribute)
|
||||
{
|
||||
// now adds the attributes in the attribute_combination table
|
||||
|
||||
Reference in New Issue
Block a user