我想在升级脚本中创建一个功能,该功能在Magento中创建2个新税率。

我查看了AdminHTML税率控制器中的ImportPost控制器,但是那里有很多工作。我希望有一种很好的简单方式:

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归因
scroll top