Magento 1 get net or gross price
Sometimes there is a lot confusion how to get net or gross price in Magento 1. In this post I give you details on how to get the correct value.
Magento 1 get net or gross price
In short, you get the desired type of price with the following code snippet:
- gross:1$gross_price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);
- net:1$net_price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), false);
As you can see, you can use a core function from Magento tax helper class. This getPrice() function needs a product model and a price. The third param, a boolean defines if you want to get it’s gross value or if it false it’s net value. All this depends on your current tax settings for current store. If there you have for example 0% tax, you will get the same value.
Use cases
In your Magento adminhtml you can set default rules for prices. If you have ever seen price.phtml, you may know that the price output is very complicated and depends on a lot of settings. Basically there are two options on how to set up your product prices:
- including tax
- excluding tax
You can change this settings in System->Sales->Tax->Calculation Settings->Catalog Prices. Depending on this setting by website, all product prices you set on your product detail page are net (exluding tax) or gross (including tax). Depending on this frontend prices are different (tax is added or prices is reduced by tax). You need the net or gross display separation for prices for different use cases. Some possible are:
- frontend display
for example if you want to display both (net and gross) value - export
if you run a customized export of products and prices where you need net and gross prices (or event more, for example special prices, tier prices, …)
Conclusion
Magento offers you a neat function to display net or gross prices. This function always displays correct values regardless if you set catalog prices to include or exclude tax.