我需要更新超过1000种产品的说明。我使用此代码来完成此任务。它工作正常,但运行此代码后,created_at和updated_at字段搞砸了。我错过了什么吗?
$products = Mage::getModel('catalog/product')->getCollection()
->setStoreId(0)
->addAttributeToSelect('description')
->addAttributeToFilter('price', array('gt' => 10.00))
;
foreach ($products as $product) {
$sku = $product->getSku();
$desc = $product->getDescription();
$descUp = $desc.'<p>New Text Here</p>';
$update = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$update->setStoreId(0);
$update->setDescription($descUp);
try {
$update->save();
echo "<pre>".$product->getSku(). " updated</pre>";
} catch (Exception $e) {
$e->getMessage();
}
}
答案 0 :(得分:1)
更好的方法:
$model = Mage::getSingleton('catalog/product_action')
->getResource();
$products = Mage::getModel('catalog/product')->getCollection()
->setStoreId(0)
->addAttributeToSelect('description')
->addAttributeToFilter('price', array('gt' => 10.00));
foreach ($products as $product) {
$attrData = array(); // Array of attributes to mass update for the product
$attrData['description'] = $product->getDescription() . '<p>New Text Here</p>';
//$attrData['other_attr'] = 'value';
// Mass update action, 0 - Store ID
$model->updateAttributes(array($product->getId()), $attrData, 0);
}
答案 1 :(得分:0)
你看过Magmi,http://sourceforge.net/projects/magmi/吗?您可以管理电子表格中的所有详细信息,并根据需要多次加载和重新加载和覆盖数据。