Magento 2 : How To Show Price of "out of stock" Products
This one adds to Sohel Rana's answer. Tested on 2.3.3 for configurable products
For any of the product out of stock:
In your di.xml
<preference for="Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox" type="<Vendor>\<Module>\Pricing\Render\FinalPriceBox" />
And in \\Pricing\Render\FinalPriceBox.php
namespace <Vendor>\<Module>\Pricing\Render;
use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox;
class FinalPriceBox extends \Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox
{
protected function _toHtml()
{
$result = BasePriceBox::_toHtml();
//Renders MSRP in case it is enabled
if ($this->isMsrpPriceApplicable()) {
/** @var BasePriceBox $msrpBlock */
$msrpBlock = $this->rendererPool->createPriceRender(
MsrpPrice::PRICE_CODE,
$this->getSaleableItem(),
[
'real_price_html' => $result,
'zone' => $this->getZone(),
]
);
$result = $msrpBlock->toHtml();
}
return $this->wrapResult($result);
}
}
For all sub-products out of stock:
In your di.xml
<type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\LinkedProductSelectBuilder">
<arguments>
<argument name="baseSelectProcessor" xsi:type="object"><Vendor>\<Module>\Model\ConfigurableProduct\ResourceModel\Product\StockStatusBaseSelectProcessor</argument>
</arguments>
</type>
And remove stock select
namespace <Vendor>\<Module>\Model\ConfigurableProduct\ResourceModel\Product;
use Magento\Framework\DB\Select;
class StockStatusBaseSelectProcessor extends \Magento\ConfigurableProduct\Model\ResourceModel\Product\StockStatusBaseSelectProcessor
{
public function process(Select $select)
{
return $select;
}
}
You need to modify some logic for that. So create a new module and add following code.
Vendor/Module/etc/frontend/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\Pricing\Render\FinalPriceBox" type="Vendor\Module\Pricing\Render\FinalPriceBox" /> </config>
Vendor/Module/Pricing/Render/FinalPriceBox.php
namespace Vendor\Module\Pricing\Render; use Magento\Msrp\Pricing\Price\MsrpPrice; use Magento\Framework\Pricing\Render\PriceBox as BasePriceBox; class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox { protected function _toHtml() { $result = parent::_toHtml(); if(!$result) { $result = BasePriceBox::_toHtml(); try { /** @var MsrpPrice $msrpPriceType */ $msrpPriceType = $this->getSaleableItem()->getPriceInfo()->getPrice('msrp_price'); } catch (\InvalidArgumentException $e) { $this->_logger->critical($e); return $this->wrapResult($result); } //Renders MSRP in case it is enabled $product = $this->getSaleableItem(); if ($msrpPriceType->canApplyMsrp($product) && $msrpPriceType->isMinimalPriceLessMsrp($product)) { /** @var BasePriceBox $msrpBlock */ $msrpBlock = $this->rendererPool->createPriceRender( MsrpPrice::PRICE_CODE, $this->getSaleableItem(), [ 'real_price_html' => $result, 'zone' => $this->getZone(), ] ); $result = $msrpBlock->toHtml(); } return $this->wrapResult($result); } return $result; } }
NOPE. 3rd try with different solutions and this also does absolutely nothing. Out of stock items have no price. Any other thoughts on a working solution for Magento 2.2.6