I would like to display the stock status (In Stock | Sold Out) on the product page.
How can I achieve that?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityTo 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
you can check product is in stock via below code
$stockItem = $product->getStockItem();
if ($stockItem->getIsInStock()) {
//in stock!
} else {
//not in stock!
}
Get the stock details in magento using below lines.
$stockItem = Mage::getModel('cataloginventory/stock_item')
->loadByProduct($productId);
print_r($stockItem);
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