1

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

How can I achieve that?

3

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

  • 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 May 4 '17 at 8:18
  • no, in this case you need to edit the file from your theme – Manashvi Birla May 4 '17 at 8:22
  • check my updated answer – Manashvi Birla May 4 '17 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!
}
  • app/design/frontend/YourPackage/YourTheme/template/catalog/product/list.phtml – Murtuza Zabuawala May 4 '17 at 9:54
1

Get the stock details in magento using below lines.

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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