Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento get price including tax in a none-template file

Tags:

php

get

magento

At the moment i am trying to get the product price including tax in a php file for my product feed. I have this code at the moment:

$_product = Mage::getModel('catalog/product')->load($productId);
$_priceIncludingTax = $this->helper('tax')
                               ->getPrice($_product, $_product->getFinalPrice());

Problem is that since that of course the '$this->' part doesn't work so well from the file. Anyone know how i can still get the price including tax in this file?

like image 795
Wesley Smits Avatar asked Nov 08 '12 11:11

Wesley Smits


2 Answers

You can get a helper-instance in any file using:

Mage::helper('tax')

Your full code is:

$_product = Mage::getModel('catalog/product')->load($productId);
$_priceIncludingTax = Mage::helper('tax')
    ->getPrice($_product, $_product->getFinalPrice());
like image 137
Alex Avatar answered Nov 18 '22 08:11

Alex


Thanks @Alex:

If the product has FinalPrice special price is the final price of the product to access the most serious tax base price:

    $_product = Mage::getModel('catalog/product')->load($p->getId());

    $_specialPriceIncTax = Mage::helper('tax')
        ->getPrice($_product, $_product->getFinalPrice());

    $_priceTax = Mage::helper('tax')
        ->getPrice($_product, $_product->getPrice());
like image 27
jruzafa Avatar answered Nov 18 '22 09:11

jruzafa