1
votes

The solution for this was almost provided in this answer https://stackoverflow.com/a/14249171 It does indeed replace the product name properly.

But I needed to take it a step further and check the productname, description and short description to replace 'example' with 'test' in all three areas. I wasn't sure if it was possible to modify the current script provided to include these other attributes.

1

1 Answers

1
votes

this do the trick :

$newName = str_replace('example','test',$product->getName());
$product->setName($newName);

Find it and add the other attributes :

$newDescription = str_replace('example','test',$product->getDescription());
$product->setDescription($newDescription);
$newShortDescription = str_replace('example','test',$product->getShortDescription());
$product->setShortDescription($newShortDescription);

Then save each attribute like this :

$product->getResource()->saveAttribute($product,'description');
$product->getResource()->saveAttribute($product,'short_description');

Or just save the product (time and resource consuming)

$product->save();

To select only product having example in name OR description OR short_desc use this

 -addAttributeToFilter(array(array('attribute'=>'name','like'=>'%example%'), array('attribute'=>'description','like'=>'%example%'),array('attribute'=>'short_description','like'=>'%example%')))

Instead of

->addAttributeToFilter('name',array('like','%example%'))