0

How to get Attributes of a Group of Default Attribute Set in my custom phtml in Magento_Catalog module.

using following code

catalog_product_view.xml:

<referenceContainer name="after.body.start">
    <block class="Magento\Catalog\Block\Product\View\abstractView" name="product_view_custom_features"
        template="Magento_Catalog::product/view/features.phtml" before="-"></block>
</referenceContainer>

template:

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();

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

    }

1 Answer 1

0

Your code works if you fix the typo:

$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();

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

    }

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.