2

I have an Enterprise site (1.12.0.2) and a Community site (1.7.0) both doing the same thing.

A configurable product (Manage Stock set to Yes) has just one simple product. Somebody orders the last remaining stock item pushing the simple product's Stock Availability Status into "Out of Stock". However, the configurable parent's Stock Availability Status remains "In Stock". Should the parent not go "Out of Stock" when all its children have gone "Out of Stock". I can see no setting for this in System - Config.

I've tried reindexing Stock Status. No joy.

Would somebody please give me the definitive answer? If the answer is No, it never has then is there a quick and easy solution?

I'm trying to get an answer from Magento at the moment (via Enterprise ticket). Not heard back yet.

Many thanks Tadhg

3
  • Is it not changing a status in admin panel as well? Commented Feb 2, 2013 at 11:42
  • I have same issue, and I think it's bug
    – Jaro
    Commented Feb 14, 2013 at 15:17
  • Was your question answered? Then please mark a solution. Commented Feb 28, 2013 at 17:45

3 Answers 3

7

Magento confirmed this is not part of Magento (Enterprise or Community). The parent (configurable) Stock Availability Status remains untouched regardless of what happens to any of it's children (simple).

Magento actually provided me with a patch (for EE v1.12.0.2) for Enterprise that checks all a parents children status before deciding to display it or not. This seems to work by default in Community 1.7. But this is only a frontend fix.

To fix the parent Availibity Status you can do one of the following:

  1. Listen out for the cataloginventory_stock_item_save_after event. Then in your Observer class for configurable product types (or other types that have children) you can load $product->getTypeInstance()->getUsedProducts(); and do your necessary checks and updates.

  2. Extend the class Mage_CatalogInventory_Model_Stock_Item and in the _afterSave() function do the same as above. Be careful doing rewrites. It might already be extended by another third party module.

Hope this helps. Tadhg

5

I have had the same issue in magento 1.12. Is this maybe a bug? Would be great to hear what magento comes back with.

At the time I solved it via a cron script, which would find all configurables, and check the children, and if all out of stock, set the configurable as out of stock. It also did teh reverse. I ran it daily to keep them updated.

Not very elegant,but served its purpose at the time.

A better way would be to hook into an event, when stock is changed, and doing the same type of logic in the observer code.

Below is the code in the cron I used.

<?php

// File shell/setStock.php

require_once 'abstract.php';

class Mage_Shell_setStock extends Mage_Shell_Abstract {

    public function run() {

        $stockCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()
                        //->addFieldToFilter('is_in_stock', Mage_CatalogInventory_Model_Stock_Status::STATUS_OUT_OF_STOCK)
                        ->addFieldToFilter('type_id', 'configurable')->load(true);
        foreach ($stockCollection as $stockObject) {
            $childStockQty = 0;
            $product = mage::getModel('catalog/product')->load($stockObject->getProductId());
            if ($product->getSku() != '' && $product->getTypeId() == 'configurable') {
                $children = $product->getTypeInstance()->getUsedProducts();
                if (count($children) > 0) {
                    foreach ($children as $child) {
                        $childStock = $child->getStockItem();
                        $childStockQty += $childStock->getQty();
                    }


                    if ($childStockQty > 0 && $product->getIsInStock() == Mage_CatalogInventory_Model_Stock_Status::STATUS_OUT_OF_STOCK) {
                        echo 'Found configurable that is out of stock, but has stock children : setting in stock. ' . $product->getSku() . "\n";
                        mage::log('Found configurable that is out of stock, but has stock children : setting in stock. ' . $product->getSku());
                        if ($this->getArg('dry-run') == false) {
                            $stockObject->setIsInStock(True);
                            $stockObject->save();
                            $this->_doReindexFlag = true;
                        }
                    } elseif ($childStockQty == 0 && $product->getIsInStock() == Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK) {
                        echo 'Found configurable that is in stock , but has no stock children : setting out of stock. ' . $product->getSku() . "\n";
                        mage::log('Found configurable that is in stock , but has no stock children : setting out of stock. ' . $product->getSku());
                        if ($this->getArg('dry-run') == false) {
                            $stockObject->setIsInStock(False);
                            $stockObject->save();
                            $this->_doReindexFlag = true;
                        }
                    }
                } else {
                    if ($product->getSku() != '') {
                        echo 'Found configurable that has no children : setting out of stock. ' . $product->getSku() . "\n";
                        mage::log('Found configurable that has no children : setting out of stock. ' . $product->getSku());
                        if ($this->getArg('dry-run') == false) {
                            $stockObject->setIsInStock(False);
                            $stockObject->save();
                            $this->_doReindexFlag = true;
                        }
                    }
                }
            } else {
                //
            }
        }

        if ($this->_doReindexFlag) {
            mage::log("Re-indexing");
            $this->reindex(array('cataloginventory_stock',
                'catalogsearch_fulltext',
                'catalog_url'));
        }
    }

}

$shell = new Mage_Shell_setStock();
$shell->run();
2
  • thanks for that. Today is dec 2014. I think this still is an issue in 1.9.1 isn't it. WOuld this code still work?
    – snh_nl
    Commented Dec 1, 2014 at 20:10
  • @snh_nl Best is to try it on a test system, and see. I see no reason why it should not work. product types did not change that much between releasees
    – ProxiBlue
    Commented Dec 1, 2014 at 22:01
0

Take a look into this Extension on Magento Connect - Simple Configurable Product, which I think should best suit your requirement. Also it has more other nice features as well. And yes its a Free Module.

Your Answer

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

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