Suppose I have an attribute that is a collection of option (dropdown/multiselect).
I can retrieve the attribute value for a given product:
$store_id = [something];
$productId = [something];
// this is a select/multiselect
$attribute_code = [something];
$option_id = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, $attribute_code, $store_id );
$option_label = ???
Now, I got the attribute option_id which is a numeric value ...
... What is the best way to load the frontend attribute label for my attribute value ? (without loading the full product)
Solution thanks Marius:
// Not loading the product - just creating a simple instance
$product = Mage::getModel('catalog/product')
->setStoreId($store_id)
->setData($attribute_code,$option_id);
$option_label = $product->getAttributeText($attribute_code);
getAttributeText('value')
doesn't work correctly if the attribute'sgetAllOptions()
method returns options arranged with nested arrays, (expressed as an<optgroup>
in the dropdown.)