Magento – Get Product Attribute ‘Option Label’

attributesproduct

I have manage to retrieve the value for an attribute relative to a particular product

 $store_id = Mage::app()->getStore()->getStoreId();
 $attribute_code = 'code';
 $value =  Mage::getResourceModel('catalog/product')
        ->getAttributeRawValue($prod_id, $attribute_code, $store_id);

What I miss here is the label associated to the attribute value.

How can I get it, without load the full product object ?

Best Answer

This code works fine and avoid to load the entire product obj

$option_id = Mage::getResourceModel('catalog/product')
    ->getAttributeRawValue($prod_id, $attribure_code, $store_id); 

Method 1

$option_value = Mage::getResourceModel('eav/entity_attribute_option_collection')
    ->setStoreFilter($store_id)
    ->setIdFilter($option_id)
    ->getFirstItem()
    ->getValue();

Method 2 (@Marius)

// to be tested
// not loading the product - just creating a simple instance
$singleton_prod = Mage::getSingleton('catalog/product')
     ->setStoreId($store_id)
     ->setData($attribure_code, $option_id); 
$optionLabel = $singleton_prod->getAttributeText($attribure_code);