1
此答案中几乎提供了此解决方案https://stackoverflow.com/a/14249171 它的确可以正确替换产品名称。更新产品名称,描述,Magento中的简短说明
但我需要更进一步,检查产品名称,说明和简短说明,以在所有三个方面用'test'取代'example'。我不确定是否可以修改提供的当前脚本以包含这些其他属性。
此答案中几乎提供了此解决方案https://stackoverflow.com/a/14249171 它的确可以正确替换产品名称。更新产品名称,描述,Magento中的简短说明
但我需要更进一步,检查产品名称,说明和简短说明,以在所有三个方面用'test'取代'example'。我不确定是否可以修改提供的当前脚本以包含这些其他属性。
这做的伎俩:
$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%'))
我是否需要修改它上面的线来搜索与说明背景? $ products = Mage :: getModel('catalog/product') - > getCollection() - > addAttributeToFilter('name',array('like'=>'%example%')); – Inflikted 2013-03-01 18:11:02
看到我编辑这个功能 – dagfr 2013-03-01 18:56:44
我试过编辑,但然后它给出了这个错误解析错误:语法错误,意想不到的T_FOREACH第33行 – Inflikted 2013-03-02 21:03:44