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?

Était-ce utile?

La 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.

Autres conseils

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;
}
?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top