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): ?>
- 
 Use this code also $_product->getData('attribute_code_here');Vishal– Vishal2016年02月26日 09:18:21 +00:00Commented Feb 26, 2016 at 9:18
1 Answer 1
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.
- 
 it does not give any output , metal is multiselect dropdown attribute , and using this code on product listing pagemcoder– mcoder2016年02月26日 09:54:44 +00:00Commented Feb 26, 2016 at 9:54
- 
 but does$_product->getMetal()output something?Marius– Marius2016年02月26日 09:55:46 +00:00Commented Feb 26, 2016 at 9:55
- 
 no but $_product->getPrice() and weight works finemcoder– mcoder2016年02月26日 09:59:20 +00:00Commented Feb 26, 2016 at 9:59
- 
 in this case, it depends on the context. If$_productcomes from a product collection, maybe the attributemetalis not added to the collection. You should add more info in your question. Provide the context that uses this.Marius– Marius2016年02月26日 10:00:32 +00:00Commented Feb 26, 2016 at 10:00
- 
 1added that code is used on product listing pagemcoder– mcoder2016年02月26日 10:03:49 +00:00Commented Feb 26, 2016 at 10:03