From ee62ed8d27c0cf545e8064a6dd613296782d4b88 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Fri, 16 Nov 2012 16:48:23 +0000 Subject: [PATCH] [-] BO: FIX #PSCFV-5088 - cant add a tax rule to a group if one have already defined as unique --- classes/tax/TaxRule.php | 4 +++- classes/tax/TaxRulesGroup.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/classes/tax/TaxRule.php b/classes/tax/TaxRule.php index 82ab4e0f6..2859408c3 100644 --- a/classes/tax/TaxRule.php +++ b/classes/tax/TaxRule.php @@ -89,7 +89,9 @@ class TaxRuleCore extends ObjectModel t.`rate`, g.`zipcode_from`, g.`zipcode_to`, g.`description`, - g.`behavior` + g.`behavior`, + g.`id_country`, + g.`id_state` FROM `'._DB_PREFIX_.'tax_rule` g LEFT JOIN `'._DB_PREFIX_.'country_lang` c ON (g.`id_country` = c.`id_country` AND `id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'state` s ON (g.`id_state` = s.`id_state`) diff --git a/classes/tax/TaxRulesGroup.php b/classes/tax/TaxRulesGroup.php index af3e38203..52a06a01c 100644 --- a/classes/tax/TaxRulesGroup.php +++ b/classes/tax/TaxRulesGroup.php @@ -113,6 +113,16 @@ class TaxRulesGroupCore extends ObjectModel WHERE `name` = \''.pSQL($name).'\'' ); } + + public function hasUniqueTaxRuleForCountry($id_country, $id_state) + { + $rules = TaxRule::getTaxRulesByGroupId((int)Context::getContext()->language->id, (int)$this->id); + foreach ($rules as $rule) + if ($rule['id_country'] == $id_country && $id_state == $rule['id_state'] && !$rule['behavior']) + return true; + + return false; + } /** * @deprecated since 1.5