cancel
Showing results for 
Search instead for 
Did you mean: 

Display Out of Stock Label

SOLVED

Display Out of Stock Label

Hi,

 

I have been trying to figure out how can I display the out of stock label instead of Add to Cart when the QTY of the product is 0.

 

I have enabled the allow back orders, since from the shop, I need to be able to sell as back orders, but online I don't wont that option.

 

But when I enabled the backorder option, magento stop putting products as out of stock.

 

Does any one know how can I check if the QTY is 0 and in that case display the Out of Stock label?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Display Out of Stock Label

Hi @Manthan Dave,

I didn't manage to work with the link you suggested since I was getting an error on 'Mage'.

 

but in the mean time I manage to work something using this code:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
?>

now my next problem, is that when I set this to hide the add to cart, I could not find a way to display the Notify me when this product is in stock link.

 

Do you know how can I add this module to the view.html of the catalog?

View solution in original post

3 REPLIES 3

Re: Display Out of Stock Label

Hi @robertbits

 

i understand your problem and certainly yes you can do it that !

 

Here is the solution link of your problem refer this - https://magento.stackexchange.com/questions/69054/display-product-label-on-out-of-stock-products

 

Override in the theme or in your custom module and add the give code over there same like mention in the link and then check it will works !

 

Hope it helps

if issue solved,Click Kudos & Accept as Solution

Re: Display Out of Stock Label

Hi @Manthan Dave,

 

I have tried to do as the link said, but I ma stuck with this error and could not figure out if 'Mage' is a function in magento itself or a third party extensions since I am getting this error:

Fatal error: Uncaught Error: Class 'Mage' not found in E:\xampp\htdocs\magento\app\design\frontend\Magento\Magento_Catalog\templates\product\list.phtml:99 Stack trace: #0 E:\xampp\htdocs\magento\vendor\magento\framework\View\TemplateEngine\Php.php(59): include() #1 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\ListProduct\Interceptor), 'E:/xampp/htdocs...', Array) #2 E:\xampp\htdocs\magento\generated\code\Magento\Catalog\Block\Product\ListProduct\Interceptor.php(557): Magento\Framework\View\Element\Template->fetchView('E:/xampp/htdocs...') #3 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\Template.php(300): Magento\Catalog\Block\Product\ListProduct\Interceptor->fetchView('E:/xampp/htdocs...') #4 E:\xampp\htdocs\magento\vendor\magento\framework\View\Element\AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #5 E:\ in E:\xampp\htdocs\magento\app\design\frontend\Magento\Magento_Catalog\templates\product\list.phtml on line 99

 

Re: Display Out of Stock Label

Hi @Manthan Dave,

I didn't manage to work with the link you suggested since I was getting an error on 'Mage'.

 

but in the mean time I manage to work something using this code:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());
?>

now my next problem, is that when I set this to hide the add to cart, I could not find a way to display the Notify me when this product is in stock link.

 

Do you know how can I add this module to the view.html of the catalog?