6

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)

12

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.

9

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

  • Thx @Marius. I was looking at this. (after the above suggestions) We ONLY want to add an "out of stock" text to the products that are out of stock. Any tips on how I access and add text to the dropdown creation? – snh_nl Mar 15 '14 at 20:15
  • So in the end we would be 1) overriding that we DO see out of stock too 2) access dropdown creation and add a custom text to the elements that have is_in_stock set to no only – snh_nl Mar 15 '14 at 20:16
  • The "code" solution should also include the "controller_action_layout_render_before_wishlist_index_configure" event. Works great, thanks! – ryaan_anthony Dec 19 '14 at 19:36
  • I have implemented your code into Wigman Ajaxswatches. It is working but lacking some kind of visual feedback that the option isn't on stock. – loeffel Sep 7 '15 at 11:05
3

@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.

1

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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