Magento 2: Проверьте, находится атрибут в определенной группе или нет


Привет, я пытаюсь получить атрибуты продукта из определенной группы. Я использую следующий код.

$pattr = $product_coll->getAttributeSetId();
$group_id = $block->getAttributeGroupId($pattr);
$attrCodes = $block->getProductAttrData($pattr);
foreach($attrCodes as $attrCode)
{
    echo $attrCode->getDefaultFrontendLabel().'<br>';
    if ($attrCode->isInGroup($pattr, $group_id))
    {
        echo 'In Product details';
    }       
 } 

Я пишу этот код в своем шаблоне phtml. Но это не работает. Пожалуйста, помогите мне решить эту проблему.

Author: Nitin Pawar, 2016-11-24

1 answers

Пробовали ли вы этот проверенный код

$productAttributes=$product->getAttributes();
      foreach ($productAttributes as $attribute):
        if ($attribute->isInGroup($pattr, $group_id)):
            if($attribute->getFrontend()->getValue($product_coll)):
                echo $attribute->getFrontendLabel().' : '.$attribute->getFrontend()->getValue($product_coll).'<br />';
            endif;
         endif;
      endforeach;
 0
Author: Fme Extensions, 2016-11-24 10:38:38