Как программатически создавать налоговые ставки

magento.stackexchange https://magento.stackexchange.com/questions/3480

  •  16-10-2019
  •  | 
  •  

Вопрос

Я хочу создать функцию в сценарии обновления, который создает 2 новые налоговые ставки в Magento.

Я посмотрел на контроллер ImportPost в контроллере налоговых ставок AdminHTML, но там много работы. Я надеялся на хороший легкий способ, как:

Mage::getModel('tax model')->setData('tax rate data')->save()

Кто-нибудь знает, как это сделать?

Это было полезно?

Решение

Вот как я создал новое налоговое правило в облегчении для австралийского магазина:

//get the product tax class
$productTaxClass = Mage::getModel('tax/class')
    ->getCollection()
    ->addFieldToFilter('class_name', 'Taxable Goods')
    ->load()
    ->getFirstItem();

//get the customer tax class
$customerTaxClass = Mage::getModel('tax/class')
    ->getCollection()
    ->addFieldToFilter('class_name', 'Retail Customer')
    ->load()
    ->getFirstItem();

//create a new australia tax rate/zone
$taxCalculationRate = Mage::getModel('tax/calculation_rate')
    ->setData(array(
        "code"                  => "GST",
        "tax_country_id"        => "AU",
        "tax_region_id"         => "0",
        "zip_is_range"          => "0",
        "tax_postcode"          => "*",
        "rate"                  => "10",
    ))->save();

//create a new tax rule
$ruleModel = Mage::getModel('tax/calculation_rule')
    ->setData(array(
        "code"                  => "GST",
        "tax_customer_class"    => array($customerTaxClass->getId()),
        "tax_product_class"     => array($productTaxClass->getId()),
        "tax_rate"              => array($taxCalculationRate->getId()),
        "priority"              => "0",
        "position"              => "0",
    ))->save();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top