Question

I want to get a dropdown attribute value on the category page, i set the show in listing to yes and added this attribute to product. then set below code to my list.phtml:

productAttribute($_product, $_product->getMaterial(), 'material') ?>

but get the id of the attribute value. mean that now i see 72 instead of Bronze How can i get the value test?

Was it helpful?

Solution

Try the below code to get the attribute value :

$attr = $_product->getResource()->getAttribute('your_attribute_code')->getFrontend()->getValue($_product);

and try to print the $attr variable.

OTHER TIPS

Try following code, I did something similar but that was on the product page.

<?php  $_attributeValue = $_helper->productAttribute($_product, $_product->getMaterial(), 'material'); 
if ($_attributeValue):
$attribute = $_product->getResource()->getAttribute($_code);
if ($attribute->usesSource()) {
    $optionText = $attribute->getSource()->getOptionText($_attributeValue);
    echo $optionText;
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top