8

I'm trying to get the tax rate (just the value) for a product. I can get the Tax Class Id doing $product->getTaxClassId().

It seems incredible, but I can't find the way to get the value. Not the Price with the included tax or the tax amount but the percentage applied to the final price.

Can anyone help?

Thanks in advanced.

26

To get the tax rate you need to perform a tax request. That can be done with the following code.

$store = Mage::app()->getStore('default');
$taxCalculation = Mage::getModel('tax/calculation');
$request = $taxCalculation->getRateRequest(null, null, null, $store);
$taxClassId = $product->getTaxClassId();
$percent = $taxCalculation->getRate($request->setProductClassId($taxClassId));

Here you take the store and make a tax calculation request. You can also specify shipping address, billing address and customer tax class id but in this case I have set them to null and it will take the default values set-up in the admin configuration tax section.

You then take the tax rate request object and assign the product class id, which you already have and then you can ask for the rate itself.

  • Thank you David. I was trying others code snippets with no result, but you are the man! – Pymoo May 2 '14 at 7:35
  • I used this, but I only needed the info for one of my stores (creating a google product feed) and ran into trouble using the store id in the getRateRequest() method, as its looking for a store object and not the store Id. I substituted the store id for 'default' in the getStore() method and all is well. thanks. – Jon Jul 27 '15 at 22:32

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.