Jun 14, 2011

Magento: Saving Attribute

Magento: Saving Attribute



$_product->getResource()->saveAttribute($_product, 'vas_rating');


For bulk UPDATE



//Get the product Ids you want to affect. For me it was all downloadable products
$downloadableProductIds = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)
->getAllIds();
//Now create an array of attribute_code => values
$attributeData = array('my_attribute_code' => 'my_attribute_value);
//Set the store to affect. I used admin to change all default values
$storeId = 0; //A.K.A Admin
//Now Update the attribute(s) for the given products.
Mage::getSingleton('catalog/product_action')
->updateAttributes($downloadableProductIds, $attributeData, $storeId);

No comments: