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

4
  • 1
    did you rebuild your indexes after adding your attribute?
    – Marius
    Commented Nov 17, 2015 at 11:50
  • try this <?php echo $_product->getData('mileage'); ?>
    – Magento 2
    Commented Nov 17, 2015 at 12:00
  • Yes I did rebuild them, that worked @Kothari Any idea why that worked but the attribute text didn't?
    – Nick M
    Commented Nov 17, 2015 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
    Commented Nov 17, 2015 at 13:24

1 Answer 1

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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.