3

I need to get all the attribute group id associated with the product.

Code:

$product_coll = $block->getProduct($product_id);
$pattr = $product_coll->getAttributeSetId();
$attrCodes = $block->getProductAttrData($pattr);
foreach($attrCodes as $attrCode)
{
    echo $attrCode->getDefaultFrontendLabel().'<br>';
    $code = $attrCode->getAttributeCode().'<br>';
    echo $product_coll->getData($code).'<br>';
    echo $block->getProductAttrValue($product_id, $code).'<br>';

}

I want to filter the attribute with it's group or group name "product details". Any help appreciated.

5

Block function

public function getAttributeGroupId($attributeSetId)
    {
         $obj = \Magento\Framework\App\ObjectManager::getInstance();

        /** @var \Magento\Catalog\Model\Config $config */
        $config= $obj->get('Magento\Catalog\Model\Config');

        return $attributeGroupId = $config->getAttributeGroupId($attributeSetId, 'Product Details');

    } 

In html file

$group_id = $block->getAttributeGroupId('attribute_set_id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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