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();
Comments
Sorry, comments are closed on this page.