Question

I'm trying to compare an attribute value with a custom value. We use the getAttributeRawValue to get the product's attribute. That give's me the ID of the value. (If that makes sense).

Currently I use this line:

$col = Mage::getResourceModel('catalog/product')->getAttributeRawValue($simp, 'manufacturer_color', 0);`

Attribute with code manufacturer_color is of type Select

which outputs 1587, I want it to output the 'label' value which in my case should be blue.

Était-ce utile?

La solution

Try it using getAttributeText() function and this function will only work with the attribute type select

$col=$simp->getAttributeText('manufacturer_color');

getAttributeRawValue() returns the id of options

OR

$col=$simp->getResource()->getAttribute('manufacturer_color')->getFrontend()->getValue($simp);

Autres conseils

You can use getAttributeText to get product label.

$label = Mage::getModel("catalog/product")->load($simp)->getAttributeText("manufacturer_name");

You can use as per Marius's answer like,

$col = \Mage::getResourceModel('catalog/product')->getAttributeRawValue($simp, 'manufacturer_color', 0);
$product = Mage::getModel('catalog/product')
     ->setStoreId(0)
     ->setData('manufacturer_color',$col); 
$optionLabel = $product->getAttributeText('manufacturer_color');
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top