diff --git a/classes/Carrier.php b/classes/Carrier.php index 97a29f6dd..22442cb91 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -837,6 +837,12 @@ class CarrierCore extends ObjectModel UPDATE `'._DB_PREFIX_.$this->def['table'].'` SET `id_reference` = '.(int)$id_reference.' WHERE `id_carrier` = '.(int)$this->id); + + // Copy tax rules group + Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'carrier_tax_rules_group_shop` (`id_carrier`, `id_tax_rules_group`, `id_shop`) + (SELECT '.(int)$this->id.', `id_tax_rules_group`, `id_shop` + FROM `'._DB_PREFIX_.'carrier_tax_rules_group_shop` + WHERE `id_carrier`='.(int)$old_id.')'); } /** @@ -936,34 +942,36 @@ class CarrierCore extends ObjectModel } - public function deleteTaxRulesGroup($all_shops = false) + public function deleteTaxRulesGroup($shops = false) { - $shop = ''; - if (!$all_shops) - $shop = ' AND `id_shop`='.(int)Context::getContext()->shop->id; + if (!$shops) + $shops = Shop::getContextListShopID(); + + $shop = ' AND `id_shop` IN ('; + + foreach ($shops as $id_shop) + $shop .= (int)$id_shop.','; + $shop = rtrim($shop, ',').')'; return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'carrier_tax_rules_group_shop WHERE id_carrier='.(int)$this->id.$shop); } public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false) { - if (!Validate::isInt($id_tax_rules_group)) + if (!Validate::isUnsignedId($id_tax_rules_group)) die(Tools::displayError()); - - if (Shop::getContext() != Shop::CONTEXT_SHOP) - $all_shops = true; - - $this->deleteTaxRulesGroup($all_shops); - - if ($all_shops) - { - $values = ''; - $shops = Shop::getShops(false, null, true); - foreach ($shops as $id_shop) - $values .= '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)$id_shop.'),'; - } + + if (!$all_shops) + $shops = Shop::getContextListShopID(); else - $values = '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)Context::getContext()->shop->id.')'; + $shops = Shop::getShops(true, null, true); + + $this->deleteTaxRulesGroup($shops); + + $values = ''; + foreach ($shops as $id_shop) + $values .= '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)$id_shop.'),'; + return Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'carrier_tax_rules_group_shop (`id_carrier`, `id_tax_rules_group`, `id_shop`) VALUES '.rtrim($values, ',')); } diff --git a/classes/Product.php b/classes/Product.php index d8b556cbc..b7856d355 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4112,33 +4112,37 @@ class ProductCore extends ObjectModel FROM '._DB_PREFIX_.'product_tax_rules_group_shop WHERE `id_product`='.(int)$id_old_product.')'); } - public function deleteTaxRulesGroup($all_shops = false) + public function deleteTaxRulesGroup($shops = false) { - $shop = ''; - if (!$all_shops) - $shop = ' AND `id_shop`='.(int)Context::getContext()->shop->id; + if (!$shops) + $shops = Shop::getContextListShopID(); + + $shop = ' AND `id_shop` IN ('; + + foreach ($shops as $id_shop) + $shop .= (int)$id_shop.','; + $shop = rtrim($shop, ',').')'; + return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_tax_rules_group_shop WHERE id_product='.(int)$this->id.$shop); } public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false) { - if (!Validate::isInt($id_tax_rules_group)) + if (!Validate::isUnsignedId($id_tax_rules_group)) die(Tools::displayError()); - $this->deleteTaxRulesGroup($all_shops); - if (Shop::getContext() != Shop::CONTEXT_SHOP) - $all_shops = true; - - if ($all_shops) - { - $values = ''; - $shops = Shop::getShops(false, null, true); - foreach ($shops as $id_shop) - $values .= '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)$id_shop.'),'; - } + if (!$all_shops) + $shops = Shop::getContextListShopID(); else - $values = '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)Context::getContext()->shop->id.')'; + $shops = Shop::getShops(true, null, true); + + $this->deleteTaxRulesGroup($shops); + + $values = ''; + foreach ($shops as $id_shop) + $values .= '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)$id_shop.'),'; + return Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'product_tax_rules_group_shop (`id_product`, `id_tax_rules_group`, `id_shop`) VALUES '.rtrim($values, ',')); } diff --git a/controllers/admin/AdminCarriersController.php b/controllers/admin/AdminCarriersController.php index 45116feef..f9f45c3c1 100644 --- a/controllers/admin/AdminCarriersController.php +++ b/controllers/admin/AdminCarriersController.php @@ -485,7 +485,7 @@ class AdminCarriersControllerCore extends AdminController $this->postImage($new_carrier->id); $this->changeZones($new_carrier->id); - $new_carrier->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group'), true); + $new_carrier->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group')); Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$current_carrier->id.'&conf=4&token='.$this->token); } else