Magento 2 – How to Show SKU in Order Summary

checkoutmagento2order-summary

I want to display sku in order summmary after product name.

I've created pluging which will called afterGetConfig to modified totalsData you can see below code for it.

class ConfigProviderPlugin extends \Magento\Framework\Model\AbstractModel
{
    public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
    {
        $items = $result['totalsData']['items'];

        for($i=0;$i<count($items);$i++){
        $items[$i]['sku'] = "dgd";

        }


        return $result;
    }
}

Then in detail.html i've added

<div class="details-sku">
                <span class="label"><!-- ko i18n: 'Sku' --><!-- /ko --></span>
                <span class="value" data-bind="text: $parent.sku"></span>
            </div>

But i can't see sku value there. i can only see lable. see below screenshot.
enter image description here

Best Answer

Override one template (simplification of Joey's answer). Bind directly to window object.checkoutConfig.quoteItemData object.

app/design/frontend/MyCustomTheme/default/Magento_Checkout/web/template/summary/item/details.html

<!-- ko foreach: window.checkoutConfig.quoteItemData -->
    <!-- ko if: item_id == $parents[1].item_id -->
        <span class="label" data-bind="i18n: 'SKU:'"></span>
        <!-- ko text: sku --><!-- /ko -->
    <!-- /ko -->
<!-- /ko -->

"===" cant be used in item_id == $parents[1].item_id so we use "=="