如何通过Magento API以编程方式将属性分配给特定属性集?

Cap*_*ine 11 php api attributes magento

标题.我没有找到相关的解决方案/问题.我只是想知道如何通过API为某个属性集的产品分配新属性.

小智 29

像这样的东西:

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