Menu Close
    Hire us Request quote Reading list Switch to dark mode

    How to add more product information on checkout cart in magento2

    How to add more product information on checkout cart in magento2 – IF there is a need to add some more information on per products in checkout cart page in magento2 and have difficulty to implement it then the solution is here. You can easily add custom information to cart products by following this post. For this just need to do some easy changes here-

    1. Step 1 – Call your block and template file to checkout_cart_index.xml inside your magento2 module layout folder.
      <?xml version="1.0"?>
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
          <body>
              <referenceContainer name="additional.product.info">
                  <block class="Webkul\Grid\Block\AdditionalProInfo" name="cart_item_addional_info" template="Webkul_Grid::checkout/cart/item/additionalinfo.phtml" cacheable="false"/>
              </referenceContainer>
          </body>
      </page>
    2. Step 2 – Now Prepare the block file –
      namespace Webkul\Grid\Block;
      
      /**
       * AdditionalProInfo
       */
      class AdditionalProInfo extends \Magento\Framework\View\Element\Template
      {
          /**
           * @param \Magento\Framework\View\Element\Template\Context $context
           * @param array $data
          */
          public function __construct(
              \Magento\Framework\View\Element\Template\Context $context,
              array $data = []
          ) {
              parent::__construct($context, $data);
          }
      
          /**
           * @return void
           */
          protected function _construct()
          {
              parent::_construct();
          }
      
          /**
           * @return $this
           */
          protected function _prepareLayout()
          {
              parent::_prepareLayout();
          }
      
          /**
           * @return additional information data
           */
          public function getAdditionalData()
          {
              // Do your code here
              return "Additional Informations";
          }
      }
    3. Step 3 – Prepare additional information template file additionalinfo.phtml –
      $_item = $block->getItem();
      $product = $_item->getProduct(); // Get cart product details
      $additional_data = $block->getAdditionalData(); // Get cart product additionl details defined in block page
      ?>
      <div>
          <span><?php echo $additional_data?></span>
      </div>
    4. Now you will see the cart page like –

    So in this way you can display additional product information to your cart page.

    . . .

    Comments (9)

    Add Your Comment

  • sethhu
    i copy you file and change the namespace,but it’s not working for me,the error is Notice: Undefined index: class in /var/www/html/magento/vendor/magento/framework/View/Layout/Generator/Block.php on line 213.but use your module,it’s working… XD….
  • Michał Michalski
    Don’t know where should I put those files.
    • Pooja Sahu
      Hello Michal,
      In the given post we are creating a module Webkul_Grid, and here we explained if there is need to add some additional info per item in checkout cart page then how we can add this. So for this we are creating a file checkout_cart_index.xml in path Webkul/Grid/view/frontend/layout/ and then creating a block file AdditionalProInfo.php in path WebkulGridBlockAdditionalProInfo and a template file additionalinfo.phtml in path Webkul/Grid/view/frontend/template .
      Here Vendor name – Webkul, Module name – Grid
      Hope now you understand the location of files. If still have issue please feel free to ask.
      Thanks!
      • Michał Michalski
        Thank you for reply. It seems that I did everything correctly. So why do I get this error:

        Notice: Undefined index: class in /home/xxxxxx/NetBeansProjects/meblomat/vendor/magento/framework/View/Layout/Generator/Block.php on line 213
        #0 /home/xxxxxxx/NetBeansProjects/meblomat/vendor/magento/framework/View/Layout/Generator/Block.php(213): MagentoFrameworkAppErrorHandler->handler(8, ‘Undefined index…’, ‘/home/xxxxxx/N…’, 213, Array)

        • Pooja Sahu
          Hello Michal,
          It looks like there is some error in your module’s block file, so please debug your block file properly.
          Thanks!
          • Michał Michalski
            I really doubt that I made mistake. Here is my code:

            <?php
            namespace CodemakeConfiguratorFurnitureBlock;

            /**
            * AdditionalProInfo
            */
            class AdditionalProInfo extends MagentoFrameworkViewElementTemplate
            {
            /**
            * @param MagentoFrameworkViewElementTemplateContext $context
            * @param array $data
            */
            public function __construct(
            MagentoFrameworkViewElementTemplateContext $context,
            array $data = []
            ) {
            parent::__construct($context, $data);
            }

            /**
            * @return $this
            */
            protected function _prepareLayout()
            {
            parent::_prepareLayout();
            }

            /**
            * @return additional information data
            */
            public function getAdditionalData()
            {
            // Do your code here
            return "Additional Informations";
            }
            }

          • Pooja Sahu
            Hello Michal,
            Please follow the module https://github.com/webkul/magento2_cartPageAdditionalInfo .
            Thanks!
          • Michał Michalski
            Although I can’t use this module in my vendor directory(yes I have changed namespaces). I suppose I have a bug somewhere in my code. So I will use it in a separate vendor.
            Thank you very much.
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close