I have a module to uncancel orders. The problem is that when I uncancel an order, the stock quantity is not decreasing for the amount of items ordered. I have the line of code that set order back to previous state. I am trying to decrease the stock without success. Here is my code.

foreach ( $order->getItemsCollection() as $item ) {
                $item->setQtyCanceled( 0 );
                $item->setTaxCanceled( 0 );
                $item->setHiddenTaxCanceled( 0 );

                $stockItem = Mage::getModel('cataloginventory/stock_item');
                $stockItem->setData('is_in_stock', 1);
                $stockItem->setData('qty', 1);

I am getting this error: Call to a member function getWebsiteId() on a non-object in \app\code\core\Mage\CatalogInventory\Model\Stock\Status.php on line 208

and the item qty is not set to "1" ( "1" for test purpose)

Does anyone have an idea on how can I achieve this?

1 Answer 1


on line 208 of \app\code\core\Mage\CatalogInventory\Model\Stock\Status.php, there is a call $product->getStore()->getWebsiteId().

This is called in the method assignProduct declared as :

public function assignProduct(Mage_Catalog_Model_Product $product, $stockId = 1, $stockStatus = null)

First param has to be an instance of Mage_Catalog_Model_Product and your $item is an instance of Mage_Sales_Model_Order_Item.

So, instead of passing $item as a first parameter, you should try to pass $item->getProduct().

  • Thanks for your answer. It does solve the php error, but still do not work to reduce item stock.
    – Gabriel G
    Mar 21, 2018 at 17:12

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.