protected function processCreateRule() { $zip_code = Tools::getValue('zipcode'); $id_rule = (int) Tools::getValue('id_tax_rule'); $id_tax = (int) Tools::getValue('id_tax'); $id_tax_rules_group = (int) Tools::getValue('id_tax_rules_group'); $behavior = (int) Tools::getValue('behavior'); $description = pSQL(Tools::getValue('description')); if ((int) ($id_country = Tools::getValue('country')) == 0) { $countries = Country::getCountries($this->context->language->id); $this->selected_countries = array(); foreach ($countries as $country) { $this->selected_countries[] = (int) $country['id_country']; } } else { $this->selected_countries = array($id_country); } $this->selected_states = Tools::getValue('states'); if (empty($this->selected_states) || count($this->selected_states) == 0) { $this->selected_states = array(0); } $tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group); foreach ($this->selected_countries as $id_country) { $first = true; foreach ($this->selected_states as $id_state) { if ($tax_rules_group->hasUniqueTaxRuleForCountry($id_country, $id_state, $id_rule)) { $this->errors[] = Tools::displayError('A tax rule already exists for this country/state with tax only behavior.'); continue; } $tr = new TaxRule(); // update or creation? if (isset($id_rule) && $first) { $tr->id = $id_rule; $first = false; } $tr->id_tax = $id_tax; $tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group); $tr->id_tax_rules_group = (int) $tax_rules_group->id; $tr->id_country = (int) $id_country; $tr->id_state = (int) $id_state; list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code); // Construct Object Country $country = new Country((int) $id_country, (int) $this->context->language->id); if ($zip_code && $country->need_zip_code) { if ($country->zip_code_format) { foreach (array($tr->zipcode_from, $tr->zipcode_to) as $zip_code) { if ($zip_code) { if (!$country->checkZipCode($zip_code)) { $this->errors[] = sprintf(Tools::displayError('The Zip/postal code is invalid. It must be typed as follows: %s for %s.'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))), $country->name); } } } } } $tr->behavior = (int) $behavior; $tr->description = $description; $this->tax_rule = $tr; $_POST['id_state'] = $tr->id_state; $this->errors = array_merge($this->errors, $this->validateTaxRule($tr)); if (count($this->errors) == 0) { $tax_rules_group = $this->updateTaxRulesGroup($tax_rules_group); $tr->id = (int) $tax_rules_group->getIdTaxRuleGroupFromHistorizedId((int) $tr->id); $tr->id_tax_rules_group = (int) $tax_rules_group->id; if (!$tr->save()) { $this->errors[] = Tools::displayError('An error has occurred: Cannot save the current tax rule.'); } } } } if (count($this->errors) == 0) { Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . (int) $tax_rules_group->id . '&conf=4&update' . $this->table . '&token=' . $this->token); } else { $this->display = 'edit'; } }