5

I want to display custom attribute value under the product name on category page.

Attribute type is dropdown and attribute name is Brand.

I want to display the brand name under the product name on category page in GRID and LIST mode.

How can i do that? What's the standard way to display brand name under product name?

Do i need to create any module for that or custom function?

Any help would be appreciated.

3 Answers 3

10

Edit below file

app/design/frontend/CUSTOM/THEME/Magento_Catalog/templates/product/list.phtml

$attribute = $_product->getResource()->getAttribute('attribute_code');

// Get Value

$attributeValue = $attribute->getFrontend()->getValue($_product);

// Get Label

$attributeLabel = $attribute->getStoreLabel();

Note: Make sure “Visible on Product View Page on Front-end” and “Used in Product Listing” options under storefront Properties are set to Yes.

1
  • Thank you for your answer. How do you display the attribute (control the output product name) on the product details page though? I would like to display Capacity just under the product name "title". Thanks. Commented May 3, 2019 at 6:32
1
<?php/***********Display Brand Attribute************/?>
<?php
$om = \Magento\Framework\App\ObjectManager::getInstance();
$attribute = $om->get(\Magento\Catalog\Api\ProductAttributeRepositoryInterface::class)->get('manufacturer');
?>
<ul>
<?php
if($attribute){
    foreach ($attribute->getOptions() as $option) {
        $name = $option->getLabel();
        $optId = $option->getValue();
        $curnt_cat_url = $category->getUrl();
        $brandId = '?manufacturer='.$optId;

        $swatchHelper=$om->get("Magento\Swatches\Helper\Media");
        $swatchCollection = $om->create('Magento\Swatches\Model\ResourceModel\Swatch\Collection');

        $swatchCollection->addFieldtoFilter('option_id',$optId);
        $item=$swatchCollection->getFirstItem();
        $ThumbImage =  $swatchHelper->getSwatchAttributeImage('swatch_thumb', $item->getValue());
        //$SwatchImage = $swatchHelper->getSwatchAttributeImage('swatch_image', $item->getValue());
?>
        <?php if ($optId) { ?>
            <div class="brand_bg">
                <li class="brand_img_bg"> 
                    <a href="<?php echo $curnt_cat_url.$brandId ?>"><img src="<?php echo $ThumbImage; ?>"></a>
                </li>
                <!--<a href="<?php //echo $curnt_cat_url.$brandId ?>"><?php //echo $name; ?></a>-->
            </div>
        <?php } ?>
    <?php } ?>
<?php } ?> 
</ul>
1

If you follow Abhishek Panchal answer above even-then your custom attribute value noe displaying on category pages the confirm you had not enabled this attribute for catalog pages: edit the attribute select:

storefront properties -> Used in Product Listing -> yes
1

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.