1

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>
  • It's look like your code is right. try echo instead of print_r() – Prince Patel May 10 '17 at 11:03
  • Did you ever figure this out? – TheRealJAG Oct 25 '18 at 6:56
0

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.

  • same problem it doesn't work. – Creativity Group May 10 '17 at 10:30
  • Same poblm :/<span class="product_badge_value"> <?php $badge=$_product->getResource()->getAttribute('product_badge')->getFrontend()->getValue($_product); /* @escapeNotVerified */ echo $badge ; ?> </span> – Creativity Group May 10 '17 at 13:26
0

You have to set yes in:

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

enter image description here

0

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.

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.