2

I need to display a few attributes in the cart page. How can i accomplish that? enter image description here

  • You Have to create attribute and assign to that product @Athbi – Learing_Coder Jul 15 '17 at 8:17
  • Look at these below link for clarity @Athbi – Learing_Coder Jul 15 '17 at 8:19
  • Hi @Athbi Please use the below code and get back with your comments thanks – Nagaraju K Jul 15 '17 at 8:49
  • Please accept the answer so that it will useful for the other developers thanks – Nagaraju K Jul 15 '17 at 9:05
  • Please comment me I u need assistance thanks – Nagaraju K Jul 16 '17 at 5:33
10

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.

| improve this answer | |
  • 1
    Where exactly do I place the catalog_attributes.xml do I need to create a module? – gabehou Oct 3 '17 at 18:24
  • In your custom module. If not plz create. Thanks – Nagaraju K Oct 4 '17 at 0:33
  • i am able to get value but it in integer that is option how can i get label or text value here ? – kushal Oct 9 '19 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.