0

I am trying to bulk update some of my product attributes. Effectively I am using this code:

foreach ($outOfStock as $product) {
    $product->setData('attribute',20);
    $product->save();
}

However I am getting a php 60 second timeout, when I check, it only got as far as about 15 products. It seems to me that this is not the most efficient way to achieve this.

What is the correct way to update products in bulk?

4

1 回答 1

2

如果你的属性是可批量更新的,你可以参考相应的核心代码Mage_Adminhtml_Catalog_Product_Action_AttributeController::saveAction(),尤其是这个方法:

Mage::getSingleton('catalog/product_action')
    ->updateAttributes($productsIds, $attributesData, $storeId);
于 2013-06-17T08:59:24.440 回答