[-] BO: Fix PSFV-630 tax rules group on product

This commit is contained in:
rGaillard
2012-03-07 14:06:00 +00:00
parent c684af0cb7
commit 846f592744
3 changed files with 49 additions and 37 deletions
+27 -19
View File
@@ -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, ','));
}
+21 -17
View File
@@ -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, ','));
}
@@ -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