0

How can I show "Out of Stock" text in dropdown option? See Chocolate Brownie Option in current and expected

Current Showing

Expected Style

  • I am not sure which file should I modify. Could you please suggest which file the code resides for attribute of complex product? – akmnahid May 21 '15 at 20:04
7

To show out of stock products go to System > Configuration > Catalog > Inventory and set Display Out of Stock Products to yes.

Now we'll need to rewrite the class Mage_Catalog_Block_Product_View_Type_Configurable which you can do in your own module. Specifically the method getJsonConfig.

This method actually outputs a javascript string that is used to build the configurable product dropdowns.

Around line 197 you'll see

$info['options'][] = array(
   'id'        => $value['value_index'],
   'label'     => $value['label'],
   'price'     => $configurablePrice,
   'oldPrice'  => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
   'products'  => $productsIndex,
);

the label key is what you need to change. Checking for the stock of the products would look something like this

if (count($productsIndex) == 1) {
   $stockItem = Mage::getModel('cataloginventory/stock_item')
       ->loadByProduct($productsIndex[0]);
   if ($stockItem->getQty() == 0) {
      $value['label'] .= ' (out of stock)';
   }
}

$info['options'][] = array(
   'id'        => $value['value_index'],
   'label'     => $value['label'],
   'price'     => $configurablePrice,
   'oldPrice'  => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
   'products'  => $productsIndex,
);
  • Hi @sander-mangel, i have try your code, but not working. Out of Stock text still does not appear. – Andhi Irawan Jan 26 '16 at 2:15
  • @AndhiIrawan I'm gonna need a whole lot more info than that to help you – Sander Mangel Jan 26 '16 at 16:35
  • It works partially. Now I can see the out of stock items in the drop down. but it doesn't mentioned (Out of Stock) in the drop down. – Doodu May 10 '17 at 17:06
  • Works perfectly for me. I've made an edit to the original answer to add a bit more clarity. – Thomas Harding Jan 15 '18 at 11:15
  • @ThomasHarding, Where is working answer !!? – anonymous May 24 at 6:46
1

app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php

Make a custom module or put that file in local directory

1) line # 94 change

            if ($product->isSaleable() || $skipSaleableCheck) {
                $products[] = $product;
            }

To

            //if ($product->isSaleable() || $skipSaleableCheck) {
                $products[] = $product;
            //}
        }

2) Line # 197 change

                $info['options'][] = array(
                    'id'        => $value['value_index'],
                    'label'     => $value['label'],
                    'price'     => $configurablePrice,
                    'oldPrice'  => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
                    'products'  => $productsIndex,
                );

To

                if (count($productsIndex) == 1) {
                   $stockItem = Mage::getModel('cataloginventory/stock_item')
                       ->loadByProduct($productsIndex[0]);
                   if ($stockItem->getQty() == 0) {
                      $value['label'] .= ' (out of stock)';
                   }
                }
                $info['options'][] = array(
                    'id'        => $value['value_index'],
                    'label'     => $value['label'],
                    'price'     => $configurablePrice,
                    'oldPrice'  => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
                    'products'  => $productsIndex,
                );
  • It works partially. Now I can see the out of stock items in the drop down. but it doesn't mentioned (Out of Stock) in the drop down. – Doodu May 10 '17 at 17:10
0

I think any of the solution given above so far would not work for configurable with more than 1 option set (more than 1 dropdown).

if (count($productsIndex)) {
    $stockItem = Mage::getModel('cataloginventory/stock_item')
                   ->loadByProduct(end($productsIndex));
    if ($stockItem->getQty() == 0) {
        $value['label'] .= Mage::helper('catalog')->__(' (out of stock)');
    }
}

could be better in such cases.

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.