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-
- Step 1 – Call your block and template file to checkout_cart_index.xml inside your magento2 module layout folder.
12345678<?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> - Step 2 – Now Prepare the block file –
12345678910111213141516171819202122232425262728293031323334353637383940414243namespace 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 herereturn "Additional Informations";}} - Step 3 – Prepare additional information template file additionalinfo.phtml –
1234567$_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> - Now you will see the cart page like –
So in this way you can display additional product information to your cart page.
9 comments
https://uploads.disquscdn.com/images/f9c12370b7624d035476255a441ae41e2417e76ee912ea1e9a3f3396d810db95.png
use your module
https://uploads.disquscdn.com/images/f0adbe4091207749e0b14ed645d3f198fb2947bf56f740b01148a125d4c0ff43.png
it’s had load class sort order?
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!
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)
It looks like there is some error in your module’s block file, so please debug your block file properly.
Thanks!
<?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";
}
}
Please follow the module https://github.com/webkul/magento2_cartPageAdditionalInfo .
Thanks!
Thank you very much.