这个问题的解决方案几乎在这个答案中提供https://stackoverflow.com/a/14249171 它确实正确地替换了产品名称。
但是我需要更进一步,检查产品名称,描述和简短描述,在所有三个方面用'test'替换'example'。我不确定是否可以修改提供的当前脚本以包含这些其他属性。
答案 0 :(得分:1)
这就是诀窍:
$newName = str_replace('example','test',$product->getName());
$product->setName($newName);
找到它并添加其他属性:
$newDescription = str_replace('example','test',$product->getDescription());
$product->setDescription($newDescription);
$newShortDescription = str_replace('example','test',$product->getShortDescription());
$product->setShortDescription($newShortDescription);
然后像这样保存每个属性:
$product->getResource()->saveAttribute($product,'description');
$product->getResource()->saveAttribute($product,'short_description');
或者只是保存产品(耗费时间和资源)
$product->save();
要仅选择名称中包含示例的产品或描述或short_desc使用此
-addAttributeToFilter(array(array('attribute'=>'name','like'=>'%example%'), array('attribute'=>'description','like'=>'%example%'),array('attribute'=>'short_description','like'=>'%example%')))
而不是
->addAttributeToFilter('name',array('like','%example%'))