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 );
$item->getData('qty_ordered');
$item->getData();
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->assignProduct($item);
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('qty', 1);
$item->setStockItem($stockItem);
$item->save();
}
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?