/**
  * @param $module
  * @return mixed
  */
 protected static function getTaxRules($module)
 {
     $taxRules = array();
     $taxRuleGroups = TaxRulesGroup::getTaxRulesGroups(true);
     foreach ($taxRuleGroups as $taxRuleGroup) {
         /** @var TaxCore $taxItem */
         $taxItem = ShopgateSettings::getTaxItemByTaxRuleGroupId($taxRuleGroup['id_tax_rules_group']);
         $rule = array('id' => $taxRuleGroup['id_tax_rules_group'], 'name' => $taxRuleGroup['name'], 'priority' => 0);
         $rule['product_tax_classes'] = array(array('id' => $taxItem->id, 'key' => is_array($taxItem->name) ? reset($taxItem->name) : ''));
         $rule['customer_tax_classes'] = array(array('key' => 'default', 'is_default' => true));
         $rule['tax_rates'] = array();
         if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) {
             $taxRulesPrestashop = TaxRule::getTaxRulesByGroupId($taxRuleGroup['id_tax_rules_group']);
         } else {
             $taxRulesPrestashop = TaxRule::getTaxRulesByGroupId($module->context->language->id, $taxRuleGroup['id_tax_rules_group']);
         }
         foreach ($taxRulesPrestashop as $idCountry => $taxRuleItem) {
             if (version_compare(_PS_VERSION_, '1.5.0.1', '>=')) {
                 $taxRuleItem = new TaxRule($taxRuleItem['id_tax_rule']);
                 $idTax = $taxRuleItem->id_tax;
                 $idCountry = $taxRuleItem->id_country;
                 $idState = $taxRuleItem->id_state;
             } else {
                 $idTax = self::getTaxIdFromTaxRule($taxRuleItem);
                 $idState = key($taxRuleItem);
             }
             /** @var TaxCore $taxItem */
             $taxItem = new Tax($idTax, $module->context->language->id);
             $country = Country::getIsoById($idCountry);
             $stateModel = new State($idState);
             $state = $stateModel->iso_code;
             $resultTaxRate = array();
             $resultTaxRate['key'] = self::getTaxRateKey($taxItem, $country, $state);
             //Fix for 1.4.x.x the taxes were exported multiple
             if (self::arrayValueExists('key', $resultTaxRate['key'], $rule['tax_rates'])) {
                 continue;
             }
             $rule['tax_rates'][] = $resultTaxRate;
         }
         if ($taxItem->active && Configuration::get('PS_TAX') == 1) {
             $taxRules[] = $rule;
         }
     }
     return $taxRules;
 }
示例#2
0
 /**
  * @return string
  */
 public function prepareTaxClass()
 {
     $taxRulesGroups = TaxRulesGroupCore::getTaxRulesGroups(true);
     $idTaxRulesGroup = (int) Product::getIdTaxRulesGroupByIdProduct($this->currentProduct->id, null);
     foreach ($taxRulesGroups as $taxRulesGroup) {
         if ($taxRulesGroup['id_tax_rules_group'] == $idTaxRulesGroup) {
             $tax = ShopgateSettings::getTaxItemByTaxRuleGroupId($idTaxRulesGroup);
             $taxClassName = '';
             if (is_array($tax->name) && !empty($tax->name[$this->getPlugin()->getLanguageId()])) {
                 $taxClassName = $tax->name[$this->getPlugin()->getLanguageId()];
             } else {
                 if (is_array($tax->name)) {
                     // fallback: just in case for older Prestashop versions
                     $taxClassName = reset($tax->name);
                 }
             }
             return $taxClassName;
         }
     }
     return '';
 }