I need to display a few attributes in the cart page.
How can i accomplish that?
-
You Have to create attribute and assign to that product @Athbi– Learing_CoderJul 15, 2017 at 8:17
-
Look at these below link for clarity @Athbi– Learing_CoderJul 15, 2017 at 8:19
-
Hi @Athbi Please use the below code and get back with your comments thanks– Nagaraju KasaJul 15, 2017 at 8:49
-
Please accept the answer so that it will useful for the other developers thanks– Nagaraju KasaJul 15, 2017 at 9:05
-
Please comment me I u need assistance thanks– Nagaraju KasaJul 16, 2017 at 5:33
1 Answer
Please follow the below steps:
Assuming you have a module already created
Step 1: Create an attribute and assign to product Ex: discount_price (your product attribute). Call the same from your custom module as shown below:
app/code/NameSpace/ModuleName/etc/catalog_attributes.xml
<?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="discount_price"/>
</group>
</config>
Step 2: Go to below path: app/design/frontend/[themepackage]/[theme]/Magento_Checkout/templates/cart/item/default.phtml
Use like this <?php echo $_item->getProduct()->getData('discount_price');?>
Step 3: Clear cache and page cache and go to frontend & check the same.