Pages

Showing posts with label bulk update products. Show all posts
Showing posts with label bulk update products. Show all posts

Sunday, November 23, 2014

Bulk update products to be in/out of stock programatically

This is an example to set all (filtered) products to be in stock with quantity of 1.

$products = Mage::getModel('catalog/product')->getCollection();
// filter your product list
$products = $products->addFieldToFilter($attribute_code, $attribute_value)->load();

foreach($products as $product){
 $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product); 
 $stockItem->setData('is_in_stock', 1);
 $stockItem->setData('qty',1);
 $stockItem->save();
}