Question

I would like to fetch and display bundle product sales price on the PDP page in the custom block programmatically (what ever the default options selected)

Can any one advise me the solution.

Was it helpful?

Solution

Try this code

$productId = 46; //any bundle product id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
//get all the selection products used in bundle product.
$selectionCollection = $product->getTypeInstance(true)
    ->getSelectionsCollection(
        $product->getTypeInstance(true)->getOptionsIds($product),
        $product
    );
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$final_price = 0;
foreach ($selectionCollection as $proselection) {
    $selectionArray = [];
    //print_r($proselection->getData());

    if ($proselection->getIsDefault()) {
        echo $proselection->getName();
        echo '-> ';
        $formattedCurrencyValue = $priceHelper->currency($proselection->getPrice(), true, false);
        echo $formattedCurrencyValue;
        echo '<br>';
        $final_price = $final_price + $proselection->getPrice();
    }
}
$formattedCurrencyValue = $priceHelper->currency($final_price, true, false);
echo "<br/>Final Price Is " . $formattedCurrencyValue;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top