Add Product Attribute to Quote Item Product

Trying to get a product attribute from the quote item using the getProduct() function but is not there? Let's see how you can easily add it!

The most common mistake in that case is to get the product Id from the quote item and then load the whole product object to get the attribute you need. But as we have seen already on a previous blog post there is another way to do that. All you need is to define in the catalog_attributes.xml file the product attributes you want to be accessible from the product of the quote item.

Just create a file under app/code/<Vendor>/<Module>/etc/catalog_attributes.xml and add the following code. Example of adding the product manufacturer attribute.

In you code and supposing that you have already gotten the quoteItem object then to access the product manufacturer attribute in frontend, you just need to call

$quoteItem->getProduct()->getAttributeText('manufacturer');

Feel free to share this post and ask your questions in the comments below.

Till next time!