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


PHP TaxRulesGroup::add方法代码示例

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


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

示例1: taxamoCreateParams

 public static function taxamoCreateParams()
 {
     $res_craete_params = array('error' => null, 'success' => false);
     $product_types = array();
     $public_token = Tools::getValue('TAXAMOEUVAT_TOKENPUBLIC', Configuration::get('TAXAMOEUVAT_TOKENPUBLIC'));
     $res_api_product_types = self::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) {
             $res_craete_params['error'] = 'Error In Product Types Dictionary';
             return $res_craete_params;
         }
     } else {
         $res_craete_params['error'] = 'Error In API Product Types Dictionary';
         return $res_craete_params;
     }
     @set_time_limit(0);
     $generic_name = Tools::getValue('TAXAMOEUVAT_GENERICNAME', Configuration::get('TAXAMOEUVAT_GENERICNAME'));
     $params_tax = array();
     $res_api_countries = self::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;
                     $res_craete_params['error'] = 'Error In Procedure Countries';
                     return $res_craete_params;
                 }
                 foreach ($product_types as $product_type) {
                     $res_api_calculate = self::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);
                     } else {
                         $res_craete_params['error'] = 'Error In API Tax Calculate';
                         return $res_craete_params;
                     }
                 }
             }
         }
         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;
//.........这里部分代码省略.........
开发者ID:hjcalvo,项目名称:prestashop-taxamo-plugin,代码行数:101,代码来源:Tools.php

示例2: importTaxRulesGroups

 protected function importTaxRulesGroups()
 {
     $this->truncateTables(array('tax_rules_group', 'tax_rules_group_shop'));
     $handle = $this->openCsvFile('tax_rule_groups.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('TaxRulesGroup', $this->tax_rule_group_fields, $line);
         if (!isset($fields['id'])) {
             $tax_rule_group = new TaxRulesGroup($line[0]);
             $tax_rule_group->id = $line[0];
         } else {
             $tax_rule_group = new TaxRulesGroup($fields['id']);
         }
         foreach ($fields as $key => $field) {
             $tax_rule_group->{$key} = $field;
         }
         $tax_rule_group->force_id = true;
         if (!$res) {
             $res = $tax_rule_group->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }
开发者ID:evgrishin,项目名称:se1614,代码行数:24,代码来源:AdminSampleDataInstallImport.php


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