Question

this may be a simple question for some - but we havent used stock extensions before.

My question: how can we easily, simply, add the ability to - instead of hiding out of stock simple products (as part of a configurable product) - show out of stock simple products with the addition of "- out of stock" & maybe greyed out in the drop down.

For example:

We sell T-shirts in sizes S, M, L. And for instance L is sold out.

Instead of only showing S, M (in config product)

Showing S, M, L - out of stock (in config product, and out of stock in grey)

Was it helpful?

Solution

Warning, using setSkipSaleableCheck(true) appears to have an additional effect of showing disabled products in the dropdown.

The function which is affected by this setting is in 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) {
            if ($product->isSaleable() || $skipSaleableCheck) {
                $products[] = $product;
            }
        }
        $this->setAllowProducts($products);
    }
    return $this->getData('allow_products');
}

if ($product->isSaleable() || $skipSaleableCheck) will therefore always be true

I am yet to dig through the isSaleable() function to determine exactly where this occurs (maybe someone can confirm) but my guess is that it includes a check against the products status which is missed if the skipSaleableCheck is set to true.

OTHER TIPS

The "code" solution:
Create your own module, and in the config.xml file of the module add these 2 events inside the <frontend> tag:

    <events>
        <controller_action_layout_render_before_catalog_product_view>
            <observers>
                <[namespace]_[module]>
                    <class>[module]/observer</class>
                    <method>showOutOfStock</method>
                </[namespace]_[module]>
            </observers>
        </controller_action_layout_render_before_catalog_product_view>
        <controller_action_layout_render_before_checkout_cart_configure>
            <observers>
                <[namespace]_[module]>
                    <class>[module]/observer</class>
                    <method>showOutOfStock</method>
                </[namespace]_[module]>
            </observers>
        </controller_action_layout_render_before_checkout_cart_configure>
    </events>

Now create an observer inside app/code/local/[Namespace]/[Module]/Model/Observer.php

class [Namespace]_[Module]_Model_Observer {
    public function showOutOfStock($observer){
        Mage::helper('catalog/product')->setSkipSaleableCheck(true);
    }
}

The extension solution
You can use this extension. Among other features, it allows you to show out of stock configuration for the configurable product.
It can also replace the standard dropdowns with labels and it adds an overlay over the out of stock combinations. Like this (see medium option)

out of stock

@Marius's answer was correct until version 1.9.3, since then the function getAllowProducts() at app/code/core/Mage/Catalog/Block/Product/View/Type/Configurable.php has added the verification of catalog inventory on admin on either show or not out of stock products.

Here's the diff:

    /*
     * Get Allowed Products
     *
     * @return array
     */
    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) {
-                if ($product->isSaleable() || $skipSaleableCheck) {
+                if ($product->isSaleable()
+                    || $skipSaleableCheck
+                    || (!$product->getStockItem()->getIsInStock()
+                        && Mage::helper('cataloginventory')->isShowOutOfStock())) {
                    $products[] = $product;
                }
            }
            $this->setAllowProducts($products);
        }
        return $this->getData('allow_products');
    }

You can also check from: https://github.com/OpenMage/magento-mirror/commit/d48bebc211cc216aaf78bdf25d7f0b0143d6333b#diff-0cbcafcade005d8e84c0377c83a67f6c

So, if you're using the 1.9.3 version all you need to do is select Yes on System > Configuration > Catalog > Inventory > Show Out Of Stock Products.

Somewhere in Mage_Catalog_Block_Product_View_Type_Configurable on line 209

if ($productStock[$productIndex]) {...}

was not allowing to insert simple product for attribute set, so instead of overriding getJsonConfig() I overwrote getAllowProducts() and set

$product->getStockItem()->setIsInStock(true);

before appending product to products array. Hope this helps someone who is already overriding getJsonConfig()

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top