Magento – Get bundle product price including tax

bundled-productmagento-1.7price

I am trying to get product prices both inclusive and exclusive tax in custom export script.

To get product price with inclusive tax I used this code.

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

This working fine for simple product.

But For Bundle product how we can get price inclusive tax.

Bundle product price type is dynamic.

And I have used this code to retrieve bundle product price.

$bundlePriceModel = Mage::getModel('bundle/product_price');
 $selectionCollection = $_product->getTypeInstance(true)->getSelectionsCollection(
                      $_product->getTypeInstance(true)->getOptionsIds($_product), $_product
                  );

                  $itemPrice = 0;
                 foreach($selectionCollection as $_option) {                             
                            $itemPrice += $bundlePriceModel->getSelectionFinalTotalPrice($_product, $_option,1, $_option->getData('selection_qty'), true, true );
                            }  

Best Answer

The price of a bundled product is calculated in the class Mage_Bundle_Model_Product_Price, in the function getFinalPrice() to be exact. When you look into this function you’ll notice two lines in particular:

$finalPrice = $product->getData('final_price');
$finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
$finalPrice += $this->getTotalBundleItemsPrice($product, $qty);

And for tax

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());

EDIT

or you can also use direct function to display price with tax

Mage::getModel('bundle/product_price');
public function getTotalPrices($product, $which = null, $includeTax = null, $takeTierPrice = true)

See for calculation

hope this will sure help you.