[Magento 2] Adding product attributes to quote items getProduct function

When calling the function $block->getProduct() in a quote item in the cart page, Magento 2 will return the product and its basic attributes. The attributes that can be retrieved from the product when calling this function in a quote_item page can be found in the file vendor/magento/module-sales/etc/catalog_attributes.xml.

From your own module, you can create the file Vendor/Module/etc/catalog_attributes.xml and add the attributes you need:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="your_attribute_code1"/>
        <attribute name="your_attribute_code2"/>
    </group>
</config>

Leave a Reply

Your email address will not be published.