Ikodes Technology

How to Get Configurable Product Price Range in Magento 2
Hello everybody, couple of days back I got a prerequisite in which I have to show the Price Range of Configurable Product. I figured I should get all the related items and after that get the Minimum Price and Maximum Price. After some exploration in Magento Configurable Product Module I got a major lead. Fortunately Magento gives the strategy to getting the Minimum and Maximum Price. In this Post we will perceive how we can get the Range in layout record.

In your module structure make a format document catalog_product_view_type_configurable.xml, for my situation the record way is application/code/Ikodes/PriceRange/see/base/design/catalog_product_view_type_configurable.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.price">
<block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="wk.info.pricerange" template="Webkul_PriceRange::product/price_range.phtml" />
</referenceBlock>
</body>
</page>

Now, we will create template file price_range.phtml at
path app/code/Ikodes/PriceRangeCustomisation/view/base/templates/
<?php
$currentProduct = $this->getProduct();
$regularPrice = $currentProduct->getPriceInfo()->getPrice('regular_price');
?>
<div class='price-box'>
<span class="price">
<?php
echo $regularPrice->getMinRegularAmount().'-'.$regularPrice->getMaxRegularAmount();
?>
</span>
</div>

Likewise, the strategies getMinRegularAmount() and getMaxRegularAmount() restores the cost of In Stock related items as it were. For further investigation the technique definition you can allude to the record

magento_root_directory/vendor/magento/module-configurable-product/Pricing/Price/ConfigurableRegularPrice.php





Author Bio

ikodes Technology

Manager of Marketing for Red Stag Fulfillment, an ecommerce fulfillment warehouse that was born out of ecommerce. He has years of experience in ecommerce and business development. In his free time, Jake enjoys reading about business and sharing his own experience with others.

Go Back

Expand Your Digital Horizons With Us

Start a new project or take an existing one to the next level. Get in touch to start
small, scale-up, and go Agile.

    Math Captcha 57 − = 49