Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magento 1.9.2: How to update Stock Item Quantity of product ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.71k
    Comment on it

    I was having issues for updating stock quantity items of product in Magento. I was loading the product then setting the stock quantity and saving the product. But that does not work for me. Finally it was resolved, in order to update the stock quantity of the product we shouldn't need to create a new stock_item nor should you have to save the product.

     

    $product = Mage::getModel('catalog/product')->load($productid);
    if (!($stockItem = $product->getStockItem())) {
        $stockItem = Mage::getModel('cataloginventory/stock_item');
        $stockItem->assignProduct($product)
                  ->setData('stock_id', 1)
                  ->setData('store_id', 1);
    }
    $stockItem->setData('qty', $stockQty)
              ->setData('is_in_stock', $stockQty > 0 ? 1 : 0)
              ->setData('manage_stock', 1)
              ->setData('use_config_manage_stock', 0)
              ->save();

    All done!. Now stock items will be updated to the database.

    Thanks for reading the blog.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: