I have added 2 custom attributes to product. I want to display them in the cart so how to proceed to get them in the cart page because i can't understand this form.phtml how it works?? I need a help please
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:
<?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.
You can add attribute in form as hidden text box. For example attribute color and value is red then you can add In this way you can add your all attributes on product form. When it is submitted all information is stored in quote object with name additionalOptions(not sure about attribute name but you can check for it). On cart page you can get those information and use them according to your requirement. I did here https://shingora.net/savannah-11535.html you can get some idea.
I found almost same post as per your requirement : How To Add Additional Options In Magento 2 Cart
Please check once and let me know if it helps you.