Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 941
Capitaine Avatar asked Sep 16 '10 19:09

Capitaine


1 Answers

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);
like image 173
Anda B Avatar answered Oct 15 '22 13:10

Anda B