更新资料
  我正在寻找质量属性更新的最快,最可靠的方法
属性或产品的“质量属性更新”?
认为已经回答了更新多个属性的问题,但是对于产品这可能是有用的...
如果要更新收藏中的产品,则不应执行此操作...
foreach ($collection as $product) {
    $product->setSomeData(...);
    # not here
    $product->save();
}
这将调度事件,重建价格规则和指数。有了这个,没有事件(和其他一些事情)被跳过,并且速度更快。
foreach ($collection as $product) {
    $product->setSomeData(...);
}
$collection->save();
为避免价格规则更新,您可以添加...
$product->setIsMassupdate(true);
要即时禁用/启用重新索引,请看一下... https://github.com/Flagbit/Magento-ChangeAttributeSet/commit/676f3af77fec880bc64333403675d183e8639fae
/**
 * Set indexer modes to manual
 */
private function _storeRealtimeIndexer()
{
    $collection = Mage::getSingleton('index/indexer')->getProcessesCollection();
    foreach ($collection as $process) {
        if($process->getMode() != Mage_Index_Model_Process::MODE_MANUAL){
            $this->_index[] = $process->getIndexerCode();
            $process->setData('mode', Mage_Index_Model_Process::MODE_MANUAL)->save();
        }
    }
}
/**
 * Restore indexer modes to realtime an reindex product data
 */
private function _restoreRealtimeIndexer()
{
    $reindexCodes = array(
        'catalog_product_attribute',
        'catalog_product_flat'
    );
    $indexer = Mage::getSingleton('index/indexer');
    foreach ($this->_index as $code) {
        $process = $indexer->getProcessByCode($code);
        if (in_array($code, $reindexCodes)) {
            $process->reindexAll();
        }
        $process->setData('mode', Mage_Index_Model_Process::MODE_REAL_TIME)->save();
    }
}
而且在批量(产品)更新之前刷新缓存可以提高性能……
Mage::app()->getCacheInstance()->flush();
从此处进行调试的一些数字:https://github.com/Flagbit/Magento-ChangeAttributeSet/issues/16
Mage::getSingleton('catalog/product_action')->updateAttributes(...) 似乎不是最快的方法...至少在mutlistore设置和平面表打开的情况下不是...
saveAttribute()
$product = Mage::getModel('catalog/product')->load($productId);
$resource = $product->getResource();
$product->setData($attributeCode, $attributeValue);
$resource->saveAttribute($product, $attributeCode);
- 总含税 墙时间(微秒):437,787微秒
 
- 总含税 CPU(微秒):423,600微秒
 
- 总含税 MemUse(字节):4,433,848字节
 
- 总含税 PeakMemUse(字节):4,395,128字节
 
- 函数调用数:25,711
 
 
updateAttributes()
Mage::getSingleton('catalog/product_action')->updateAttributes(
    array($productId),
    array($attributeCode => $attributeValue),
    $storeId
);
- 总含税 墙时间(微秒):3,676,950微秒
 
- 总含税 CPU(微秒):3,122,064微秒
 
- 总含税 MemUse(字节):8,174,792字节
 
- 总含税 PeakMemUse(字节):8,199,192字节
 
- 函数调用数:150,132
 
 
updateAttributes() (资源单例)
Mage::getResourceSingleton('catalog/product_action')->updateAttributes(
    array($productId),
    array( $attributeCode => $attributeValue),
    $storeId
);
- 总含税 墙壁时间(微秒):94,155微秒
 
- 总含税 CPU(微秒):48,568微秒
 
- 总含税 MemUse(字节):1,426,304字节
 
- 总含税 PeakMemUse(字节):1,370,456字节
 
- 函数调用数:2,221