Question

I am able to get Bundle and Configurable Regular Price of Product. But Special Price there is no min max available.

Below is code which I tried for regular configurable price but same is not working for special Price

    $product = $this->modelProduct->load(745);
    $configPrice=$product->getPriceInfo()->getPrice('regular_price');
    echo '=>'. $configPrice->getMinRegularAmount();// For min price
    echo '=>'. $configPrice->getMaxRegularAmount();// For max price
Était-ce utile?

La solution

Try this function for Special Price Range (it works for me)

public function getSpecialPriceRange($product)
    {
        $specialChildProductPrice = [];
        $specialChildProduct = $this->configurableProduct->getUsedProducts($product);
        foreach ($specialChildProduct as $child) {
            $specialPrice = $child->getSpecialPrice();
            if ($specialPrice !=0 and !is_null($specialPrice)) {
                $specialPrice = number_format($specialPrice, 2, '.', '');
                $specialChildProductPrice[] = $specialPrice;
            }
        }
        if (count($specialChildProductPrice)==0) {
            return '';
        }
        $maxInt = max($specialChildProductPrice);
        $minInt = min($specialChildProductPrice);
        if ($maxInt == 0) {
            return '';
        }
        $max = $this->pricingHelper->currencyByStore($maxInt);
        $min = $this->pricingHelper->currencyByStore($minInt);


        if ($min==$max) {
            return $this->getPriceRender($product, "$min", '', 'special-price');
        } else {
            return $this->getPriceRender($product, "$min - $max", '', 'special-price');
        }
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top