1

In my case configurable simple products are outof stock it is not displaying under configurable product options list. it is working fine for me. But How can i hide configurable product when all options are outofstock....? In this case configurable product not showing addtocart button and options dropdown. But i need to hide total configurable product if there are no options under this.

Thanks, Murali

krishna
  • 923
  • 3
  • 15
  • 42

2 Answers2

5

This works for me (ver. 1.7.0.2) with the following configuration:

  • cataloginventory/options/show_out_of_stock is 0 (Configuration/Catalog/Inventory/Display Out of Stock Products "No" on admin interface)
  • Configurable product/Inventory/Manage Stock is "No"
  • Simple product/Inventory/Manage Stock is "Yes"

In this way when all options are sold out, the main product is hidden.

Péter Gulyás
  • 1,111
  • 7
  • 8
1

One solution is to write an observer to catch the catalog_controller_product_init_after event. From your observer you can access the product object via Mage::registry('product');

Check if the product is configurable by calling ($product->getTypeId() == 'configurable'). If it is a configurable product, you can access its children's stock by executing

$simples = $product->getTypeInstance(true)->getUsedProducts(null, $product);
$confHasStock = false;
foreach ($simples as $simple) {
  if ($simple->getStockItem()->getData('qty') > 0) {
     $confHasStock = true;
     break;
  }
}

if the variable $confHasStock is still false then do a 404 redirect or whatever you find proper as "hiding" the product.

Oleg Ishenko
  • 2,243
  • 1
  • 15
  • 16