I created a custom attribute (dropdown) "product_overlay" in Magento (with options like "NEW", "Backorder", "Cashback available", etc.). I want to use the selected option in list.phtml to add a image to the view in case something is selected.
However, in some cases the system returns the option with the lowest ID (the one I created first) despite a different option or noting is selected. In other cases it works just fine.
I'm, using this line to get the selected value.
$overlay = $_product->getResource()->getAttribute('product_overlay')->getFrontend()->getValue($_product);
What would be the right way to debug this issue?
For dropdown attributes, using getAttributeText() tends to be the more robust way of retrieving data:
$overlay = $_product->getAttributeText('product_overlay');
EDIT - you can then cycle through the potential options:
<?php
if($overlay == "NEW") {
echo "something";
} elseif ($overlay == "Backorder") {
echo "something else";
} elseif ($overlay == "Cashback available") {
echo "another something";
} elseif {
// etc
}
?>