Back to Top

Get All Attribute Group Ids And All Attribute Ids Of A Specific Attribute Set In Magento 2

Updated 28 February 2024

Get All Attribute Group Ids And All Attribute Ids Of A Specific Attribute Set In Magento 2- Here I’m going to explain you that how to get all attribute groups and all attributes of a specific attribute set in magento 2.

        $attributeSetId = 4;
        $groupIds = [];
        $attributeids = [];
        // \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory
        $groupCollection = $this->attributeGroupCollection->create()
            ->setAttributeSetFilter($attributeSetId)
            ->load(); // product attribute group collection
        foreach ($groupCollection as $group) {
            array_push($groupIds, $group->getAttributeGroupId());
            // \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory
            $groupAttributesCollection = $this->productAttributeCollection->create()
                ->setAttributeGroupFilter($group->getId())
                ->addVisibleFilter()
                ->load(); // product attribute collection
            foreach ($groupAttributesCollection->getItems() as $attribute) {
                array_push($attributeids, $attribute->getAttributeId());
            }
        }
        print_r($groupIds); // It will print all attribute group ids
        print_r($attributeids); // It will print all attributes ids

In this way you can get all attributes and all attribute group ids of a specific attribute set.
Thanks..

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Damon Moats
    • Rani Priya (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home