且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Magento的所有产品默认属性值

更新时间:2022-06-20 07:46:48

我以前同样的问题,当我在我的商店增加11096产品(下载产品),然后客户端告诉我加在产品新的属性,所以我创建1属性(类型是是/否),并设置为属性集。
现在我的问题是如何编辑的所有产品,并设置该属性是或not.if我不会设置值为空,所以我写了几行code。

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.

请检查该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);