Magento: Load single product attribute vs. load entire product

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone

Let’s assume that as developer you are in following situation: You know a product id and you have to fetch single attribute value of a product which id you already know. For example let’s try to get color attribute of Magento product.

Question: How would you do it? Are you going to load the product or you would look for more efficient solutions in order to fetch only the attribute you are looking for?

Magento allows us to fetch product attribute in many ways and depending on the context we could choose one. I am definitely against loading entire product in case there are much more efficient solutions and the goal is to fetch single product attribute (not all product attributes).

I think that people choose the easy way because:

  • People read the first answer (which sometimes is not the most efficient) in StackOverflow but don’t check other answers.
  • There is a lack of Magento documentation.
  • Missing out of the box way how to accomplish the task.
  • There are many examples in Internet but they are not descriptive enough to explain what happens on background and how efficient they are.

Continue reading “Magento: Load single product attribute vs. load entire product”

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone