18

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);
  • 2
    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
49

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');
9
$attribute = Mage::getModel('catalog/resource_eav_attribute')
            ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
$label     = $attribute->getFrontendLabel();
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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