0

i want to show Availability label "In Stock" or "Out Of stock" in my homepage product display. do you know how to do this? thankyou

enter image description here

1

Try This

// $_item->getProductId() -> your product id
$product = Mage::getModel('catalog/product')->load($_item->getProductId());

if ($product->getStockItem()->getIsInStock()) { 
    // $product->getStockItem()->getIsInStock() == 1
    echo "product is in stock";
}else{
    // $product->getStockItem()->getIsInStock() == 0
    echo "product is not in stock";
}

**Method 2**

$stockItem = $product->getStockItem();
if($stockItem->getIsInStock())
{
    //in stock!
}
else
{
    //not in stock!
}
  • thanks for you answer, but where i can find the code? – Ruri Mar 21 '16 at 14:58
  • You add this code in your phtml file – Magento 2 Mar 21 '16 at 15:07
  • what phtml? catalog/product/list.phtml? catalog/product/view.phtml? – Ruri Mar 21 '16 at 15:16
  • which phtml you call home page there you have to place – Magento 2 Mar 21 '16 at 16:31

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.