Magento – Magento 2 – Show product options and attributes in categories

attributescategory-viewcustom-optionsmagento2products

I need some help to display products custom options and attributes in category view, I can't find any guide to do this.

What I want to do is that if a simple product has custom options to display a list with those in the category view.
Also I'd like to show the products attributes there too, not all attributes but ones I've selected in the template with attribute codes.

Best Answer

As we need to override below file

From:

magento\vendor\magento\module-catalog\view\frontend\templates\product\list.phtml

To:

magento\app\design\frontend\Custom\YourTheme\Magento_Catalog\templates\product\list.phtml

Content:

 <?php foreach ($_productCollection as $_product): ?>
        <?php echo($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
        <div class="product-item-info" data-container="product-grid">
            <div class="your-custom-class">
            <?php
            // START DISPLAY ATTRIBUTE
            $attributeName = $_product->getResource()->getAttribute('your_attribute_name');
            if ($attributeName) {
                $labelValue = $attributeName->getFrontend()->getValue($_product);
            }
echo $labelValue;
            // END DISPLAY ATTRIBUTE
            ?>
            </div>
        </div>
    <?php endforeach; ?>    

Please check from Main File & U can display your thing as needed & adjust as per your design.

Thanks.

Related Topic