$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);
4 回答
之前我有同样的问题,当我在我的商店中添加11096产品(可下载的产品)时,客户端告诉我在产品中添加新属性,所以我创建1个属性(类型是是/否)并设置为属性集 . 现在我的问题是如何编辑所有产品并设置该属性是或否 . 如果我没有设置那么值为null所以我写了几行代码 .
请检查此代码可能对您有所帮助 .
如上所述: - http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-attributes-custom-fields
因此,我认为它仅适用于您在创建该属性后创建的新产品 . 因此,属性的默认值设置可能不适用于在创建属性之前创建的那些产品 .
我有类似的问题并解决它,我在文件中写了以下代码,我想显示属性的默认值: -
您可以在属性管理中执行此操作
管理面板 - 目录 - 属性 - 管理属性
选择属性 - 属性 - 属性属性 - 默认值
您还可以通过对所有产品执行massupdate来解决问题 . 转到Manage Products paga和Select All,然后选择Update属性 .