Someone can ask you to change a product attribut value for every products. When you’ve got thousands of products, it can be a little complicated. Loop on a collection with a save inside is very long, and a massAction on the BO is useless if it need to be automatic.

Fortunatly, there is a method for this job :

<?php

/* Here is my collection, after apply filters, I do getAllIds() */

$aIds = Mage::getModel('catalog/product')->getCollection()
				->addAttributeToFilter('status', 1)
				->addFieldToFilter('visibility', array("gt" => '1'))
				->getAllIds();

$storeId = 0; // Default store ID, you can change it if you need.

Mage::getSingleton('catalog/product_action')->updateAttributes($aIds, array('myAttribute' => 'myValue'), $storeId);

?>
Mass update of products attribute value

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to ensure that we give you the best experience on our website.
Ok