Reputation: 35744
I want to add a new product attribute and am using code similar to this:
/**
* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
*/
$installer = $this;
$attribute = array(
'label' => 'New Attribute',
'required' => false,
'type' => 'varchar',
'input' => 'text'
);
$installer->addAttribute('catalog_product', 'new_attribute', $attribute);
Which works fine.
But, I want to add this attribute to a specific attribute set and ONLY to this specific attribute set.
How can this be achieved?
Upvotes: 0
Views: 193
Reputation: 2233
Assuming you know the $attributeSetId
, the procedure is as follows:
For example
$attributeId = $installer->getAttributeId(
'catalog_product',
'new_attribute'
);
$attributeGroupId = $installer->getAttributeGroup(
'catalog_product',
$attributeSetId,
'General'
);
$installer->addAttributeToSet(
'catalog_product',
$attributeSetId,
$attributeGroupId,
$attributeId
);
Upvotes: 1