cancel
Showing results for 
Search instead for 
Did you mean: 

Disable configurable product when all the associated products are out of stock

Disable configurable product when all the associated products are out of stock

Hi, 

 

Through programming I want when all the associated simple products are out of stock and because of that shows a message in frontend on configurable product 'Out Of Stock'. In place of showing the 'Out of stock' message on configurable product page I want to hide the configurable product when all it's associated simple products are out of stock.

 

Thank You!

3 REPLIES 3

Re: Disable configurable product when all the associated products are out of stock

Under System->Configuration->Catalog->Stock Options there is an option to "Display Out of Stock Products". Make sure to set that to no. You'll probably have to clear your cache to get the changes to appear.

 

Oh and keep in mind it's a global option, so it'll be global across all your stores.

Re: Disable configurable product when all the associated products are out of stock

Thanks for your reply, but I already set that option as 'No' and it's not working accordingly and I want to hide the configurable products only.

Re: Disable configurable product when all the associated products are out of stock

I use this programming logic and now it's working great.

 

<?php if ($_product->isConfigurable() && !$_product->isAvailable()): ?>
             <?php $simples = $_product->getTypeInstance(true)->getUsedProducts(null, $_product) ?>
            <?php foreach($simples as $simpleProduct): ?>
                    <?php if (!$simpleProduct->isAvailable()) : ?>
                          <?php $this->setData('status',Mage_Catalog_Model_Product_Status:Smiley FrustratedTATUS_DISABLED) ?>
                          <p class="availability nostock"><?php echo $this->__('Configurable Product is Out of Stock') ?></p>
                   <?php endif; ?>
                          <?php return $this->getData('status') ?>
           <?php endforeach; ?>
     <?php else: ?>
            <?php $this->setData('status',Mage_Catalog_Model_Product_Status:Smiley FrustratedTATUS_ENABLED) ?>
<?php endif; ?>

 

Hope this logic will help someone.