Magento 2 – Get Product Attribute by Attribute Group

magento-2.1magento2

How to get product attribute group in magento 2 from a attribute set. I want to show attribute on listing page by using a group so i can add more attributes in future

Best Answer

you simply get all product attribute by $product->getAttributes();

$productAttributes=$product->getAttributes();
        $group_id=9;
        $attributeSetId=4;
        foreach ($productAttributes as $attribute) {
            if ($attribute->isInGroup($attributeSetId, $group_id)) {
             echo $attribute->getFrontendLabel().' : '.$attribute->getFrontend()->getValue($product).'<br />';
            }

    }
Related Topic