Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
share|improve this question
1  
Why this question is given several times by exact author and all of them confusing users. Can we mark as duplicate like these questions without correct answers? This magento.stackexchange.com/questions/3003 question given by the author is no correct answers, but why upvotes (and given own answer)! This one magento.stackexchange.com/questions/976 is also same. Maybe my request is not right, but one question, one author and no answers. Please, keep the quality of the site. Thanks. – mageUz Sep 24 '13 at 10:16
    
I have improved the other question adding @Marius solution magento.stackexchange.com/questions/3003/… – Fra Dec 19 '13 at 17:06
1  
Note that at least in Magento CE 1.9 and EE 1.14 and below, getAttributeText('value') doesn't work correctly if the attribute's getAllOptions() method returns options arranged with nested arrays, (expressed as an <optgroup> in the dropdown.) – Tyler V. Jan 8 '15 at 5:01
up vote 36 down vote accepted

In addition to your code put this:

$product = Mage::getModel('catalog/product')
                ->setStoreId($store_id)
                ->setBrand($brand_value); // not loading the product - just creating a simple instance
$brandLabel = $product->getAttributeText('brand');
share|improve this answer
    
this look good, thanks – Fra Sep 24 '13 at 9:23
$attribute = Mage::getModel('catalog/resource_eav_attribute')
            ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
$label     = $attribute->getFrontendLabel();
share|improve this answer
1  
I confused for "frontend attribute label", please, correct the question. Not "attribute label", this is "option label" or "attribute text" – mageUz Sep 24 '13 at 10:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.