1

For shopping cart, I added the following code to

app/design/frontend/VendorName/custom/Magento_checkout/templates/cart/item/default.phtml

<?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getDescription(), 'description') ?>

But it is not displaying the description. How to add product description to shopping cart and checkout page?

9
  • I got the description for product in shopping cart page with the following code. What template to override for checkout page? $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productDescription = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId())->getDescription(); echo $productDescription;
    – Karts
    Jul 31, 2017 at 11:01
  • Let me know whether you have custom theme? Jul 31, 2017 at 11:38
  • Here i am considering Smartwave/porto is the theme, Hence place <?php echo $_item->getProduct()->getData('description');?>in your custom theme Jul 31, 2017 at 11:42
  • I just saw your suggestion. Thanks for the reply but I got the description on checkout page working partially with @Sejal's suggestion on magento.stackexchange.com/questions/163848/…. Currently it is displaying the description after the page loads and then the order summary part is getting refreshed and the description is no longer seen.Would you know what the issue is n how to fix it? I don't have the points to comment on sejal's answer.
    – Karts
    Jul 31, 2017 at 13:39

3 Answers 3

4

Please follow the below steps:

Step 1: description is an default attribute for the product hence call the same from your custom module as shown below.

/app/etc/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="description"/>
 </group>
</config>

Step 2: Go to below path /app/design/frontend/Smartwave/porto/Magento_Checkout/templates/cart/item/default.phtml

use like this <?php echo $_item->getProduct()->getData('description');?>

Step 3: Clear cache and page cache and go to frontend & check the same.

1

Go to below path

/app/design/frontend/Smartwave/porto/Magento_Checkout/templates/cart/item/default.phtml

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

 $productDescription = $objectManager->get('Magento\Catalog\Model\Product')->load($‌​_item->getProductId(‌​))->getDescription()‌​; 
echo $productDescription;
0

It's too easy to get product fields on the checkout cart page with the object manager

There are two ways to get details

  1. Using Object Manager
  2. Using the override method

Here I'm showing you a direct method from the Object manager

  1. Please go to below path in your root magento 2
app/design/frontend/VendorName/custom/Magento_checkout/templates/cart/item/default.phtml
  1. Using the below the line you can get the description of the product
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productDescription = $objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId())->getDescription();

If you want to get any field of the product than just replace with the Description in the above code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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