Magento

Magento Show Out of Stock Configurable Options – Magento 1.5+

To show Out of Stock options in configurable products, we need to make these changes:

Create a Local Module : Mindgeek_Outofstock
/app/code/local/Mindgeek/Outofstock/Product/Block/Product/View/Type/Configurable.php
/app/code/local/Mindgeek/Outofstock/etc/config.xml
/app/code/etc/modules/Mindgeek_Outofstock.xml

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

<config>
<modules>
<mindgeek_outofstock>
<version>0.1.0</version>
</mindgeek_outofstock>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_type_configurable>Mindgeek_Outofstock_Block_Product_View_Type_Configurable
</product_view_type_configurable>
</rewrite>
</catalog>
</blocks>
</global>
</config>

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

class Mindgeek_Outofstock_Block_Product_View_Type_Configurable  extends Mage_Catalog_Block_Product_View_Type_Configurable
{
//Rewrite getAllowProducts() function:
public function getAllowProducts()
{
if (!$this->hasAllowProducts()) {
$products = array();
$allProducts = $this->getProduct()->getTypeInstance(true)
->getUsedProducts(null, $this->getProduct());
foreach ($allProducts as $product) {
$products[] = $product;
}
$this->setAllowProducts($products);
}
return $this->getData(‘allow_products’);
}
}

Now changes required in design template, view.phtml

/app/design/frontend/purple/default/template/catalog/product/view.phtml

<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml(‘container2’, ”, true, true) ?>
<?php endif;?>

<?php if ($this->hasOptions()):?>
<?php echo $this->getChildChildHtml(‘container2’, ”, true, true) ?>
<?php endif;?>

Enable this Module from /app/etc/modules/Mindgeek_Outofstock.xml

<?xml version=”1.0″?>
<config>
<modules>
<Mindgeek_Outofstock>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Mindgeek_Outofstock>
</modules>
</config>

Done!!

You Might Also Like

  • http://www.phpzag.com/ laeeq khan

    really mice

  • Hammy

    Amazing. Thanks!

  • sarvagya

    Hello,
    I am trying to show out of stock configurable products having two attributes.
    Please help asap.
    Thanks in Advance

    • http://mindgeek-primary-host.com/ Mindgeek

      Hi Sarvagya, I have tested the code above and its working for all cases of multiple attributes. Please use same, let me know if you have any confusion in its implementation.

  • Brendan Gallagher

    Hi Mindgeek,

    Thanks for the awesome tutorial but I’m a little confused.

    What code needs to go into /app/code/local/Mindgeek/Outofstock/Product/Block/Product/View/Type/Configurable.php

    Thanks,

    Brendan

    • mindgeek

      Hi Brendan,
      In /app/code/local/Mindgeek/Outofstock/Product/Block/Product/View/Type/Configurable.php
      you need to need this code:
      #Filename Configurable.php

      class Mindgeek_Outofstock_Block_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Type_Configurable
      {
      //Rewrite getAllowProducts() function:
      public function getAllowProducts()
      {
      if (!$this->hasAllowProducts()) {
      $products = array();
      $allProducts = $this->getProduct()->getTypeInstance(true)
      ->getUsedProducts(null, $this->getProduct());
      foreach ($allProducts as $product) {
      $products[] = $product;
      }
      $this->setAllowProducts($products);
      }
      return $this->getData(‘allow_products’);
      }
      }

    • http://mindgeek-primary-host.com/ Mindgeek

      Hi Brendan,
      In /app/code/local/Mindgeek/Outofstock/Product/Block/Product/View/Type/Configurable.php
      you need to need this code:
      #Filename Configurable.php

      class Mindgeek_Outofstock_Block_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Type_Configurable
      {
      //Rewrite getAllowProducts() function:
      public function getAllowProducts()
      {
      if (!$this->hasAllowProducts()) {
      $products = array();
      $allProducts = $this->getProduct()->getTypeInstance(true)
      ->getUsedProducts(null, $this->getProduct());
      foreach ($allProducts as $product) {
      $products[] = $product;
      }
      $this->setAllowProducts($products);
      }
      return $this->getData(‘allow_products’);
      }
      }

  • Mtg

    Will this work in 1.7 ?

    • http://mindgeek-primary-host.com/ Mindgeek

      I am sure it will work with 1.7 as it just enables out of stock products.
      Give it a try. All the best.

  • Pingback: Judder: The Abridged Learnings of Alex Judd » Magento: Show out of stock configurable product options and notifications

  • Ronen

    Hi,

    first of all thanks a lot for this excellent module !!!

    But there is another problem that I need to be done,

    what if all my associate’s simple products is “out of stock”?

    because your module working only if there at least one simple product

    that is “in stock” then it will showing us the others that “out of stock”.

    Please advice I need that help it’s really important for me.

    And again thanks a lot !!!!

    • http://mindgeek-primary-host.com/ Mindgeek

      On /app/design/frontend/your_theme/default/template/catalog/product/view/type/options/configurable.phtml
      Try to replace this line if ($_product->isSaleable() && count($_attributes)) with if(count($_attributes))
      Hope this will fix your problem.

  • Pingback: rimonabantexcellence site title

  • Benzir

    Hi Mindgeek,
    Thanks for you excellent Extension.
    I have an issue with multiple attributes. When products show multiple attributes with ” – Out of Stock” it’s don’t show correct. Can you please help.
    Thanks in advance.

  • Karl Monson

    Modules should never modify core files… just saying…