Mass update product description programmatically Magento -
i need update description on more 1000 products. use code task. works created_at , updated_at fields got messed after running code. did miss something?
$products = mage::getmodel('catalog/product')->getcollection() ->setstoreid(0) ->addattributetoselect('description') ->addattributetofilter('price', array('gt' => 10.00)) ; foreach ($products $product) { $sku = $product->getsku(); $desc = $product->getdescription(); $descup = $desc.'<p>new text here</p>'; $update = mage::getmodel('catalog/product')->loadbyattribute('sku',$sku); $update->setstoreid(0); $update->setdescription($descup); try { $update->save(); echo "<pre>".$product->getsku(). " updated</pre>"; } catch (exception $e) { $e->getmessage(); } }
better way it:
$model = mage::getsingleton('catalog/product_action') ->getresource(); $products = mage::getmodel('catalog/product')->getcollection() ->setstoreid(0) ->addattributetoselect('description') ->addattributetofilter('price', array('gt' => 10.00)); foreach ($products $product) { $attrdata = array(); // array of attributes mass update product $attrdata['description'] = $product->getdescription() . '<p>new text here</p>'; //$attrdata['other_attr'] = 'value'; // mass update action, 0 - store id $model->updateattributes(array($product->getid()), $attrdata, 0); }
Comments
Post a Comment