0

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.

2

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);
  • Getting Call to a member function getSource() on a non-object in gi es an error.. Any idea? – xvilo Feb 25 '17 at 12:05
  • getAttributeText will only work if your attribute is of type select @xvilo – Gopal Patel Feb 25 '17 at 12:09
  • Not sure where to find type select. the input type is on dropdown – xvilo Feb 25 '17 at 12:12
  • yes select is nothing but dropdown only. Then it must be work @xvilo – Gopal Patel Feb 25 '17 at 12:14
  • Bút, it doesn't. – xvilo Feb 25 '17 at 12:15
1

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');
  • Getting Call to a member function getSource() on a non-object in gi es an error.. Any idea? – xvilo Feb 25 '17 at 12:02

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.