Menu Close

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

    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 ?
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

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


    2 comments

  • Damon Moats
    Great Work! Attribute are used for multiple purposes in Magento. There’s a very easy to follow guide for creating an attribute and attribute set programmatically in Magento on magenticians. I found it very easy to understand, I hope it helps others too. thanks
    • Rani Priya (Moderator)
      Your Welcome @Damon Moats
  • Back to Top