public static function hasCounties($id_state) { return sizeof(County::getCounties((int) $id_state)); }
protected function afterUpdate($object) { global $cookie; TaxRule::deleteByGroupId($object->id); foreach (Country::getCountries($cookie->id_lang, true) as $country) { $id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_0'); // default country rule if (!empty($id_tax)) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = 0; $tr->id_county = 0; $tr->id_tax = $id_tax; $tr->state_behavior = 0; $tr->county_behavior = 0; $tr->save(); } // state specific rule if (!empty($country['contains_states'])) { foreach ($country['states'] as $state) { $state_behavior = (int) Tools::getValue('behavior_state_' . $state['id_state']); if ($state_behavior != PS_PRODUCT_TAX) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = (int) $state['id_state']; $tr->id_county = 0; $tr->id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_' . $state['id_state']); $tr->state_behavior = $state_behavior; $tr->county_behavior = 0; $tr->save(); } // county specific rule if (State::hasCounties($state['id_state'])) { $counties = County::getCounties($state['id_state']); foreach ($counties as $county) { $county_behavior = (int) Tools::getValue('behavior_county_' . $county['id_county']); if ($county_behavior != County::USE_STATE_TAX) { $tr = new TaxRule(); $tr->id_tax_rules_group = $object->id; $tr->id_country = (int) $country['id_country']; $tr->id_state = (int) $state['id_state']; $tr->id_county = (int) $county['id_county']; $tr->id_tax = (int) Tools::getValue('tax_' . $country['id_country'] . '_' . $state['id_state'] . '_' . $county['id_county']); $tr->state_behavior = 0; $tr->county_behavior = $county_behavior; $tr->save(); } } } } } } }