Magento 1.7/1.8 – Show Out of Stock Product Variants for Configurable Products

configurable-productmagento-1.7magento-1.8

do you know how to show the product "variants" (sorry if this terminology is incorrect) even if it is out of stock and possibly show "Out of stock" instead of the price?

So for example I have a T-shirt configurable product, so I have added a green single product and an orange single product as Associated products. The orange product is out of stock, I still want it to be displayed in the dropdown menu so customers know that there's an orange option but it should be out of stock so the customer can't order.

Does anybody know?

Best Answer

You can view out of stock variable in product by remove this code

if ($product->isSaleable() || $skipSaleableCheck) { from function getAllowProducts() at class Mage_Catalog_Block_Product_View_Type_Configurable.

So you need to rewrite class Mage_Catalog_Block_Product_View_Type_Configurable

Step1: You will need to create /app/code/local/Amit/MyProduct/Block/Catalog/Product/View/Type/ and file Configurable.php

and code:

<?php
class Amit_MyProduct_Block_Catalog_Product_View_Type_Configurable extends Mage_Catalog_Block_Product_View_Type_Configurable{

 public function getAllowProducts()
    {
        if (!$this->hasAllowProducts()) {
            $products = array();
            $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
            $allProducts = $this->getProduct()->getTypeInstance(true)
                ->getUsedProducts(null, $this->getProduct());
            foreach ($allProducts as $product) {
                    $products[] = $product;
                }
            $this->setAllowProducts($products);
        }
        return $this->getData('allow_products');
    }

}

Step2: create config.xml /app/code/local/Amit/MyProduct/etc/ and code is

<?xml version="1.0"?>
<config>
 <modules>
    <Amit_MyProduct>
        <version>1.0.0</version>
    </Amit_MyProduct>
 </modules>
 <global>
   <blocks>
    <catalog>
         <rewrite>
              <product_view_type_configurable>Amit_MyProduct_Block_Catalog_Product_View_Type_Configurable</product_view_type_configurable>
             </rewrite>
      </catalog>
  </blocks>
 </global>
</config>

Step3: Create Amit_MyProduct.xml at app/etc/modules

<?xml version="1.0"?>
<config>
 <modules>
    <Amit_MyProduct>
        <codePool>local</codePool>
        <active>active</active>
    </Amit_MyProduct>
 </modules>
</config>
Related Topic