سؤال

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.

هل كانت مفيدة؟

المحلول

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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top