Magento - Credit Memo "Return to Stock" not updating Stock Availability

magento, magento-1.5

Solution

I know it's old but because this isn't yet fixed not even in 1.7.0.1 I came up with a better solution.

Tested on 1.5.1 and above:

\app\code\core\Mage\CatalogInventory\Model\Observer.php

in

public function refundOrderInventory($observer)

after

Mage::getSingleton('cataloginventory/stock')->revertProductsSale($items);

    //add this
    foreach ($creditmemo->getAllItems() as $item) {
        $productId = $item->getProductId();
        $product = Mage::getModel('catalog/product')->load($productId);

        if(!$product->isConfigurable()){

            $stockItem = $product->getStockItem();

            //$stockItem->setQty($item->getQty());
            $stockItem->setIsInStock(1);
            $stockItem->save();

            $product->setStockItem($stockItem);
            $product->save();
        }
    }

Problem

So when you do a credit memo in Magento, it sets the stock back to the correct level but does not change the "out of stock" back to "in stock" (if applicable). I came across this post by Wright Creatives (http://wrightcreativelabs.com/blog/55-credit-memo-in-stock.html) and it solves this problem. However, the method is too slow! It takes about 30 seconds per product. I've ultimately had to remove this as a solution (because of the "speed") and now my boss would like the functionality reimplemented. I know that the `is_in_stock` data controls this & I'm wondering if there is already a module out there, an article/tutorial, or someone who can help me get started on a "better/faster" solution.

Original source