I recently migrated from Volusion to Magento using Cart2Cart. Most of my products are configurable and are showing "Out of Stock" and quantities set to zero. I have 5,000 products (including variations). My question is, is there a way to do a either do a bulk update, or at least have access to a page where I can see all products at once with the option of setting stock values from that page?
2 Answers
You can do it programatically via a script or an extension. What you need is to load magento object, load product collection
//load Magento
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app('admin');
//load products collection
$productsCollection = Mage::getModel('catalog/product')->getCollection();
foreach($productsCollection as $item) {
//load product object
$product = Mage::getModel('catalog/product')->load($item->getId());
//set Is in stock to Yes
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
$stockItem->setData('is_in_stock', 1);
$stockItem->save();
$product->save();
}
For more information check this thread (perhaps you need to set Manage Stock=Yes, Qty etc.)
After @Marius brilliant answer I decided to update my answer by providing few alternatives in case you don't need the same QTY for ALL products.
1) What you can do is to use Magento Dataflow - Import/Export Profile. You need to export your products, change Qty field and if you enabled the stock control in the administration area I believe this would solve the problem. 2) Also you could check Magmi Mass Importer as it allows to update products 3) And here you can check MASS UPDATE STOCK LEVELS IN MAGENTO – FAST by @Sonassi
-
1This may work for a few products, but for 5k products...your grandchildren will graduate from college before the script ends.– Marius ♦Feb 28, 2014 at 18:26
-
agreed for 50k or 500k but 5k not that bad. Would be curious to read the better solution (I know that $product->save() is very very slow, but not that slow as I'm planning to attend my grandchildren graduation in 50 years as earliest :) ) Feb 28, 2014 at 18:43
If you want to set the same qty for all the products you can run this query on your db.
UPDATE `cataloginventory_stock_item`
SET
`qty` = 5000,
`is_in_stock` = 1
Then rebuild your indexes.
-
Brilliant answer if @Brent needs the same qty to all products. Upvoted :) Feb 28, 2014 at 19:05
-
Thanks guys, I appreciate it. Running that query Marius provided did what I needed. Thanks again!– BrentMar 4, 2014 at 5:45