Magento – Default attribute value for all product in magento

attributesmagentoproduct

I want to set a default value of an attribute for all product.

Best Answer

I had same problem before,when i added 11096 product(downloadable products) in my store then client told me to add new attributes in product so i create 1 attribute (Type is Yes/No) and set to attribute set. Now my problem is how can i edit all product and set that attribute yes or not.if i not set then value is null so i wrote few line code.

Please check this code may be it'll helpful to you.

$ProductId = 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; 

//Now Update the attribute for the given products.

Mage::getSingleton('catalog/product_action')
    ->updateAttributes($ProductId, $attributeData, $storeId);
Related Topic