This is the default Magento behaviour when you update the stock quantity from backend admin. In the admin product form if you look over the html, for the stock quantity input, you will actually find two inputs:
<input type="hidden" id="original_inventory_qty" name="product[stock_data][original_inventory_qty]" value="6">
<input type="text" class="input-text required-entry validate-number" id="inventory_qty" name="product[stock_data][qty]" value="6">
So when you submit the form after changing the quantity text input to 7 you will actually send two variables to Magento:
product[stock_data][original_inventory_qty] = 6
and
product[stock_data][qty] = 7
.
If you look into the observer that handles the product stock update Mage_CatalogInventory_Model_Observer
under the _prepareItemForSave($item, $product)
method you will find:
$originalQty = $product->getData('stock_data/original_inventory_qty');
if (strlen($originalQty)>0) {
$item->setQtyCorrection($item->getQty()-$originalQty);
}
So Magento will check each time when you submit an original quantity and only apply a quantity correction and not just update the quantity to the one you've set.
Then the resource model that handles the save, Mage_CatalogInventory_Model_Resource_Stock_Item
, will check the quantity correction in the _prepareDataForTable(Varien_Object $object, $table)
method:
$data = parent::_prepareDataForTable($object, $table);
if (!$object->isObjectNew() && $object->getQtyCorrection()) {
$qty = abs($object->getQtyCorrection());
if ($object->getQtyCorrection() < 0) {
$data['qty'] = new Zend_Db_Expr('qty-' . $qty);
} else {
$data['qty'] = new Zend_Db_Expr('qty+' . $object->getQtyCorrection());
}
}
return $data;
So you don't need to worry about changing the stock quantity from the admin backend because Magento will apply the price correction by default.
You can also do this programmatically, but make sure you use the models available in the CatalogInventory
module for loading and saving the stock.
Updating directly by performing an SQL statement while a customer is placing an order would not be a good idea.
Best Answer
Please check settings in
and
The topic was discussed here:
Magento cart can only take one item (1 quantity per product)