cancel
Showing results for 
Search instead for 
Did you mean: 

Show SKU on checkout

Highlighted

Show SKU on checkout

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:

<extension_attributes for="Magento\Quote\Api\Data\TotalsItemInterface">
        <attribute code="sku" type="string" />
 </extension_attributes>

In etc / di.xml I enter information about the new plugin:

<type name="">
        <plugin name="" type=""/>
    </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!

8 REPLIES

Re: Show SKU on checkout

Hello,

 

Magento already adding Sku into checkout json

 

so you need to make change into html file

 

vendor\magento\module-checkout\view\frontend\web\template\summary\item\details.html

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.

Re: Show SKU on checkout

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.

Re: Show SKU on checkout

Hello @prudnikov

 

window.checkoutConfig.quoteItemData already contain item info, why you want to add one more time.

 

@prudnikov if it will help you then mark as solution.

Re: Show SKU on checkout

You need to follow below link to show sku on order summary checkout page,

show sku on order summary

Thanks.

If Issue Solved, Click Kudos/Accept As solutions.
More info visit Blogs

Re: Show SKU on checkout

My module works in such a way that I need to add the SKU field to the window.checkoutConfig.totalsData object, in "items" array. For this, I need to make a plugin that will add the SKU field to the interface:

"Magento\Quote\Api\Data\TotalsItemInterface"

like I sad in first post

Re: Show SKU on checkout

Hello @aliaksandr_prudnikau

 

If want to directly add into window.checkoutConfig.totalsData not in extension attribute then create plugin for Magento\Checkout\Model\DefaultConfigProvider .

 

You need to create afterPlugin for getConfig method

 

Hope it will help you.

 

 

Re: Show SKU on checkout

Can you tell me the code for this method (afterGetConfig)? I need to add a SKU to the .totalsData object. Thanks!

Re: Show SKU on checkout

Hello  @aliaksandr_prudnikau

 

app/code/{namespace}/{module}/etc/di.xml

 

 

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\DefaultConfigProvider">
        <plugin name="config_plugin" type="namespace\module\Plugin\DefaultConfigProvider" sortOrder="10" disabled="false"  />
    </type>
</config>

 Then After create namespace\module\Plugin\DefaultConfigProvider.php

 

public function aftergetConfig($subject, $result)
	{

		$totalData = $result['totalsData'];
$totalData['items'] ='11'; // get items for it // hope you will do it }

 If above code work then mark as solution.