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?
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
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.