I am migrating Magento 1.9 to Magento 2.2 and I need to know how to display the Delivery Term attribute that each product has in the cart. Someone could help me? because I've tried several options but I can not get any of them to work for me.
Solved! Go to Solution.
There is new concept in Magento 2 to create catalog_attributes.xml file in which you can define your custom attribute value using quote_item group section.
You Just need to create app/code/Vendor/Modulename/etc/catalog_attributes.xml with below content:
<?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="custom_attribute_name"/>
</group>
</config>
You can get custom_attribute_name in the template file withcart/item/default.phtml
below code.
echo $_item->getProduct()->getData('custom_attribute_name');
Clear Cache and check.
There is new concept in Magento 2 to create catalog_attributes.xml file in which you can define your custom attribute value using quote_item group section.
You Just need to create app/code/Vendor/Modulename/etc/catalog_attributes.xml with below content:
<?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="custom_attribute_name"/>
</group>
</config>
You can get custom_attribute_name in the template file withcart/item/default.phtml
below code.
echo $_item->getProduct()->getData('custom_attribute_name');
Clear Cache and check.
If i do it with the attribute SKU it shows me the value well, but if I do it with the attribute tiempo_envio that is defined for each product and indicates the delivery time, it does not show me anything.
Thank so much. It´s ok now
You can also use
echo $_item->getProduct()->getCustomAttributeName();
Its giving the Error!
Exception #0 (Exception): Notice: Undefined variable: _item in