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?

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

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.