1
votes

How to do so that the stock status goes from "not in stock" to "in-stock" when we update qty from 0?

I have to update 600 products from qty = 0 to 1-10. I was hoping that i could use the plugin: mass product updater to do the task. But the plugin will lose its purpose if I need to change stock status on every products manually.

2

2 Answers

0
votes

If you have decided to update all products' quantity and stock status at once, then you can write this code in any controller's action and hit that controller's action in browser.

$_products = Mage::getModel('catalog/product')->getCollection();
foreach($_products as $_product){
    $product = Mage::getModel('catalog/product')->load($_product['entity_id']);
    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
    $stockItem->setData('manage_stock', 1);
    $stockItem->setData('is_in_stock', 1);
    $stockItem->setData('use_config_notify_stock_qty', 0);
    $stockItem->setData('qty', 10);
    try{
        $stockItem->save();
        $product->save();
    }catch(Exception $e){
        Mage::log($e->getMessage(),null,'mohit.log');
    }
}

I hope, my answer could solve your problem.

If not please comment. :)

0
votes

Please take a look at Magmi:

http://sourceforge.net/projects/magmi/

I have used it to import/update millions of products within minutes ( 30-45 minutes ).

The best part is that the csv column headers are build based on the ids of product fields/attributes so any time you'd like to update a field you can right click, inspect element in your admin panel and get the column header desired.

If you've already committed to your product import of choice you could write an observer that fires off on each product save, check if product quantity is > 0 and set the product to 'in stock' then save.

https://magento.stackexchange.com/questions/9067/catalog-product-save-after-event-for-massaction