1

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?

2 Answers 2

1

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>
7
  • Thank you Amit. I will create a full backup of the site overnight and try that tomorrow morning. Nov 5, 2014 at 23:08
  • Hi Amit Bera, I have just done the fix that you said and it's pulling through the product and if added to basket it shows the popup with "This product is currently out of stock.<br/>" message which is great too, however I was wondering - is it possible to add "(out of stock)" to the end of the product variant in the dropdown menu so the customer knows in advance that it isn't in stock? Nov 6, 2014 at 9:51
  • Magento is provide to backorders facility which give this type solution ,where customer can place out of stock products magentocommerce.com/knowledge-base/entry/…
    – Amit Bera
    Nov 6, 2014 at 9:57
  • But disabled products are also showing in dropdown after implementing this? why??? Jun 24, 2015 at 2:00
0

You can do this without any rewrites.
Just use the event catalog_controller_product_init.
So add this to the config.xml from one of your modules inside the <frontend><events> tag

<catalog_controller_product_init>
    <observers>
        <[module]>
            <class>[module]/observer</class>
            <method>showOutOfStock</method>
        </[module]>
    </observers>
</catalog_controller_product_init>

Then create the file Observer.php inside the Model folder with this content

<?php 
class [Namespace]_[Module]_Model_Observer
{
    public function showOutOfStock($observer)
    {
        $product = $observer->getEvent()->getProduct();
        if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
            Mage::helper('catalog/product')->setSkipSaleableCheck(true);
        }
    }
}
3
  • can we do the same in m2 also? Dec 20, 2018 at 14:16
  • most likely. I just don't know how. Maybe look for the method getSkipSaleableCheck, not sure in what class it is. And make an after plugin for it, that returns true.
    – Marius
    Dec 20, 2018 at 14:19
  • I am looking for it, but nowhere finding the proper solution Dec 20, 2018 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.