magento中所有产品的默认属性值 [英] Default attribute value for all product in magento

查看:26
本文介绍了magento中所有产品的默认属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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);

这篇关于magento中所有产品的默认属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆