Magento 1.9 – How to Get Tax Name in Sales Order

magento-1.9sales-ordertax

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.

Best Answer

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.

Related Topic