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.

asked Apr 2, 2018 at 7:59

1 Answer 1

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
 ...
]);
answered Apr 2, 2018 at 8:11
1
  • 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. Commented Apr 2, 2018 at 8:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.