Get product attribute by product attribute group in magento 2

how to get an attribute group in magento 2 from a set of attributes . I want to show an attribute on a listing page using a group to add additional attributes in the future

+4
source share
2 answers

you just get the whole product attribute $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 />';
            }

    }
+2
source

You can get all the attributes as below:

$attributes = $product->getAttributes();
foreach ($attributes as $attribute) { 
     $attribute->getCode();
}

Ref. https://magento.stackexchange.com/questions/98945/magento-2-how-can-i-get-all-product-attributes-and-get-the-value-yes-no

+2
source

Source: https://habr.com/ru/post/1653259/


All Articles