1

Hi i am trying to get the attributes of product from specific group. I am using following code.

$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';
    }       
 } 

I write this code in my phtml template. But this is not working. Please help me to solve this.

1 Answer 1

0

did you tried this is tested code

$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;
9
  • did you load all attributes of product? Nov 24, 2016 at 9:54
  • Yes it loads and shows the attribute label as i updated in the question Nov 24, 2016 at 9:57
  • $groupCollection->addFieldToFilter('attribute_group_name','Testing'); can you check the attribute group id is correct? Nov 24, 2016 at 10:02
  • I cross checked the group id in database eav_attribute_group table. It is correct. Nov 24, 2016 at 10:05
  • @NitinPawar let me test a get back to you Nov 24, 2016 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.