>Add More Product Information on Checkout Cart in Magento 2

Add More Product Information on Checkout Cart in Magento 2

Many store owners and administrations are always looking for new features in Magento 2 that would help them easily customize or manage products and products’ information in their online store.

So today we will guide how to add more product information on checkout cart in Magento 2 by following this post.

Step 1: Create file etc\frontend\di.xml

This file will declare plugin which interferes in class Magento\Catalog\Helper\Product\Configuration and add custom information as a custom option of this product.

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Helper\Product\Configuration">
          <plugin name="bss-add-to-product-quote-coap" type="Bss\ModuleName\Plugin\QuotePlugin" sortOrder="1"/>
    </type>
</config>

Step 2: Create file Plugin\QuotePlugin.php

This class is a plugin which we use to add new custom information to product in cart.

<?php
namespace Bss\ModuleName\Plugin;
class QuotePlugin
{
    /**
    * @param \Magento\Catalog\Helper\Product\Configuration $subject
    * @param callable $proceed
    * @param CatalogItemInterface $item
    * @return array
    */
    public function aroundGetCustomOptions(
            \Magento\Catalog\Helper\Product\Configuration $subject,
            callable $proceed,
            \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
    ) {
        $result = $proceed($item);
        $result[] = [
            'label' => 'Custom Label',
            'value' => 'Custom Value'
        ];
        return $result;
    }
}

In this class, the function aroundGetCustomOptions() is a plugin which we use to customize result of default function: Magento\Catalog\Helper\Product\Configuration::getCustomOptions().

We use plugin around method so we can get post data, product data v.v… by using this code: $requestData = $item->getBuyRequest();.

The result

Finally, we have the results as below images after following above simple steps.


If you have any problems or need our professional service, please email us support@bsscommerce.com. You can also find the right solution in our best-in-class https://bsscommerce.com/magento-2-extensions.html

< Previous Post
Next Post >