0

I currently have a working method which allows me to create an attribute set on the fly. This works well:

public function createAttributeSets($attribute_set_name) {
 $attr_set_id = $this->getAttrSetId("generated_" . $attribute_set_name);
 if (!$attr_set_id) {
 $entityTypeCode = 'catalog_product';
 $entityType = $this->eavTypeFactory->create()->loadByCode($entityTypeCode);
 $defaultSetId = $entityType->getDefaultAttributeSetId();
 $attributeSet = $this->attributeSetFactory->create();
 $data = [
 'attribute_set_name' => $attribute_set_name,
 'entity_type_id' => $entityType->getId(),
 'sort_order' => 200,
 ];
 $attributeSet->setData($data);
 try {
 $this->attributeSetManagement->create($entityTypeCode, $attributeSet, $defaultSetId);
 } catch (Exception $e) {
 }
 return $attributeSet->getId();
 } else {
 return $attr_set_id;
 }
}

Now I'd like to create an attribute group within this attribute set so that it's ready to place my new attributes within it.

Is this group automatically created if I assign a new attribute to a non-existing group name when I create it?

asked Dec 8, 2017 at 10:26

1 Answer 1

1

Yes to add group and attribute in that group, you just need to add that group name into new attribute parameters. like bellow

'type' => 'int',
.....
.....
.....
'group' => "Attribute Group Name"

That's it. Once it will run that script and create new attribute it will create new attribute group and assign that new attribute into that new group. This is for magento2x.

Thanks

answered Dec 9, 2017 at 7:33

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.