本文整理汇总了PHP中TaxRulesGroup::hasUniqueTaxRuleForCountry方法的典型用法代码示例。如果您正苦于以下问题:PHP TaxRulesGroup::hasUniqueTaxRuleForCountry方法的具体用法?PHP TaxRulesGroup::hasUniqueTaxRuleForCountry怎么用?PHP TaxRulesGroup::hasUniqueTaxRuleForCountry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaxRulesGroup
的用法示例。
在下文中一共展示了TaxRulesGroup::hasUniqueTaxRuleForCountry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processCreateRule
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';
}
}