I have written quite a few scripts to update my product catalog based on some or other parameter. In each of them the base logic is something simillar to this…
//Get collection
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('sku');
$collection->addAttributeToSelect('publihser');
$collection->addFieldToFilter(array(array('attribute'=>'publisher','eq'=>$publisher)));
// for each product in collection do a individual save
foreach ($collection as $product) {
$product->setSKU($newValue);
$product->save();
}
Though this work, each save is a SQL update query and the fact is that having a very large catalog, this is fairly slow.
I was wondering if this could be sped up by doing single save on the collection instead on the product.
There are several things you can do to write a much faster update script. I don’t know how you are getting some of your variables so you’ll need to modify to get it working in your case, but the code below should be much faster than the way you are currently doing it. e.g: