cancel
Showing results for 
Search instead for 
Did you mean: 

Show SKU on checkout

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!

4 REPLIES
Magento
PHP

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.

Highlighted

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.

Magento
PHP

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.

Magento
E-Commerce

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.