Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Configurable Product is out of stock?

We all know that a configurable product in magento is associated with simple product.

If the simple products associated to the configurable product becomes Inventory = 0, it means that the configurable product is out of stock

So the question is how do i detect if Configurable Product is out of stock? i want to detect so I can display in front-end the "Out of Stock" text.

something like this

if($configurable_product->isOutOfStock()) {
   echo "Out of Stock";
}

How can i do this in Magento?

like image 400
Bogz Avatar asked Aug 15 '14 08:08

Bogz


1 Answers

if (!$configurable->isSaleable() ||$configurable_product->getIsInStock()==0){
// out of stock
}

For checking child simple product:

$allProducts = $configurable->getTypeInstance(true)
                ->getUsedProducts(null, $configurable);
            foreach ($allProducts as $product) {
                if (!$product->isSaleable()|| $product->getIsInStock()==0) {
                    //out of stock for check child simple product
                }
            }
like image 109
Amit Bera Avatar answered Oct 22 '22 18:10

Amit Bera