There is a custom extension for the checkout and I need to show the SKU of the product next to its name. To display information about the product, the functionality of the magento itself is used. When adding here: magento2/app/code/Magento/Quote/Api/Data/TotalsItemInterface.php following constant: const KEY_SKU = 'sku' and methods: public function getSku(); and public function setSku($sku); and when added to the model implementing this interface: magento2/app/code/Magento/Quote/Model/Cart/Totals/Item.php following methods: getSku() and setSku($sku), the SKU field appeared in the object storing the data about the goods in the cart. But since I can not edit magento files directly, I want to make a plugin for adding SKU to the interface and adding data to the object I need. As far as I understand, using the Extension Attribute, I can add a new attribute to the interface I need, but the data will not be picked up and added to the object I need. In my module, I created etc / extension_attributes.xml and added:
<attribute code="sku" type="string" />
In etc / di.xml I enter information about the new plugin:
<plugin name="" type=""/>
With fields 'plugin type' and 'name' it is clear, in the field 'type name' you need to enter the path to the class containing the method that we will "intercept" and here I have difficulties start: what should I do next, we need to intercept the method in which an array of data is formed for the object I need? How should I do it right? So, what is next? Help me understand how this plugin should work and how to actualize it. Thanks!
Magento already adding Sku into checkout json
so you need to make change into html file
In that file
<strong class="product-item-name" data-bind="text: $parent.name"></strong> Add below code <strong class="product-item-name" data-bind="text: $parent.sku"></strong>
first try into pub/static folder into your theme and check it.
If it will help you then mark as solution.
I'm working on a custom module, he has his own template, I need to add SKU value to it. Data on products in the cart are stored in the following object: window.checkoutConfig.totalsData.items (being on the page of the checkout, enter it into the console). This array does not contain SKU in native Magento 2.
You need to follow below link to show sku on order summary checkout page,