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..
2 comments