Magento: access a dropdown attribute value

Posted on in Development, How-Tos

In Magento it is possible to access a product’s attributes with a simple getter method. Let’s get the attribute test:

$_product->getTest()

This works as long as test is an attribute of type ‘text’. If the attribute is a dropdown, the method will just return the id of the selected option. To get the dropdown text, you need to call another method:

$_product->getAttributeText('test')
  • http://www.andreasacca.it andrea

    Great! many thanks! I was lookin for this! Tnks :)

  • http://www.andreasacca.it andrea

    Great! many thanks! I was lookin for this! Tnks :)

  • gurvinder

    thanxxx..:)

  • gurvinder

    thanxxx..:)

  • Vijay Thummar

    Cool. Thanks I have wasted so much time to find it.

    Thanks a lot.

    Vijay Thummar

  • Vijay Thummar

    Cool. Thanks I have wasted so much time to find it.

    Thanks a lot.

    Vijay Thummar

  • 8asic

    Thanks!

  • 8asic

    Thanks!

  • derStefan

    What a hero you are!!! But you need to get better ranked in google. I searched for hours ’til i found your life-saving (maybe just “job-saving”) post.

  • derStefan

    What a hero you are!!! But you need to get better ranked in google. I searched for hours ’til i found your life-saving (maybe just “job-saving”) post.

  • aaaaa

    thanks

  • aaaaa

    thanks

  • http://www.holzweg.com Tobias Strebitzer

    Nice, was looking for that too, and guess what: first entry @gogol.

    cu@work

  • http://www.holzweg.com Tobias Strebitzer

    Nice, was looking for that too, and guess what: first entry @gogol.

    cu@work

  • blAck PR

    thnx bro!

  • http://psdtomagento.net PSD to Magento

    hey, very nice, worked perfectly!

    Thanks!

  • http://pulse.yahoo.com/_MCPAJRE5K63INVRKNGWYYZ3JQE jerome dennis

    Thanks a lot Mathias. Its pretty handy.