4

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?

4
  • Did you find a solution for this issue? Commented Feb 23, 2017 at 12:59
  • No, unfortunenately Commented Feb 23, 2017 at 13:05
  • Did you figure it out ? Commented Dec 5, 2018 at 22:42
  • Refer This Magento 2 How To Display Out Of Stock Product’s Price Commented Nov 26, 2021 at 10:29

3 Answers 3

5

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; } 
1
  • 1
    I have tried this solution and its also working for me as well. Commented Nov 17, 2017 at 5:27
0

@gianis6 We have the same issue and tracked it back to the LinkedProductSelectBuilderComposite which builds a bunch of SELECT statements. Each of the linkedProductSelectBuilder objects in that class get the StockStatusBaseSelectProcessor class injected into it (module-catalog-inventory/etc/di.xml). That stock status base select processor adds the table and where clause needed to restrict products that are out of stock.

So, my solution is to remove the StockStatusBaseSelectProcessor from the CompositeBaseSelectProcessor when building the select statements.

WARNING: This code may be used by several components in Magento 2. We're still testing to see if it has any adverse effects. If you use this, please run a full UAT to make sure it doesn't break other code.

In the {Vendor}/{Module}/etc/di.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor" type="{Vendor}\{Module}\Model\ResourceModel\Product\CompositeBaseSelectProcessor" /> </config> 

In the {Vendor}/{Module}/Model/ResourceModel/Product/CompositeBaseSelectProcessor.php

namespace {Vendor}\{Module}\Model\ResourceModel\Product; use Magento\CatalogInventory\Model\ResourceModel\Product\StockStatusBaseSelectProcessor; class CompositeBaseSelectProcessor extends \Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor { public function __construct( array $baseSelectProcessors ) { // REMOVE THE STOCK STATUS PROCESSOR //................................... $finalProcessors = array(); foreach ($baseSelectProcessors as $baseSelectProcessor) { if(!is_a($baseSelectProcessor, StockStatusBaseSelectProcessor::class)) { $finalProcessors[] = $baseSelectProcessor; } } parent::__construct($finalProcessors); } } 

Any other ideas on how to selectively remove the StockStatusBaseSelectProcessor only when we need to would be greatly appreciated.

0

Magento still has this problem on 2.4.6 p_1.. when all children of config product is out of stock, the price that returns is 0.

Any legit solution???

my way is this ->

 $finalPrice = $product->getFinalPrice() > 0 ? $product->getFinalPrice() : $this->getConfigFinalPrice($product); public function getConfigFinalPrice(Product $product) { $childProducts = $product->getTypeInstance()->getUsedProducts($product); return $childProducts[0] ? $childProducts[0]->getPriceInfo()->getPrice('final_price')->getAmount()->getValue() : 0; } 

any suggestions??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.