开发者

Saving In Magento Taking A Very Very Long Time

In Magento I write a number of small command line scripts to do things like set a new attribute on a number of products. I am finding that the time it takes to开发者_JAVA技巧 update 900 products takes about 6 hours to complete.

The time it takes to load the individual products goes as fast as I would except, but the act of saving once I have made the change takes a very long time.

I am attaching how I am loading the products in case there is something I can do to better optimize the process. Any help here would be greatly appreciated.

$product = Mage::getModel('catalog/product')->load($magento_id);
$product->setMadeInUsa(1);
try {
    $product->save();
} catch(Exception $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}

The code runs without error, but it takes forever.


Mage::getSingleton('catalog/product_action')
            ->updateAttributes(array($product->getId()), $attributesData, $storeId);

This code only updates the attributes you want to change. The first paramater is an array of product IDs, the second is an array of attribute names and values, and then the third is the store ID you wish to update.

This is MUCH faster than saving the entire model.


Try first seting indexing to Manual and then reindex after update is done. This should improve the performance. However the ultimate solution, if you are going to do the import often, is to follow the code ideas you can find in update attributes mass action, which is optimized for saving many products at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜