3

(Magento 2.2.6) Hi, normally when you remove attribute group from an attribute set you still see the attributes that belonged to the group under "Unassigned Attributes" section of attribute set edit page on adminhtml. I'm working on tiding up a store and want to do this programatically, I'm removing unused groups from couple sets in upgrade script with

$this->eavSetup->removeAttributeGroup(
     $entityTypeId,
     $set->getAttributeSetId(),
     $groupName
);

The code works and removes the group from sets but unfortunately the attributes that belonged to the group are no longer visible on attribute set edit page. The attributes are definitely not removed since they are visible on sets that were not touched with the upgrade script. I've tried reindexing, flushing cache, removing view_preprocessed and pub/static (bascially everything I could think of that could affect frontend) but it still doesn't work.

Maybe someone has experiece with such issue? I'm kinda lost here because it seems that the removeAttributeGroup works as intended but I would like to add these attributes back with admin panel in the future if such need occur.

0

It seems that eavSetup doesn't have necessary method so what we have to do is to call setRemoveAttributes method on attributeSet model and then save the set model. In the argument we need to state list of attribute entities (thingies that are responsible for holding connections between attributes themselves and groups and some other stuff), to generate it I used attribute group filter:

$this->eavEntityAttrCollectionFactry->create()
                ->setAttributeGroupFilter($groupData['attribute_group_id']);

Only then, after saving the attribute set we can proceed to remval of attribute group as pasted in the first message in the topic.

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.