Likewise, to update any attribute, we first need to load product by SKU or by ID, then update the attribute value. In this example, the attribute is of type textbox and named “my_option”.
<?php //ensure to set current store as product attributes are store specific Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $productCollection = Mage::getModel('catalog/product')->getCollection(); foreach($productCollection as $product) { $attributeCode = "my_option"; echo "\n".'updating '.$product->getSku()."...\n"; $product = Mage::getModel('catalog/product’) ->load($product->getEntityId()); $product->setData($attributeCode, "enter_your_value") ->getResource() ->saveAttribute($product, $attributeCode); }
Cheers!