Magento – How to have the size and color of out of stock products displayed

color-swatchesconfigurable-productmagento-1.9out-of-stockswatches

I would need help regarding the out of stock and color/size display function on Magento based website.

I show the items on my website, even after they went out of stock.

But the problem is that after an item goes out of stock, the color and size are not visible anymore.
And I would like to show the color and size available at the origin for the item, even when out of stock. Like on this image, I would like to show them in the red area.
enter image description here

So can somebody help me with this?

Thank you.

Best Answer

You can write an observer for the event catalog_controller_product_init.
Add this to the config.xml file in one of your modules inside the <frontend> tag.

<events>
    <catalog_controller_product_init>
        <observers>
            <[namespace]_[module]>
                <class>[module]/observer</class>
                <method>showStock</method>
            </[namespace]_[module]>
        </observers>
    </catalog_controller_product_init>
</events>

then create the file [Namespace]/[Module]/Model/Observer.php

<?php 
class [Namespace]_[Module]_Model_Observer
{
    public function showStock(Varien_Event_Observer $observer)
    {
        /** @var Mage_Catalog_Model_Product $product */
        $product = $observer->getEvent()->getProduct();
        if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
            Mage::helper('catalog/product')->setSkipSaleableCheck(true);
        }
        return $this;
    }
}

The downside of this is that the configurable product will appear as in stock in the product even if all the simple products are out of stock.

Related Topic