0

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.

0

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 Apr 2 '18 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.