1

I have added a new drop-down attribute called features to products.

It is basically a list of options that I want to show on the front end. I have used this code to my list.phtml file for get option values:

<?php echo $_product->getfeatures() ?>

But it will display as number instead of text on fronted.

How I can display drop down option value as text ?

The below picture shows 2 features but instead of text it shows as numbers. Can anyone help?

enter image description here

2
  • The piece of code I added was:
    – DevAnd
    Oct 7 '16 at 19:41
  • <?php echo $_product->getfeatures() ?>
    – DevAnd
    Oct 7 '16 at 19:42
1

if you use:

<?php echo $_product->getFeatures();?> 

it will return option value of attribute like 18,19

if you use:

<?php $_product->getAttributeText('features');?> 

it will return an Array

so first get an Array and convert it to String

<?php $features = $_product->getAttributeText('features');?> 
<?php echo implode(",", $features) ;?>

It will display your Text

0

Within either catalog/product/view.phtml or catalog/product/list.html you can use this to output the attribute text:

echo $_product->getAttributeText('features');
0

If you want to display attribute option value then you should write code like this

<?php $_product->getAttributeText('features');?> 

insted of

<?php echo $_product->getFeatures();?>
0

You can get your selected options like:

$x = $_product->getResource()->getAttribute('your_attribute_code');

and then get the values of your selected options:

$x->getFrontend()->getValue($_product);

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.