When a stock item reaches QTY 0 or negative (granted backorders are disabled & QTY for item to become out of stock is 0 as well), is_in_stock
is set to 0 automatically.
However, when it then reaches a positive inventory level, is_in_stock
is not automatically set to 1. Why is this the case?
Consider the following example:
$product = Mage::getModel('catalog/product')->load($product_id); //where $product_id is an in stock product
$stock_item = $product->getStockItem();
$stock_item->setQty(0);
$stock_item->save();
The product is now listed as out of stock.
$product = Mage::getModel('catalog/product')->load($product_id); //where $product_id is the product now out of stock
$stock_item = $product->getStockItem();
$stock_item->setQty(1);
$stock_item->save();
The product remains out of stock. Should this not be put back into stock?
Best Answer
I ran a grep for "setIsInStock" and there are only a few places where this is set:
What I've found in
Mage_CatalogInventory_Model_Stock
andMage_CatalogInventory_Model_Stock_Item
is, that there is a check the functions of these classes for the minimum quantity of the product. The backend setting for this (on the product edit page) is "Qty for Item's Status to Become Out of Stock".This is for example the code in
Mage_CatalogInventory_Model_Stock_Item
:and verifyStock which also checks for the minimum quantity:
$qty <= $this->getMinQty()
Possible solution:
My guess is, that you have a minimum quantity set which is higher than "1".
Update:
As tested in the comments below, the
is_in_stock
value is not set back when updating a product in the backend. It seems the only place where a product is set into stock by default isbackItemQty()
method inMage_CatalogInventory_Model_Stock
when an order is cancelled/returned.