Geoff
Geoff

Reputation: 3574

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

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.

Upvotes: 4

Views: 5374

Answers (4)

Caius36
Caius36

Reputation: 1

Go to System -> Configuration -> Inventory (under Catalog) -> Product Stock Options -> Automatically Return Credit Memo Item to Stock and make sure it's set to Yes. Or simply go to your database and in core_config_data where the path is 'cataloginventory/item_options/auto_return' make sure that the value column is set to '1';

Upvotes: 0

Jake S
Jake S

Reputation: 1

Stores >> Config >> Inventory >> scroll to bottom

Upvotes: 0

Ovidiu
Ovidiu

Reputation: 2931

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

Upvotes: 5

Droydn
Droydn

Reputation: 1067

Write a module that observes the event for credit memos and sets the in_stock flag on the products stock item object before product save. I cant tell you the event you want to observe but I am positive you can find it :)

If there is none, the uglier way would be to observe the products before save. More logic to pull it off but if you always want products to be in stock if they have qty regardless of anything else, then its not a bad idea.

Upvotes: 0

Related Questions