How to add an product attribute to multiple attribute sets programmatically?
This question has been answerded for Magento 1, but how does it work with Magento 2?
Edit: I create all my custom attributes in an installation script. They are created when installing magento (I add my extentions to the Magento folder before installing it on a server). At this time I don't know about the attrubute sets. They are created later during an import. So I want to assign existing custom attributes when creating an attribute set.
1 Answer 1
If you provide a value for 'group' in the attribute configuration array the attribute will be added to that group in all attribute sets:
$eavSetup->addAttribute('catalog_product', 'my_attribute', [
...
'group' => 'General', // or some other group name
...
]);
-
I create all my custom attributes in an installation script. They are created when installing magento (I add my extentions to Magento folder before installing it on a server). At this time I don't know about the attrubute sets. They are created later during an import. So I want to assign existing custom attributes when creating an attribute set.Jens– Jens2018年04月02日 08:15:46 +00:00Commented Apr 2, 2018 at 8:15