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