1

i want to get attribute value for multi select attribute,

below is code that work if it is just text field or drop down , but for multi select it does not work , please guide way to fix it

$_product->getMetal();

works for text attibute for not for multiselect attibutes.

I am using above code on product listing page.

sample snap from where $_product comes:

<?php foreach ($_productCollection as $_product): ?>
asked Feb 26, 2016 at 8:23
1
  • Use this code also $_product->getData('attribute_code_here'); Commented Feb 26, 2016 at 9:18

1 Answer 1

2

This should give you what you need

$_product->getAttributeText('attribute_code_here');

If you are using this from a collection, make sure the attribute you use is marked as "Used in product listing" and that you rebuilt the indexes.

answered Feb 26, 2016 at 8:58
6
  • it does not give any output , metal is multiselect dropdown attribute , and using this code on product listing page Commented Feb 26, 2016 at 9:54
  • but does $_product->getMetal() output something? Commented Feb 26, 2016 at 9:55
  • no but $_product->getPrice() and weight works fine Commented Feb 26, 2016 at 9:59
  • in this case, it depends on the context. If $_product comes from a product collection, maybe the attribute metal is not added to the collection. You should add more info in your question. Provide the context that uses this. Commented Feb 26, 2016 at 10:00
  • 1
    added that code is used on product listing page Commented Feb 26, 2016 at 10:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.