Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

MASS UPDATE STOCK LEVELS IN MAGENTO Problem
 
joongpark
Jr. Member
 
Total Posts:  5
Joined:  2009-05-21
 

Hi.
I am trying to use following code with latest Magento V1.7.1
http://www.sonassi.com/knowledge-base/magento-kb/mass-update-stock-levels-in-magento-fast/

I updates stock quantities from CSV file.

It works fine with following fields
“sku”,"qty"
“prod1”,"11"

However, it does not work if there is any additional fields.
I tried
“sku”,"qty”,"is_in_stock"
“prod1”,"11”,"1"

but qty gets updated but is_in_stock or any other fields that are after qty does not get imported into DB.

I tried to switch fields and tried following
“sku”,"is_in_stock”,"qty"
“prod1”,"1”,"11"

and now is_in_stock get updated but qty does not.

Instruction says minimum of 2 + any of additional fields listed but it does not work.
Would you be able to share updated code?

Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joongpark
Jr. Member
 
Total Posts:  5
Joined:  2009-05-21
 

Following is the code. It was written while ago but it still updates the stock but there must be something missing

joongpark - 12 August 2012 07:08 PM

<?

define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';

umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$count = 0;

$file = fopen(MAGENTO . '/var/import/updateStockLevels.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {

if ($count == 0) {
foreach ($line as $key=>$value) {
$cols[$value] = $key;
}
}

$count++;

if ($count == 1) continue;

#Convert the lines to cols
if ($count > 0) {
foreach($cols as $col=>$value) {
unset(${$col});
${$col} = $line[$value];
}
}

// Check if SKU exists
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);

if ( $product ) {

$productId = $product->getId();
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
$stockItemId = $stockItem->getId();
$stock = array();

if (!$stockItemId) {
$stockItem->setData('product_id', $product->getId());
$stockItem->setData('stock_id', 1);
} else {
$stock = $stockItem->getData();
}

foreach($cols as $col=>$value) {
$stock[$col] = $line[$value];
}

foreach($stock as $field => $value) {
$stockItem->setData($field, $value?$value:0);
}



$stockItem->save();

unset($stockItem);
unset($product);
}

echo "<br />Stock updated $sku";

}
fclose($file);

?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
online2design
Jr. Member
 
Total Posts:  2
Joined:  2012-01-20
 

Does this work for you?

“sku”,"qty”,"use_config_manage_stock”,"is_in_stock”,"manage_stock"
“prod1”,11”,"1”,"1”,"1"

Make sure the above contains the correct “. Because above it is displaying to different types of them (” and “).

 
Magento Community Magento Community
Magento Community
Magento Community
 
stutino
Jr. Member
 
Total Posts:  3
Joined:  2012-09-18
 

hi there, ive succesfully used the import fetaure of community edition to update prices in bulk. however, I noticed qty is not getting updated. my csv simply consisted of [sku, price, qty]. actually, it appears it may even have just cascaded the qty for row1 all the way down the list. but i can’t necessarily confirm at this point since they are all the same now. do you have any further insight into your issue? -thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fulcan
Jr. Member
 
Total Posts:  16
Joined:  2010-04-28
 
stutino - 19 September 2012 10:08 AM

hi there, ive succesfully used the import fetaure of community edition to update prices in bulk. however, I noticed qty is not getting updated. my csv simply consisted of [sku, price, qty]. actually, it appears it may even have just cascaded the qty for row1 all the way down the list. but i can’t necessarily confirm at this point since they are all the same now. do you have any further insight into your issue? -thanks

Ok I just ran some test with small lists of 5 products.  Yes then import system is taking the inventory for the first product and then applies this inventory number to all other products.  Very frustrating!

Anyone else have this problem and anyone with a solution on updating 15,000 products?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
stutino
Jr. Member
 
Total Posts:  3
Joined:  2012-09-18
 

ok great thanks for the confirmation. i have someoned working on a fix for the bug as we speak. i will post the solution asap.

 
Magento Community Magento Community
Magento Community
Magento Community
 
phillipmeyer
Jr. Member
 
Total Posts:  6
Joined:  2012-02-07
 

I have the same issue, it’s very frustrating. Did anyone find a fix?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nChannel
Guru
 
Avatar
Total Posts:  329
Joined:  2012-02-28
 

You may consider using a simple plugin or integration solution to connect the Magento store to your inventory. Otherwise, manual entry can be quite time consuming and lead to some errors. With an integration solution like nChannel, there is no need to manually update inventory quantities in all your eCommerce systems. nChannel will synchronize inventory as sales are made placed and fulfilled. Inventory displayed on your eCommerce sites will always be up to date so you’re not selling items you no longer have in stock.

If you’re interested in learning more, feel free to contact me.

Darren

1-800-406-8217

 
Magento Community Magento Community
Magento Community
Magento Community
 
darose
Jr. Member
 
Total Posts:  2
Joined:  2013-08-09
 

Hello,

We are using Magento API for such tasks in combination with extensions installed for products management.

Here is simple example how you can update stock level+status through magento api:

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId $proxy->login('apiUser''apiKey');
 
// Get stock info
var_dump($proxy->call($sessionId'product_stock.list''Sku'));
 
// Update stock info
$proxy->call($sessionId'product_stock.update', array('Sku', array('qty'=>50'is_in_stock'=>1)));
 
var_dump($proxy->call($sessionId'product_stock.list''Sku'));

You can just add CSV parsing and update stock inventory in way as in example. Also you need to add credentials for magento api access in your magento admin. It’s workng very well.

Also, here is few great extensions Advanced Admin Products Manager (we are using it now) and Stock Inventory Manager (have using before Advanced Admin Products Management upgrade) both of this extensions allow you edit products stock data right in the product grid as you do it in Excel and perform bulk update in one click. The difference between is in stack of features - Advanced Admin Products Manager allow you do more things on the fly, not limited to stock management tasks.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top