TransWikia.com

magento 2 custom attributes value frontend return No value of select

Magento Asked by Creativity Group on December 14, 2021

I have a problem in retrieving the value of custom attribute of type select, it returns a value No
enter image description here

I try this code in

list.phtml:

 <span class="product_badge_value">
 <?php /* @escapeNotVerified */ print_r($_product->getResource()->getAttribute('product_badge')->getFrontend()->getValue($_product)); ?>
  </span>

3 Answers

This is the property/bug of Magento custom attribute where it will create records in eav table only after we save that particular product manually. Otherwise the attribute returns a NULL value. So if you need to get the value for product_badge attribute you need to save that particular product and check from the front end.

Answered by VIPIN A ROY on December 14, 2021

You have to set yes in:

Stores -> Attributes -> Product (edit attribute) -> Storefront properties -> Visible on Catalog Pages on StoreFront

enter image description here

Answered by Eduardo Pedrosa on December 14, 2021

After adding custom attribute, you need to reindex and clear cache as follows.

php bin/magento indexer:reindex
php bin/magento cache:flush

Then try again.

Answered by Kishan Patadia on December 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP