i wrote custom code to assign attribute to product , issue is with dropdown attribute say color with values : red , green , yellow

not i want to set value of color to be red so i used code below


but it does not works as i neet to put id instead of vlaue , but i do not want to put id , can anyone help in this case

1 Answer 1


Try this

  //Possible color value
  $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); //"color" is the attribute_code
  $allOptions = $attribute->getSource()->getAllOptions(true, true);
  foreach ($allOptions as $instance) {
    $id = $instance['value']; //id of the option
    $value = $instance['label']; //Label of the option

it will display your Label and ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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