If you need only one product attribute value in Magento 2, you do not always need to load the entire product through a repository or collection. That can be wasteful in loops, cron jobs and imports.

Using the Product Resource Model, you can read an attribute directly by product ID, attribute code and store ID:

Magento does not load the entire product with all its attributes. Instead, it reads only the value you need. This can be useful when processing many products but retrieving only one attribute for each.

For a dropdown attribute such as manufacturer gibt getAttributeRawValue() , however, Magento returns the stored option ID rather than the visible label. To retrieve the label, resolve the option through the attribute’s source:

A stored option ID such as 42 can then become the visible label Bosch. The store ID also allows different attribute values and option labels for different store views.

Getting Product Attributes Without Loading the Entire Product
Need help implementing this solution, or still looking for a fix to your Magento problem? Get in touch and I will be happy to help with your project.
Tags: