I have generate XML file using Product list, there are sections called AttributeValueCode and AttributeValueLabel.

Want to get Label and Value(id) for the options of attribute having type select

Any one have idea about this ?

  • do you mean attribute code and attribute label? Commented Feb 24, 2017 at 5:54
  • No. if color is black , have to get its code? is it possible?
    – Lasantha
    Commented Feb 24, 2017 at 6:08
  • I found this, This should be the answer for my question ? $attr = $product->getResource()->getAttribute('size'); if ($attr->usesSource()) { echo $color_id = $attr->getSource()->getOptionId("10"); }
    – Lasantha
    Commented Feb 24, 2017 at 6:10
  • how can you get the color id from size attribute? Commented Feb 24, 2017 at 6:22

1 Answer 1


Find below code

$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

For product

  • This is working .How can I get product base attribute. labels and values.
    – Lasantha
    Commented Feb 24, 2017 at 6:31
  • @ssk8323 find updated code Commented Feb 24, 2017 at 6:34
  • I customized and found a solution using following method Its works for me, thanks for your time and help, $attr = $product->getResource()->getAttribute($attrname); if ($attr->usesSource()) { return $color_id = $attr->getSource()->getOptionId($attrvalue); }
    – Lasantha
    Commented Feb 24, 2017 at 6:49

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.