How to Update Stock Quantity Manually in Magento

10,535

Solution 1

3 tables are mainly used to manage the stock : cataloginventory_stock, cataloginventory_stock_item and cataloginventory_stock_status

If you need to update a product's stock quantity you will need to find the relevant line in the cataloginventory_stock_item table and edit the qty field:

Example (set qty to 100 for product ID 33) :

UPDATE cataloginventory_stock_item set qty=100 where product_id=33

Solution 2

Exist following solution

$stockItem = Mage::getModel('cataloginventory/stock_item');
Mage::getResourceModel('cataloginventory/stock_item')->loadByProductId($stockItem, $allProductsIDs[$sku]);

$dataStock['sku'] = $sku;
$dataStock['qty'] = $qty;
$dataStock['is_in_stock'] = $isInStock;
$dataStock['manage_stock'] = $stockData['manage_stock'];
$dataStock['use_config_manage_stock'] = $stockData['use_config_manage_stock'];

foreach($dataStock as $key1=>$value1) {
$stockItem->setData($key1, $value1);
}

$stockItem->save();
Share:
10,535
Lapinou
Author by

Lapinou

Updated on June 05, 2022

Comments

  • Lapinou
    Lapinou almost 2 years

    I'm trying to update the stock quantity in magento manually. I know it's possible but I don't know how to proceed...

    I want to update the stock from a web service, and I'm searching how to list all my articles. Then, get the id of the article, send it to the web service, get the stock provides by the web service and to finish, update the stock in the database of Magento.

    I'm a new user of Magento and your help will be really appreciate :)

    Thank you so much guys!