1

How can I get the price range of bundle products? It's complicated as the bundle product can have different settings e.g. fixed price / dynamic price?

I tried to take Magento's core code as an example, but I failed to trace it as the price range is rendered in a _toHtml() function.

Any suggestion is welcome.

0

3 Answers 3

7
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load(YOUR_ID);
$bundleObj=$product->getPriceInfo()->getPrice('final_price');
echo $bundleObj->getMinimalPrice();// For min price
echo $bundleObj->getMaximalPrice(); // for max price

Note: I am against of direct loading object with objectManager, for better impact you can inject it in your constructor

4

Just to add to this answer for getting the min/max price, if you want it to display with currency formatted you need the raw number value. The accepted answer returns an object rather than a flat value, so you need to update it to this;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load(YOUR_ID);
$bundleObj=$product->getPriceInfo()->getPrice('final_price');
$minRaw = $bundleObj->getMinimalPrice()->getValue();// For min price
$maxRaw = $bundleObj->getMaximalPrice()->getValue(); // for max price

// Minimum price formatted
echo $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($minRaw,true,false);

// Maximum price formatted
echo $this->helper('Magento\Framework\Pricing\Helper\Data')->currency($maxRaw,true,false);
0

Bandle min/max price store in catalog_product_index_price table. You can it to product collection using method \Magento\Catalog\Model\ResourceModel\Product\Collection::addPriceData and then use for output

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.