2013-03-01 193 views

回答

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%')) 
+0

我是否需要修改它上面的線來搜索與說明背景? $ products = Mage :: getModel('catalog/product') - > getCollection() - > addAttributeToFilter('name',array('like'=>'%example%')); – Inflikted 2013-03-01 18:11:02

+0

看到我編輯這個功能 – dagfr 2013-03-01 18:56:44

+0

我試過編輯,但然後它給出了這個錯誤解析錯誤:語法錯誤,意想不到的T_FOREACH第33行 – Inflikted 2013-03-02 21:03:44

相關問題