diff --git a/classes/Product.php b/classes/Product.php index fb71dd729..482678440 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -987,7 +987,7 @@ class ProductCore extends ObjectModel return count($result) > 0; } - public function productAttributeExists($attributes_list, $current_product_attribute = false, Context $context = null) + public function productAttributeExists($attributes_list, $current_product_attribute = false, Context $context = null, $all_shops = false, $return_id = false) { if (!Combination::isFeatureActive()) return false; @@ -998,7 +998,7 @@ class ProductCore extends ObjectModel FROM `'._DB_PREFIX_.'product_attribute` pa JOIN `'._DB_PREFIX_.'product_attribute_shop` pas ON (pas.id_product_attribute = pa.id_product_attribute) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`) - WHERE pas.id_shop ='.(int)$context->shop->id.' AND pa.`id_product` = '.(int)$this->id + WHERE 1 '.(!$all_shops ? ' AND pas.id_shop ='.(int)$context->shop->id : '').' AND pa.`id_product` = '.(int)$this->id ); /* If something's wrong */ @@ -1017,9 +1017,17 @@ class ProductCore extends ObjectModel $diff = false; for ($i = 0; $diff == false && isset($product_attribute[$i]); $i++) if (!in_array($product_attribute[$i], $attributes_list) || $key == $current_product_attribute) - $diff = true; + { + if ($return_id) + return $key; + return true; + } if (!$diff) + { + if ($return_id) + return $key; return true; + } } return false; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 8aebf16b6..e0f06ffa0 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -668,35 +668,31 @@ class AdminProductsControllerCore extends AdminController if (Tools::getValue('attribute_default')) $product->deleteDefaultAttributes(); // Change existing one - if ($id_product_attribute = (int)Tools::getValue('id_product_attribute')) + if (($id_product_attribute = (int)Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) { if ($this->tabAccess['edit'] === '1') { - if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'), (int)$id_product_attribute)) - $this->errors[] = Tools::displayError('This attribute already exists.'); + + if ($this->isProductFieldUpdated('available_date_attribute') && !Validate::isDateFormat(Tools::getValue('available_date_attribute'))) + $this->errors[] = Tools::displayError('Invalid date format.'); else { - if ($this->isProductFieldUpdated('available_date_attribute') && !Validate::isDateFormat(Tools::getValue('available_date_attribute'))) - $this->errors[] = Tools::displayError('Invalid date format.'); - else - { - $product->updateAttribute((int)$id_product_attribute, - $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, - $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, - $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, - $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, - $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, - Tools::getValue('id_image_attr'), - Tools::getValue('attribute_reference'), - Tools::getValue('attribute_ean13'), - $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, - Tools::getValue('attribute_location'), - Tools::getValue('attribute_upc'), - $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, - $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, - false); - } - } + $product->updateAttribute((int)$id_product_attribute, + $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, + $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, + $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, + $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, + $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, + Tools::getValue('id_image_attr'), + Tools::getValue('attribute_reference'), + Tools::getValue('attribute_ean13'), + $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, + Tools::getValue('attribute_location'), + Tools::getValue('attribute_upc'), + $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, + $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, + false); + } } else $this->errors[] = Tools::displayError('You do not have permission to add here.');