How to get attribute “option label/attribute text” having “attribute value” (option_id)?
-
16-10-2019 - |
Question
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);
Solution
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');
OTHER TIPS
$attribute = Mage::getModel('catalog/resource_eav_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
$label = $attribute->getFrontendLabel();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange