Question

I want to create a feature in an upgrade script that creates 2 new tax rates in Magento.

I looked at the importPost controller in adminhtml tax rates controller, but there is a lot of work in there. I was hoping for a nice easy way kind of like:

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

Anyone know how to do this?

Was it helpful?

Solution

This is how I created a new tax rule in an upgradescript for an Australian shop:

//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();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top