当前位置: 首页>>代码示例>>PHP>>正文


PHP TaxRulesGroup::getIdByName方法代码示例

本文整理汇总了PHP中TaxRulesGroup::getIdByName方法的典型用法代码示例。如果您正苦于以下问题:PHP TaxRulesGroup::getIdByName方法的具体用法?PHP TaxRulesGroup::getIdByName怎么用?PHP TaxRulesGroup::getIdByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaxRulesGroup的用法示例。


在下文中一共展示了TaxRulesGroup::getIdByName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _installTaxes

 /**
  * @param SimpleXMLElement $xml
  * @return bool
  * @throws PrestaShopException
  */
 protected function _installTaxes($xml)
 {
     if (isset($xml->taxes->tax)) {
         $assoc_taxes = array();
         foreach ($xml->taxes->tax as $taxData) {
             /** @var SimpleXMLElement $taxData */
             $attributes = $taxData->attributes();
             if ($id_tax = Tax::getTaxIdByName($attributes['name'])) {
                 $assoc_taxes[(int) $attributes['id']] = $id_tax;
                 continue;
             }
             $tax = new Tax();
             $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $attributes['name'];
             $tax->rate = (double) $attributes['rate'];
             $tax->active = 1;
             if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
                 $this->_errors[] = Tools::displayError('Invalid tax properties.') . ' ' . $error;
                 return false;
             }
             if (!$tax->add()) {
                 $this->_errors[] = Tools::displayError('An error occurred while importing the tax: ') . (string) $attributes['name'];
                 return false;
             }
             $assoc_taxes[(int) $attributes['id']] = $tax->id;
         }
         foreach ($xml->taxes->taxRulesGroup as $group) {
             /** @var SimpleXMLElement $group */
             $group_attributes = $group->attributes();
             if (!Validate::isGenericName($group_attributes['name'])) {
                 continue;
             }
             if (TaxRulesGroup::getIdByName($group['name'])) {
                 continue;
             }
             $trg = new TaxRulesGroup();
             $trg->name = $group['name'];
             $trg->active = 1;
             if (!$trg->save()) {
                 $this->_errors[] = Tools::displayError('This tax rule cannot be saved.');
                 return false;
             }
             foreach ($group->taxRule as $rule) {
                 /** @var SimpleXMLElement $rule */
                 $rule_attributes = $rule->attributes();
                 // Validation
                 if (!isset($rule_attributes['iso_code_country'])) {
                     continue;
                 }
                 $id_country = (int) Country::getByIso(strtoupper($rule_attributes['iso_code_country']));
                 if (!$id_country) {
                     continue;
                 }
                 if (!isset($rule_attributes['id_tax']) || !array_key_exists(strval($rule_attributes['id_tax']), $assoc_taxes)) {
                     continue;
                 }
                 // Default values
                 $id_state = (int) isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0;
                 $id_county = 0;
                 $zipcode_from = 0;
                 $zipcode_to = 0;
                 $behavior = $rule_attributes['behavior'];
                 if (isset($rule_attributes['zipcode_from'])) {
                     $zipcode_from = $rule_attributes['zipcode_from'];
                     if (isset($rule_attributes['zipcode_to'])) {
                         $zipcode_to = $rule_attributes['zipcode_to'];
                     }
                 }
                 // Creation
                 $tr = new TaxRule();
                 $tr->id_tax_rules_group = $trg->id;
                 $tr->id_country = $id_country;
                 $tr->id_state = $id_state;
                 $tr->id_county = $id_county;
                 $tr->zipcode_from = $zipcode_from;
                 $tr->zipcode_to = $zipcode_to;
                 $tr->behavior = $behavior;
                 $tr->description = '';
                 $tr->id_tax = $assoc_taxes[strval($rule_attributes['id_tax'])];
                 $tr->save();
             }
         }
     }
     return true;
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:89,代码来源:LocalizationPack.php

示例2: _installTaxes

 protected function _installTaxes($xml)
 {
     if (isset($xml->taxes->tax)) {
         $available_behavior = array(PS_PRODUCT_TAX, PS_STATE_TAX, PS_BOTH_TAX);
         $assoc_taxes = array();
         foreach ($xml->taxes->tax as $taxData) {
             $attributes = $taxData->attributes();
             if (Tax::getTaxIdByName($attributes['name'])) {
                 continue;
             }
             $tax = new Tax();
             $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = strval($attributes['name']);
             $tax->rate = (double) $attributes['rate'];
             $tax->active = 1;
             if (!$tax->validateFields()) {
                 $this->_errors[] = Tools::displayError('Invalid tax properties.');
                 return false;
             }
             if (!$tax->add()) {
                 $this->_errors[] = Tools::displayError('An error occurred while importing the tax: ') . strval($attributes['name']);
                 return false;
             }
             $assoc_taxes[(int) $attributes['id']] = $tax->id;
         }
         foreach ($xml->taxes->taxRulesGroup as $group) {
             $group_attributes = $group->attributes();
             if (!Validate::isGenericName($group_attributes['name'])) {
                 continue;
             }
             if (TaxRulesGroup::getIdByName($group['name'])) {
                 continue;
             }
             $trg = new TaxRulesGroup();
             $trg->name = $group['name'];
             $trg->active = 1;
             if (!$trg->save()) {
                 $this->_errors = Tools::displayError('This tax rule cannot be saved.');
                 return false;
             }
             foreach ($group->taxRule as $rule) {
                 $rule_attributes = $rule->attributes();
                 // Validation
                 if (!isset($rule_attributes['iso_code_country'])) {
                     continue;
                 }
                 $id_country = Country::getByIso(strtoupper($rule_attributes['iso_code_country']));
                 if (!$id_country) {
                     continue;
                 }
                 if (!isset($rule_attributes['id_tax']) || !array_key_exists(strval($rule_attributes['id_tax']), $assoc_taxes)) {
                     continue;
                 }
                 // Default values
                 $id_state = (int) isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0;
                 $id_county = 0;
                 $state_behavior = 0;
                 $county_behavior = 0;
                 if ($id_state) {
                     if (isset($rule_attributes['state_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior)) {
                         $state_behavior = (int) $rule_attributes['state_behavior'];
                     }
                     if (isset($rule_attributes['county_name'])) {
                         $id_county = County::getIdCountyByNameAndIdState($rule_attributes['county_name'], (int) $id_state);
                         if (!$id_county) {
                             continue;
                         }
                     }
                     if (isset($rule_attributes['county_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior)) {
                         $county_behavior = (int) $rule_attributes['county_behavior'];
                     }
                 }
                 // Creation
                 $tr = new TaxRule();
                 $tr->id_tax_rules_group = $trg->id;
                 $tr->id_country = $id_country;
                 $tr->id_state = $id_state;
                 $tr->id_county = $id_county;
                 $tr->state_behavior = $state_behavior;
                 $tr->county_behavior = $county_behavior;
                 $tr->id_tax = $assoc_taxes[strval($rule_attributes['id_tax'])];
                 $tr->save();
             }
         }
     }
     return true;
 }
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:86,代码来源:LocalizationPack.php

示例3: taxamoCreateParams


//.........这里部分代码省略.........
                 }
             }
         }
         if (count($params_tax) <= 0) {
             $res_craete_params['error'] = 'Error In Countries Dictionary';
             return $res_craete_params;
         }
     } else {
         $res_craete_params['error'] = 'Error In API Countries Dictionary';
         return $res_craete_params;
     }
     foreach ($params_tax as $key => $tax_values) {
         if (!Validate::isGenericName($tax_values['name'])) {
             // continue;
             $res_craete_params['error'] = 'Error In Procedure Tax';
             return $res_craete_params;
         }
         if (!($id_tax = Tax::getTaxIdByName($tax_values['name'], 1))) {
             $id_tax = Tax::getTaxIdByName($tax_values['name'], 0);
         }
         if ($id_tax) {
             $tax = new Tax($id_tax);
             if ($tax->rate != (double) $tax_values['rate'] || $tax->active != 1) {
                 $tax->rate = (double) $tax_values['rate'];
                 $tax->active = 1;
                 if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
                     $res_craete_params['error'] = 'Invalid tax properties (update). ' . $error;
                     return $res_craete_params;
                 }
                 if (!$tax->update()) {
                     $res_craete_params['error'] = 'An error occurred while updating the tax: ' . (string) $tax_values['name'];
                     return $res_craete_params;
                 }
             }
             $params_tax[$key]['id_tax'] = $id_tax;
         } else {
             $tax = new Tax();
             $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $tax_values['name'];
             $tax->rate = (double) $tax_values['rate'];
             $tax->active = 1;
             if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
                 $res_craete_params['error'] = 'Invalid tax properties (add). ' . $error;
                 return $res_craete_params;
             }
             if (!$tax->add()) {
                 $res_craete_params['error'] = 'An error occurred while importing the tax: ' . (string) $tax_values['name'];
                 return $res_craete_params;
             }
             $params_tax[$key]['id_tax'] = $tax->id;
         }
     }
     foreach ($product_types as $product_type) {
         $tax_group_name = $generic_name . ' - ' . $product_type;
         if (!Validate::isGenericName($tax_group_name)) {
             // continue;
             $res_craete_params['error'] = 'Error In Procedure Product Type';
             return $res_craete_params;
         }
         if ($id_tax_rules_group = TaxRulesGroup::getIdByName($tax_group_name)) {
             $trg = new TaxRulesGroup($id_tax_rules_group);
             if ($trg->active != 1) {
                 $trg->active = 1;
                 if (!$trg->update()) {
                     $res_craete_params['error'] = 'An error occurred while updating the tax rule group: ' . (string) $tax_values['name'];
                     return $res_craete_params;
                 }
             }
             $is_new_record = false;
         } else {
             $trg = new TaxRulesGroup();
             $trg->name = $tax_group_name;
             $trg->active = 1;
             if (!$trg->add()) {
                 $res_craete_params['error'] = 'An error occurred while importing the tax rule group: ' . (string) $tax_values['name'];
                 return $res_craete_params;
             }
             $is_new_record = true;
         }
         foreach ($params_tax as $tax_values) {
             if ($tax_values['product_type'] == $product_type) {
                 if ($is_new_record) {
                     // Creation
                     $tr = new TaxRule();
                     $tr->id_tax_rules_group = $trg->id;
                     $tr->id_country = $tax_values['id_country'];
                     $tr->id_state = 0;
                     $tr->id_county = 0;
                     $tr->zipcode_from = 0;
                     $tr->zipcode_to = 0;
                     $tr->behavior = 0;
                     $tr->description = '';
                     $tr->id_tax = $tax_values['id_tax'];
                     $tr->save();
                 }
             }
         }
     }
     $res_craete_params['success'] = true;
     return $res_craete_params;
 }
开发者ID:hjcalvo,项目名称:prestashop-taxamo-plugin,代码行数:101,代码来源:Tools.php

示例4: generateEuropeTaxRule

 private function generateEuropeTaxRule()
 {
     $euro_vat_array = self::$europe_vat_array;
     $euro_tax_rule_grp_id = TaxRulesGroup::getIdByName((string) $this->european_vat_name);
     if (!$euro_tax_rule_grp_id) {
         // Create it
         $trg = new TaxRulesGroup();
         $trg->name = (string) $this->european_vat_name;
         $trg->active = 1;
         if (!$trg->save()) {
             $this->_errors[] = Tools::displayError('Tax rule cannot be saved.');
             return false;
         }
         $euro_tax_rule_grp_id = (int) $trg->id;
     }
     $tax_rules_euro_group = TaxRule::getTaxRulesByGroupId((int) Context::getContext()->language->id, (int) $euro_tax_rule_grp_id);
     $euro_group_taxes_rules = array();
     foreach ($tax_rules_euro_group as $tax_rule) {
         $euro_group_taxes_rules[] = $tax_rule;
     }
     foreach ($euro_vat_array as $euro_vat_name => $euro_vat_details) {
         $posted_euro_vat = 'euro_vat_' . (string) $euro_vat_details['iso_country'];
         $posted_available_vat = 'available_vat_' . (string) $euro_vat_details['iso_country'];
         $country_id = Country::getByIso((string) $euro_vat_details['iso_country']);
         if (Tools::isSubmit($posted_euro_vat)) {
             if (!Tools::isSubmit($posted_available_vat)) {
                 $id_tax_found = Tax::getTaxIdByName((string) $euro_vat_name);
                 if ($id_tax_found !== false) {
                     $tax = new Tax((int) $id_tax_found);
                 } else {
                     $tax = new Tax();
                 }
                 $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $euro_vat_name;
                 $tax->rate = (double) $euro_vat_details['rate'];
                 $tax->active = 1;
                 if ($tax->validateFields(false, true) !== true || $tax->validateFieldsLang(false, true) !== true) {
                     $this->_errors[] = Tools::displayError('Invalid tax properties.');
                     continue;
                 }
                 if (!$tax->save()) {
                     $this->_errors[] = Tools::displayError('An error occurred while saving the tax: ');
                     continue;
                 }
                 $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $id_tax_found);
                 if ($id_tax_rule !== false) {
                     $tr = new TaxRule((int) $id_tax_rule);
                 } else {
                     $tr = new TaxRule();
                 }
                 $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
                 $tr->id_country = (int) $country_id;
                 $tr->id_state = 0;
                 $tr->id_county = 0;
                 $tr->zipcode_from = 0;
                 $tr->zipcode_to = 0;
                 $tr->behavior = 0;
                 $tr->description = '';
                 $tr->id_tax = (int) $tax->id;
                 $tr->save();
             } else {
                 $assoc_id_tax = (int) Tools::getValue($posted_available_vat);
                 $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $assoc_id_tax);
                 if ($id_tax_rule !== false) {
                     $tr = new TaxRule((int) $id_tax_rule);
                 } else {
                     $tr = new TaxRule();
                 }
                 $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
                 $tr->id_country = (int) $country_id;
                 $tr->id_state = 0;
                 $tr->id_county = 0;
                 $tr->zipcode_from = 0;
                 $tr->zipcode_to = 0;
                 $tr->behavior = 0;
                 $tr->description = '';
                 $tr->id_tax = (int) $assoc_id_tax;
                 $tr->save();
             }
         } else {
             $this->_errors[] = Tools::displayError('Invalid parameters received');
         }
     }
 }
开发者ID:EliosIT,项目名称:PS_AchatFilet,代码行数:83,代码来源:eurovatgenerator.php

示例5: createParams

 private function createParams()
 {
     $product_types = array();
     $public_token = Tools::getValue('TAXAMOEUVAT_TOKENPUBLIC', Configuration::get('TAXAMOEUVAT_TOKENPUBLIC'));
     $res_api_product_types = $this->getResApi('https://api.taxamo.com/api/v1/dictionaries/product_types', 'GET', array('public_token' => $public_token));
     if ($res_api_product_types && isset($res_api_product_types['dictionary'])) {
         $res_product_types_dictionary = $res_api_product_types['dictionary'];
         foreach ($res_product_types_dictionary as $product_type) {
             if (isset($product_type['code'])) {
                 $product_types[] = $product_type['code'];
             }
         }
         if (count($product_types) <= 0) {
             $this->_html .= $this->displayError($this->l('Error In Product Types Dictionary'));
             return false;
         }
     } else {
         return false;
     }
     @set_time_limit(0);
     $generic_name = Tools::getValue('TAXAMOEUVAT_GENERICNAME', Configuration::get('TAXAMOEUVAT_GENERICNAME'));
     $params_tax = array();
     $res_api_countries = $this->getResApi('https://api.taxamo.com/api/v1/dictionaries/countries', 'GET', array('tax_supported' => 'true', 'public_token' => $public_token));
     if ($res_api_countries && isset($res_api_countries['dictionary'])) {
         $res_countries_dictionary = $res_api_countries['dictionary'];
         foreach ($res_countries_dictionary as $country) {
             if (isset($country['tax_supported'], $country['cca2']) && (bool) $country['tax_supported']) {
                 $id_country = Country::getByIso($country['cca2']);
                 if (!$id_country) {
                     continue;
                 }
                 foreach ($product_types as $product_type) {
                     $res_api_calculate = $this->getResApi('https://api.taxamo.com/api/v1/tax/calculate', 'GET', array('public_token' => $public_token, 'currency_code' => 'EUR', 'force_country_code' => $country['cca2'], 'buyer_tax_number' => null, 'product_type' => $product_type, 'amount' => 100));
                     if ($res_api_calculate && isset($res_api_calculate['transaction']['transaction_lines'][0])) {
                         $res_tax = $res_api_calculate['transaction']['transaction_lines'][0];
                         $tax_name = $generic_name . ' ' . $country['cca2'] . ' ' . $product_type . ' ' . trim((string) $res_tax['tax_rate']) . '%';
                         $params_tax[] = array('name' => $tax_name, 'rate' => $res_tax['tax_rate'], 'active' => 1, 'product_type' => $product_type, 'id_country' => $id_country);
                     }
                 }
             }
         }
     }
     foreach ($params_tax as $key => $tax_values) {
         if (!Validate::isGenericName($tax_values['name'])) {
             continue;
         }
         if ($id_tax = Tax::getTaxIdByName($tax_values['name'])) {
             $params_tax[$key]['id_tax'] = $id_tax;
             continue;
         }
         $tax = new Tax();
         $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $tax_values['name'];
         $tax->rate = (double) $tax_values['rate'];
         $tax->active = 1;
         if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
             $this->_html .= $this->displayError('Invalid tax properties.') . ' ' . $error;
             return false;
         }
         if (!$tax->add()) {
             $this->_html .= $this->displayError('An error occurred while importing the tax: ') . (string) $tax_values['name'];
             return false;
         }
         $params_tax[$key]['id_tax'] = $tax->id;
     }
     foreach ($product_types as $product_type) {
         $tax_group_name = $generic_name . ' - ' . $product_type;
         if (!Validate::isGenericName($tax_group_name)) {
             continue;
         }
         if (TaxRulesGroup::getIdByName($tax_group_name)) {
             $this->_html .= $this->displayError('This tax rule group cannot be saved, exists.');
             return false;
         }
         $trg = new TaxRulesGroup();
         $trg->name = $tax_group_name;
         $trg->active = 1;
         if (!$trg->save()) {
             $this->_html .= $this->displayError('This tax rule group cannot be saved.');
             return false;
         }
         foreach ($params_tax as $tax_values) {
             if ($tax_values['product_type'] == $product_type) {
                 // Creation
                 $tr = new TaxRule();
                 $tr->id_tax_rules_group = $trg->id;
                 $tr->id_country = $tax_values['id_country'];
                 $tr->id_state = 0;
                 $tr->id_county = 0;
                 $tr->zipcode_from = 0;
                 $tr->zipcode_to = 0;
                 $tr->behavior = 0;
                 $tr->description = '';
                 $tr->id_tax = $tax_values['id_tax'];
                 $tr->save();
             }
         }
     }
     return true;
 }
开发者ID:hjcalvo,项目名称:prestashop-taxamo-plugin,代码行数:99,代码来源:taxamoeuvat.php


注:本文中的TaxRulesGroup::getIdByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。