Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top