I have installed Magento 1.8. When a user orders a product, the quantity is decreased by one, but if he cancels that order (before invoicing), the stock quantity does not gets increased.
Admin > Catalog > Inventory > Stock Options > Set Items Status to be In Stock When Order is Cancelled is set to Yes
The code I have been using to cancel order is as follows:
class Kaushikamdotcom_Pay_OrderController extends Mage_Core_Controller_Front_Action {
public function cancelAction() {
if (($order_id = $this->getRequest()->getParam('order_id'))) {
$order = Mage::getModel('sales/order')->load($order_id);
$order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
$order->save();
}
$this->_redirect('sales/order/history');
}
}
The code I have been using to know the current stock is as follows (The same can be also seen in the admin side):
Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
Why is the quantity not get increased ? Is it the intended behavior ? I searched in google, on those links I have been instructed to do it programmatically.