Bulk updating prices in Magento e-Commerce

Keeping your product catalog up-to-date is always a bit of a pain. Whilst Magento provides you with a very sophisticated multiple product/attribute editing system, you can only do this on 200 products at most. So what do you do if you want to bulk update all the prices in your catalog? Well you could directly query the database. But Magento’s complex EAV database is kinda scary, so as a rule I prefer to use the existing Magento API.

$model = Mage::getModel('catalog/product');
$products = $model->getCollection()
   ->addAttributeToSelect( array('name', 'description', 'price') )
    ->addAttributeToFilter('someAttribute', 'someValue');

foreach ($products as $product) {
    /* @var $product Mage_Catalog_Model_Product */
    $product->setPrice(1);
    $product->save();
    print $product->getId() . " " .  $product->getName() . " " . $product->getPrice() . "<br />";
 }
Mage::app()->cleanCache();
This entry was posted in Magento and tagged , , , . Bookmark the permalink.

Comments

Awwww. No one's left a comment yet. Why don't you start things off?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Email Alerts

Signup to receive occasional emails with news that may be of interest. Your details will never be disclosed to 3rd parties.




* = required field
I'm interested in...