3

I can get tax amount by

$order->getTaxAmount();

But how can I get tax name applied to order.

I used this

$taxClassId = $order->getTaxClassId();
$taxClassName = Mage::getModel('tax/class')->load($taxClassId)->getClassName();

But it is not working.

Any help.

2 Answers 2

5

Order data doesn't hold tax class id (check what can you get from order regarding tax), which is why you cannot get it from there. But you can work around to it.

You can call tax class this way:

$items = $order->getAllItems();
foreach($items as $item){
   $productId = $item->getProductId();
   $_product = Mage::getModel('catalog/product')->load($productId);
   $taxClassId = $_product->getTaxClassId();
   $taxClass = Mage::getModel('tax/class')->load($taxClassId);
   $taxClassName = $taxClass->getClassName();
   echo $taxClassName."<br>";
}

Since tax class is applied to individual product in magento, it may have different class for different products within a order.

Here we are going through each item in order and then getting tax class of those items.

Hope this helps.

3
  • Can you answer this @AdarshKhatri magento.stackexchange.com/questions/119706/… Commented Jun 7, 2016 at 10:38
  • But tax class id for a product can be changed and if you want to get info from an old order/item you get the wrong value ... I am not sure how it works but tax class are recorded here for every order_item sales_order_tax_item
    – Fra
    Commented Aug 10, 2017 at 15:49
  • $order->getFullTaxInfo() this might have the code right?
    – arqam
    Commented Sep 30, 2019 at 11:20
0

If you're running Community edition 1.6+, the catalog module has a very nice method to get tax name without loading the entire product.

Here is how to achieve it:

$_resource = $this->getProduct()->getResource();
$items = $order->getAllItems();
foreach($items as $item){
   $productId = $item->getProductId();
   $taxClassId = $_resource->getAttributeRawValue($_item, 'tax_class_id', Mage::app()->getStore());
   $taxClass = Mage::getModel('tax/class')->load($taxClassId);
   $taxClassName = $taxClass->getClassName();
   echo $taxClassName;
   echo PHP_EOL;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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