4

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?

15

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();
  • Curious how well this would work when used in conjunction with a tax lookup service. Do a lookup on customer's tax rate and then programmatically store it in the backend if it doesn't already exist... – pspahn Aug 8 '13 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.