magento中所有产品的默认属性值

Sha*_*lam 3 attributes product magento

我想为所有产品设置属性的默认值.

小智 5

之前我有同样的问题,当我在我的商店中添加11096产品(可下载的产品)时,客户端告诉我在产品中添加新属性,所以我创建1个属性(类型是是/否)并设置为属性集.现在我的问题是如何编辑所有产品并设置该属性是或否.如果我没有设置那么值为null所以我写了几行代码.

请检查此代码可能对您有所帮助.

$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);
Run Code Online (Sandbox Code Playgroud)