开发者

How can a attribute be assigned to specific attribute set programmatically via Magento API?

开发者 https://www.devze.com 2023-01-16 17:03 出处:网络
as titled. I found no related solutions / questions . I just wonder how I can assign a new attribute to a product of certain 开发者_开发百科attribute set via API.Something like this:

as titled. I found no related solutions / questions . I just wonder how I can assign a new attribute to a product of certain 开发者_开发百科attribute set via API.


Something like this:

$attribute_set_name = 'your attribute set name here';
$group_name = 'your attribute group here';
$attribute_code = 'your attribute code here';

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

            //-------------- add attribute to set and group
            $attribute_set_id=$setup->getAttributeSetId('catalog_product', $attribute_set_name);
            $attribute_group_id=$setup->getAttributeGroupId('catalog_product', $attribute_set_id, $group_name);
            $attribute_id=$setup->getAttributeId('catalog_product', $attribute_code);

            $setup->addAttributeToSet($entityTypeId='catalog_product',$attribute_set_id, $attribute_group_id, $attribute_id);


I'm not certain on exactly how you would do it, but I would imagine that using Mage_Eav_Model_Mysql4_Entity_Attribute_Collection and Mage_Eav_Model_Entity_Attribute_Group will get you in the right direction...

0

精彩评论

暂无评论...
验证码 换一张
取 消