How to Get the Price Range of Bundle Products in Magento 2
Magento 2 Bundled Product is a composite product that has a number of simple or virtual products. The price of bundled products can be either a dynamic or fixed value.
For a fixed price for a bundle product, you can enter a base price with applied taxes for it. For the dynamic price, enter the price range from least expensive to the most expensive price.
However, when you are selling such bundled products on multiple sales channels such as Facebook store where you can display only one price. At that time, you either show the minimum or the maximum price for which you need to get the price range of bundle products in Magento 2.
The below programmatic method gives the code for the same.
Method to Get the Price Range of Bundle Products in Magento 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php namespace [Vendor]\[Module]\Helper; use Magento\Framework\App\Helper\Context; use Magento\Catalog\Model\Product; class Data extends AbstractHelper { protected $product; public function __construct( Context $context, Product $product ) { $this->product = $product; parent::__construct($context); } public function getPrice($productId) { $productObj = $this->product->load($productId); $finalPrice = $productObj->getPriceInfo()->getPrice('final_price')->getValue(); $minimumPrice = $productObj->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue(); $maximumPrice = $productObj->getPriceInfo()->getPrice('final_price')->getMaximalPrice()->getValue(); } } |
Any doubts? Mention them in the Comments section below. I’d help you out.
Do share the solution with fellow developers via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Add Attachments with Email in Magento 2.3.x
How To Enable GZIP Compression for Magento
Next