update quantity by csv file in Magento

In this article we discuss how to update quantity by csv file. Like when you update in csv file then automatically update in magento admin.

Above screenshot given a csv file, in this have sku and quantity if we update qty in this csv file and save then automatically update in magento admin.

EX: like sku A016 have 25 quantity then if you want to update qty 35.

First of all upload csv file in root directory. And one php file upload in root like qty.php.

here is code... copy code and paste in qty.php file. 

 $mageFilename = 'app/Mage.php';
 require_once $mageFilename;
 ini_set('display_errors', 1);

 $data = array() ;
 if (($file = fopen("qtyupdate.csv", "r")) !== FALSE)  // qtyupdate.csv is file which is have sku and quantity (above given screenshot)
 while (($data = fgetcsv($file, 1000, ",")) !== FALSE)
 $product = Mage::getModel('catalog/product');
 $id = Mage::getModel('catalog/product')->getResource()->getIdBySku( $data[0] );
 $stockItem = $product->getStockItem();
 $stockItem->setData( 'manage_stock', $data[1] );
 $stockItem->setData( 'is_in_stock', $data[1] );
 $stockItem->setData( 'use_config_notify_stock_qty', $data[1] );
 $stockItem->setData( 'qty', $data[1] );
 echo '<br/>';

After both file upload in root, run the url: yourdomain.com/qty.php

and update product quantity which is update in csv file.