1

I would like to display the stock status (In Stock | Sold Out) on the product page.

How can I achieve that?

4 Answers 4

4

To display the "out of stock" and "in stock" label on product view page, write the below code in the file app/design/frontend/rwd/default/template/catalog/product/view.phtml

<?php    
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
    $qty = $stock->getQty();
    if($qty <= 0)
    {
?>
       <span class="out-of-stock"><span>Sold Out</span></span>
<?php
    }
    else
    {
?>
       <span class="in-stock"><span>In stock</span></span>
<?php
    }
?>

And if you want the label on the category page, write in app/design/frontend/rwd/default/template/catalog/product/list.phtml

NOTE : It is assumed that you are using magento-1.9 or greater

3
  • Hi! Thank you for the quick response! I forgot to mention, I am using custom theme boilerplate, do I still edit the files you mentioned or use the ones from my theme?
    – Greg
    Commented May 4, 2017 at 8:18
  • no, in this case you need to edit the file from your theme Commented May 4, 2017 at 8:22
  • check my updated answer Commented May 4, 2017 at 9:21
5

you can check product is in stock via below code

$stockItem = $product->getStockItem();
if ($stockItem->getIsInStock()) {
    //in stock!
} else {
    //not in stock!
}
1
  • app/design/frontend/YourPackage/YourTheme/template/catalog/product/list.phtml Commented May 4, 2017 at 9:54
2

Get the stock details in magento using below lines.

$stockItem = Mage::getModel('cataloginventory/stock_item')
           ->loadByProduct($productId);
         print_r($stockItem);
1

If you are using rwd theme, you can find the code to show product stock availability at

app\design\frontend\rwd\default\template\catalog\product\view\type\availability\default.phtml

4
  • Hi! I am using custom bolierplate theme, I presume it will be the same location but under my custom theme?
    – Greg
    Commented May 4, 2017 at 9:07
  • Simple, You can refer to how to do it in rwd theme
    – dat.tran
    Commented May 4, 2017 at 9:41
  • Good shout, I check that!
    – Greg
    Commented May 4, 2017 at 9:42
  • Wish you success!
    – dat.tran
    Commented May 4, 2017 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.