Magento 2: How to show Prices for OUT of stock products












1














I'm pretty new to Magento in general and just started working with Magento 2.



Here is my question - How to show prices for all out of stock products?



There is this topic: Magento 2 : How To Show Price of "out of stock" Products



And apparently it works, but half of the instructions don't make sense to me.
After creating custom module, what should I do with it? Should I change anything else anywhere?



Thanks!










share|improve this question
























  • Did you enable your module?
    – Abbas
    Feb 16 '17 at 2:09










  • Good question. I'm not sure how to do it :)
    – Dmitrii Kustov
    Feb 16 '17 at 2:21










  • run php bin/magento setup:upgrade command to activate your module
    – Manthan Dave
    Feb 16 '17 at 4:51










  • Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
    – Teja Bhagavan Kollepara
    May 18 '17 at 4:19










  • Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
    – vagg
    Aug 29 '18 at 13:46
















1














I'm pretty new to Magento in general and just started working with Magento 2.



Here is my question - How to show prices for all out of stock products?



There is this topic: Magento 2 : How To Show Price of "out of stock" Products



And apparently it works, but half of the instructions don't make sense to me.
After creating custom module, what should I do with it? Should I change anything else anywhere?



Thanks!










share|improve this question
























  • Did you enable your module?
    – Abbas
    Feb 16 '17 at 2:09










  • Good question. I'm not sure how to do it :)
    – Dmitrii Kustov
    Feb 16 '17 at 2:21










  • run php bin/magento setup:upgrade command to activate your module
    – Manthan Dave
    Feb 16 '17 at 4:51










  • Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
    – Teja Bhagavan Kollepara
    May 18 '17 at 4:19










  • Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
    – vagg
    Aug 29 '18 at 13:46














1












1








1







I'm pretty new to Magento in general and just started working with Magento 2.



Here is my question - How to show prices for all out of stock products?



There is this topic: Magento 2 : How To Show Price of "out of stock" Products



And apparently it works, but half of the instructions don't make sense to me.
After creating custom module, what should I do with it? Should I change anything else anywhere?



Thanks!










share|improve this question















I'm pretty new to Magento in general and just started working with Magento 2.



Here is my question - How to show prices for all out of stock products?



There is this topic: Magento 2 : How To Show Price of "out of stock" Products



And apparently it works, but half of the instructions don't make sense to me.
After creating custom module, what should I do with it? Should I change anything else anywhere?



Thanks!







magento2 out-of-stock product-prices






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:55









Community

1




1










asked Feb 16 '17 at 0:10









Dmitrii Kustov

3511




3511












  • Did you enable your module?
    – Abbas
    Feb 16 '17 at 2:09










  • Good question. I'm not sure how to do it :)
    – Dmitrii Kustov
    Feb 16 '17 at 2:21










  • run php bin/magento setup:upgrade command to activate your module
    – Manthan Dave
    Feb 16 '17 at 4:51










  • Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
    – Teja Bhagavan Kollepara
    May 18 '17 at 4:19










  • Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
    – vagg
    Aug 29 '18 at 13:46


















  • Did you enable your module?
    – Abbas
    Feb 16 '17 at 2:09










  • Good question. I'm not sure how to do it :)
    – Dmitrii Kustov
    Feb 16 '17 at 2:21










  • run php bin/magento setup:upgrade command to activate your module
    – Manthan Dave
    Feb 16 '17 at 4:51










  • Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
    – Teja Bhagavan Kollepara
    May 18 '17 at 4:19










  • Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
    – vagg
    Aug 29 '18 at 13:46
















Did you enable your module?
– Abbas
Feb 16 '17 at 2:09




Did you enable your module?
– Abbas
Feb 16 '17 at 2:09












Good question. I'm not sure how to do it :)
– Dmitrii Kustov
Feb 16 '17 at 2:21




Good question. I'm not sure how to do it :)
– Dmitrii Kustov
Feb 16 '17 at 2:21












run php bin/magento setup:upgrade command to activate your module
– Manthan Dave
Feb 16 '17 at 4:51




run php bin/magento setup:upgrade command to activate your module
– Manthan Dave
Feb 16 '17 at 4:51












Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
– Teja Bhagavan Kollepara
May 18 '17 at 4:19




Possible duplicate of Magento 2 : How To Show Price of "out of stock" Products
– Teja Bhagavan Kollepara
May 18 '17 at 4:19












Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
– vagg
Aug 29 '18 at 13:46




Fatal error: Uncaught RuntimeException: Can't create directory /var/www/html/generated/code/Magento/Directory/Helper/Data/. in [MagentoDirectoryHelperDataProxy] in /var/www/html/vendor/magento/framework/Code/Generator.php:115 Stack trace: #0 /var/www/html/vendor/magento/framework/Code/Generator/Autoloader.php(35): MagentoFrameworkCodeGenerator->generateClass('Magento\Directo...') #1 [internal function]: MagentoFrameworkCodeGeneratorAutoloader->load('Magento\Directo...') #2 [internal function]: spl_autoload_call('Magento\Directo...') #3 /var/www/html/vendor/magento/framework/Objec
– vagg
Aug 29 '18 at 13:46










1 Answer
1






active

oldest

votes


















2














You need to create your custom module using below code



Let say module name Custom_Outofstock



So create folder in app/code



Create registration.php file at app/code/Custom/Outofstock/registration.php



Add below code to it:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Outofstock',
__DIR__
);


Create module.xml at app/code/Custom/Outofstock/etc/module.xml



Add below code to it:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Outofstock" setup_version="2.0.0">
</module>
</config>


Now create file suggested in this
answer given By Sohel Rana as below



Create di.xml at app/code/Custom/Outofstock/etc/di.xml



Add below code to it:



<?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="MagentoCatalogPricingRenderFinalPriceBox" type="CustomOutofstockPricingRenderFinalPriceBox" />
</config>


Create Price render file FinalPriceBox.php at app/code/Custom/Outofstock/Pricing/Render/FinalPriceBox.php



Add below code to it:



<?php
namespace CustomOutofstockPricingRender;

use MagentoMsrpPricingPriceMsrpPrice;
use MagentoFrameworkPricingRenderPriceBox as BasePriceBox;

class FinalPriceBox extends MagentoCatalogPricingRenderFinalPriceBox
{
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;
}
}


Now run below command to enable module:



php bin/magento setup:upgrade


Flush cache using below command:



php bin/magento cache:flush





share|improve this answer























  • Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
    – Dmitrii Kustov
    Feb 16 '17 at 18:16












  • Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
    – Dmitrii Kustov
    Feb 16 '17 at 18:22










  • So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
    – Dmitrii Kustov
    Feb 16 '17 at 18:45










  • Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
    – Prashant Valanda
    Feb 17 '17 at 5:45












  • Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
    – Gediminas
    Jun 28 '17 at 13:51











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f160145%2fmagento-2-how-to-show-prices-for-out-of-stock-products%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You need to create your custom module using below code



Let say module name Custom_Outofstock



So create folder in app/code



Create registration.php file at app/code/Custom/Outofstock/registration.php



Add below code to it:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Outofstock',
__DIR__
);


Create module.xml at app/code/Custom/Outofstock/etc/module.xml



Add below code to it:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Outofstock" setup_version="2.0.0">
</module>
</config>


Now create file suggested in this
answer given By Sohel Rana as below



Create di.xml at app/code/Custom/Outofstock/etc/di.xml



Add below code to it:



<?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="MagentoCatalogPricingRenderFinalPriceBox" type="CustomOutofstockPricingRenderFinalPriceBox" />
</config>


Create Price render file FinalPriceBox.php at app/code/Custom/Outofstock/Pricing/Render/FinalPriceBox.php



Add below code to it:



<?php
namespace CustomOutofstockPricingRender;

use MagentoMsrpPricingPriceMsrpPrice;
use MagentoFrameworkPricingRenderPriceBox as BasePriceBox;

class FinalPriceBox extends MagentoCatalogPricingRenderFinalPriceBox
{
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;
}
}


Now run below command to enable module:



php bin/magento setup:upgrade


Flush cache using below command:



php bin/magento cache:flush





share|improve this answer























  • Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
    – Dmitrii Kustov
    Feb 16 '17 at 18:16












  • Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
    – Dmitrii Kustov
    Feb 16 '17 at 18:22










  • So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
    – Dmitrii Kustov
    Feb 16 '17 at 18:45










  • Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
    – Prashant Valanda
    Feb 17 '17 at 5:45












  • Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
    – Gediminas
    Jun 28 '17 at 13:51
















2














You need to create your custom module using below code



Let say module name Custom_Outofstock



So create folder in app/code



Create registration.php file at app/code/Custom/Outofstock/registration.php



Add below code to it:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Outofstock',
__DIR__
);


Create module.xml at app/code/Custom/Outofstock/etc/module.xml



Add below code to it:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Outofstock" setup_version="2.0.0">
</module>
</config>


Now create file suggested in this
answer given By Sohel Rana as below



Create di.xml at app/code/Custom/Outofstock/etc/di.xml



Add below code to it:



<?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="MagentoCatalogPricingRenderFinalPriceBox" type="CustomOutofstockPricingRenderFinalPriceBox" />
</config>


Create Price render file FinalPriceBox.php at app/code/Custom/Outofstock/Pricing/Render/FinalPriceBox.php



Add below code to it:



<?php
namespace CustomOutofstockPricingRender;

use MagentoMsrpPricingPriceMsrpPrice;
use MagentoFrameworkPricingRenderPriceBox as BasePriceBox;

class FinalPriceBox extends MagentoCatalogPricingRenderFinalPriceBox
{
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;
}
}


Now run below command to enable module:



php bin/magento setup:upgrade


Flush cache using below command:



php bin/magento cache:flush





share|improve this answer























  • Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
    – Dmitrii Kustov
    Feb 16 '17 at 18:16












  • Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
    – Dmitrii Kustov
    Feb 16 '17 at 18:22










  • So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
    – Dmitrii Kustov
    Feb 16 '17 at 18:45










  • Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
    – Prashant Valanda
    Feb 17 '17 at 5:45












  • Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
    – Gediminas
    Jun 28 '17 at 13:51














2












2








2






You need to create your custom module using below code



Let say module name Custom_Outofstock



So create folder in app/code



Create registration.php file at app/code/Custom/Outofstock/registration.php



Add below code to it:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Outofstock',
__DIR__
);


Create module.xml at app/code/Custom/Outofstock/etc/module.xml



Add below code to it:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Outofstock" setup_version="2.0.0">
</module>
</config>


Now create file suggested in this
answer given By Sohel Rana as below



Create di.xml at app/code/Custom/Outofstock/etc/di.xml



Add below code to it:



<?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="MagentoCatalogPricingRenderFinalPriceBox" type="CustomOutofstockPricingRenderFinalPriceBox" />
</config>


Create Price render file FinalPriceBox.php at app/code/Custom/Outofstock/Pricing/Render/FinalPriceBox.php



Add below code to it:



<?php
namespace CustomOutofstockPricingRender;

use MagentoMsrpPricingPriceMsrpPrice;
use MagentoFrameworkPricingRenderPriceBox as BasePriceBox;

class FinalPriceBox extends MagentoCatalogPricingRenderFinalPriceBox
{
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;
}
}


Now run below command to enable module:



php bin/magento setup:upgrade


Flush cache using below command:



php bin/magento cache:flush





share|improve this answer














You need to create your custom module using below code



Let say module name Custom_Outofstock



So create folder in app/code



Create registration.php file at app/code/Custom/Outofstock/registration.php



Add below code to it:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Custom_Outofstock',
__DIR__
);


Create module.xml at app/code/Custom/Outofstock/etc/module.xml



Add below code to it:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Outofstock" setup_version="2.0.0">
</module>
</config>


Now create file suggested in this
answer given By Sohel Rana as below



Create di.xml at app/code/Custom/Outofstock/etc/di.xml



Add below code to it:



<?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="MagentoCatalogPricingRenderFinalPriceBox" type="CustomOutofstockPricingRenderFinalPriceBox" />
</config>


Create Price render file FinalPriceBox.php at app/code/Custom/Outofstock/Pricing/Render/FinalPriceBox.php



Add below code to it:



<?php
namespace CustomOutofstockPricingRender;

use MagentoMsrpPricingPriceMsrpPrice;
use MagentoFrameworkPricingRenderPriceBox as BasePriceBox;

class FinalPriceBox extends MagentoCatalogPricingRenderFinalPriceBox
{
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;
}
}


Now run below command to enable module:



php bin/magento setup:upgrade


Flush cache using below command:



php bin/magento cache:flush






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday









Ordog

10812




10812










answered Feb 16 '17 at 5:31









Prashant Valanda

9,49912353




9,49912353












  • Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
    – Dmitrii Kustov
    Feb 16 '17 at 18:16












  • Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
    – Dmitrii Kustov
    Feb 16 '17 at 18:22










  • So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
    – Dmitrii Kustov
    Feb 16 '17 at 18:45










  • Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
    – Prashant Valanda
    Feb 17 '17 at 5:45












  • Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
    – Gediminas
    Jun 28 '17 at 13:51


















  • Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
    – Dmitrii Kustov
    Feb 16 '17 at 18:16












  • Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
    – Dmitrii Kustov
    Feb 16 '17 at 18:22










  • So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
    – Dmitrii Kustov
    Feb 16 '17 at 18:45










  • Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
    – Prashant Valanda
    Feb 17 '17 at 5:45












  • Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
    – Gediminas
    Jun 28 '17 at 13:51
















Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
– Dmitrii Kustov
Feb 16 '17 at 18:16






Thanks for the answer! However, after doing this, all the css was overwritten with default css which came with theme. And products are not displaying whatsoever, instead I get this message: "We're sorry, an error has occurred while generating this email". In exception log i have this message: "[2017-02-13 17:11:58] main.CRITICAL: exception 'MagentoFrameworkExceptionLocalizedException' with message 'The element 'product.info.options' already has a child with alias 'default'' in /home/uspatriot/public_html/vendor/magento/framework/Data/Structure.php:611" Any ideas what happened?
– Dmitrii Kustov
Feb 16 '17 at 18:16














Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
– Dmitrii Kustov
Feb 16 '17 at 18:22




Actually, after enabling developer mode, then disabling it, and then enabling production mode, this is the error I get now: "Fatal error: Class 'VendorModulePricingRenderFinalPriceBox' not found in /home/uspatriot/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93"
– Dmitrii Kustov
Feb 16 '17 at 18:22












So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
– Dmitrii Kustov
Feb 16 '17 at 18:45




So, I figured there was a mistake in di.xml. After changing type from "VendorModulePricingRenderFinalPriceBox" to "CustomOutofstockPricingRenderFinalPriceBox", and re-enabling production mode, it all works now!
– Dmitrii Kustov
Feb 16 '17 at 18:45












Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
– Prashant Valanda
Feb 17 '17 at 5:45






Yes that is error I forgot to modify it. I have updated code thanks for acknowledge
– Prashant Valanda
Feb 17 '17 at 5:45














Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
– Gediminas
Jun 28 '17 at 13:51




Is there any modification to show "as low as" price only of "in stock" products on configurable product? magento.stackexchange.com/questions/181053/…
– Gediminas
Jun 28 '17 at 13:51


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f160145%2fmagento-2-how-to-show-prices-for-out-of-stock-products%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1300-talet

1300-talet

Display a custom attribute below product name in the front-end Magento 1.9.3.8