Magento 2 – How to Get Subtotal and Grand total in Checkout Page using Knockout JS

In this post I am going to explain how to get subtotal and grand total in checkout page using knockout js in Magento 2.

Here, I am using my custom module – Ht_Mymodule

In order to display content on checkout page, first we need to add block in checkout_index_index.xml file.

So create layout file checkout_index_index.xml in your module at below path and add below code.

File Path: app/code/Ht/Mymodule/view/frontend/layout/checkout_index_index.xml

In this file you can see:

– Block class: Ht\Mymodule\Block\Checkout\Quoteinfo
– Block template: Ht_Mymodule::checkout/quoteinfo.phtml
– Knockout js file: Ht_Mymodule/js/view/checkout/quoteinfo.js
– The template file of knockout js: Ht_Mymodule/checkout/quoteinfo.html

Now we are going to create all above files.

1. Block class: Quoteinfo.php

File Path: app/code/Ht/Mymodule/Block/Checkout/Quoteinfo.php

2. Block template: quoteinfo.phtml

File Path: app/code/Ht/Mymodule/view/frontend/templates/checkout/quoteinfo.phtml

3. Knockout js file: quoteinfo.js

File Path: app/code/Ht/Mymodule/view/frontend/web/js/view/checkout/quoteinfo.js

4. The template file of knockout js: quoteinfo.html

File Path: app/code/Ht/Mymodule/view/frontend/web/template/checkout/quoteinfo.html

Now, Run upgrade and deploy commands and check for the result on checkout page.

1 Comment

  1. Excellent blog! I really appreciated to you on this quality work.

Leave a Reply

Your email address will not be published. Required fields are marked *