4

Well I have this code here and I am adding it to my list.phtmlfile to try and get the attribute text for each product to display:

<?php echo $_product->getAttributeText('mileage') ?>

This code works with any attribute that has a Catalog Input Type for Store Owner value of dropdown however it does not display for attributes with the value of Text Field.

Any idea why this might be happening?

I have the setting Used in Product Listing enabled for both attributes.

Thanks

  • 1
    did you rebuild your indexes after adding your attribute? – Marius Nov 17 '15 at 11:50
  • try this <?php echo $_product->getData('mileage'); ?> – Magento 2 Nov 17 '15 at 12:00
  • Yes I did rebuild them, that worked @Kothari Any idea why that worked but the attribute text didn't? – Nick M Nov 17 '15 at 12:11
  • 1
    getAttributeText() method is specifically there for dropdown type attributes. If you take a look at the method in Product model, you'll find that the method gets value index from Product data and then, finds the text for that index in respective table. – Prateek Nov 17 '15 at 13:24
1

Make sure Visible on Product View Page on Front-end and Used in Product Listing options under properties of this attribute are set to Yes.

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.