How to get attribute option label in Magento with different store view

In Magento customization, sometimes you may want to get the value of attribute’s option. In below example I will show you how to do it.

Assuming that there is an attribute named “dropdown_field” and contains 4 options label: “Option 1″, “Option 2″, “Option 3″, “Option 4″. The codes below get the option label which is set in product:

// get product Model
$_product = Mage::getModel('catalog/product');

// get the attribute object
$dropdownAttributeObj = $_product->getResource()->getAttribute("dropdown_field");

// if input type for this attribute is dropdown or multi-select
if ($dropdownAttributeObj->usesSource()) {
      // get the option label
      $dropdown_option_label = $dropdownAttributeObj->getSource()->getOptionText($_product->getData('dropdown_field'));
}

How about multiple websites / store / store view? No worry, it’s automatically get the correct label for you; or you can use $this->__() translation method in your template files.

Happy Magento’ing ~

Related Posts Plugin for WordPress, Blogger...

I hope you have enjoyed this post, be sure to subscribe to my rss feed by click the subscribe button at the top.

Good Luck!

Be Sure to Subscribe to our feed or follow us on twitter to get the latest updates/patches
End of Article, Thanks for reading.
You can leave a response, or trackback from your own site.

6 Responses to “How to get attribute option label in Magento with different store view”

  1. dinesh says:

    thank u very much………. it's working fine………..

  2. Michle Jackson says:

    Thank you

  3. RICHIE says:

    Really great article, worth the read many times over !

  4. sunil rana says:

    I found good link on getting product attributes values and labels. It may help you.
    http://www.phptechi.com/getting-product-attribute

  5. Ivn says:

    How can we get Attribute Labels like (name, telephone, email, Country, City) in a drop down list for Customers?

  6. Magento Core says:

    "How about multiple websites / store / store view? No worry, it’s automatically get the correct label for you"

    NO !!!!
    NOT automatically..You were lucky.
    It should be as below.
    $field_code = Mage::getModel('catalog/product')->setStoreId($product->getStoreId())->getData('dropdown_field');

Leave a Reply