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 the checkout cart in Magento 2, to be specific, Magento 2 quote item additional data, by following this post.
Or, you can GET THE EXTENSION NOW >>> Magento 2 Quote Extension
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 – The Magento 2 quote item additional data.
If you have any problems with Magento 2 quote item additional data or need our professional service, please email us support@bsscommerce.com.
About BSS Commerce:
We are one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bring high-quality products and services to optimize our business effectively. Let us know about your problems. We are willing to support you every time.