Magento – Magento2: show price for out of stock configurable products

configurable-productmagento-2.1out-of-stockprice

Following this guide Magento 2 : How To Show Price of "out of stock" Products

I successfully managed to show price for out of stock products. But this applies only to simple products. For configurable out of stock products the price printed is always 0,00 while I would like to show the lowest price of simple products composing its parent.

How can I do it?

Best Answer

Not sure if this is applicable, but I'm on Magento 2.1.9 and there is an

issue with configurable products showing price of $0.00 when child products are out of stock on Github.

The hack, Albeit a core hack, is the only available remedy it seems.

I added the code & commented below, into

vendor/magento/module-configurable-product/Pricing/Price/ConfigurablePriceResolver.php

and it fixed my issue.

    /**
 * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
 * @return float|null
 */
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
{
    $price = null;

    foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
        $productPrice = $this->priceResolver->resolvePrice($subProduct);
        $price = $price ? min($price, $productPrice) : $productPrice;
    }

    /* fix >>> */
    $price = $price ?: $product->getData('price');
    /* <<< fix */

    return $price === null ? null : (float)$price;
}
Related Topic