Magento: $_product->getData() VS. $_product->getAttributeName()

There are two main ways of displaying product attributes on the product list, and the product view. Let’s say for this example that our attribute code is ‘awesome_dude’. The two ways you’d expect to see this attribute displayed are:

<?php echo $_product->getData('awesome_dude') ?>
<?php echo $_product->getAwesomeDude() ?>

Both of these produce the same result. However, they have somewhat significant differences:


In most cases, this is the method you should use. Of the two options, this one is actually faster and more efficient. If you have no need to modify the output, and just want to display the value, use getData(). However, there are attributes that may not work properly with getData() such as the product price. Though I haven’t tested it yet, getData(‘price’) will most likely end up producing different results than getPrice().


You should really only use this method if you are needing to override the method in your block to add functionality to how the data is displayed/formatted. Magento needs to take some additional steps in rendering the data when you use this method, so it is a slightly slower process than displaying data using getData(). So, by using $_product->getAwesomeDude(), I am able to add a function to the product view block for example to modify the data before it is output to the screen:

public function getAwesomeDude()
  // code to do something with the data
  return $yournewdata;
This entry was posted in Magento. Bookmark the permalink.

5 Responses to Magento: $_product->getData() VS. $_product->getAttributeName()

  1. Pingback: Magento: Customizing Store | Ricardo Malla's Blog

  2. The question is, how do you load an attribute into a product collection.
    I’m having trouble doing that in Magento 1.5

    • Josh Pratt says:

      Have you tried this? addAttributeToSelect(“*”) when getting the collection? That should get all available attributes.

  3. Gorkyman says:

    The better question here is, which one should one use when getting system attributes from Magento, because getPrice() and getData(‘price’) could return different result. So be careful when using getData for system attributes.

    Anyway, keep up with good articles! Community appreciate it :)

    • Josh Pratt says:

      Gorkyman – Yes. You bring up a good point that I failed to mention. I will add that to the article. Thanks!