2

At checkout, I would like to have the checkout total price (display in the right corner in the order summary box) in order to display a message under the 'Order Total' according to his value (and according to the payment method selected). And I want to send the 'Order Total' information to my server too.

To send the Order Total, I use an observer (predispatchCheckout) and call the quote->getGrandTotal but the shipping cost is not included.

And for the displaying message, I create a component in checkout_index_index.html :

<item name="sidebar" xsi:type="array">
  <item name="children" xsi:type="array">
    <item name="summary" xsi:type="array">
      <item name="children" xsi:type="array">
        <item name="totals" xsi:type="array">
          <item name="children" xsi:type="array">
            <item name="myapp_total" xsi:type="array">
              <item name="component" xsi:type="string">MyApp_MyApp/js/view/checkout/summary/myapp_total</item>
            </item>
          </item>
        </item>
      </item>
    </item>
  </item>
</item>

And use the different classes to get the information:

[
        'jquery',
        'Magento_Checkout/js/view/summary/abstract-total',
        'Magento_Checkout/js/model/totals',
        'mage/url',
        'Magento_Checkout/js/checkout-data',
        'Magento_Checkout/js/model/quote'
    ],

But the total price is not the final one. There is no shipping cost included. And when I try to have it on the payment method selection, I don't have the right price the first time but when I change the payment method, this time, the shipping cost is here.

How can I manage it?

Maybe you have another idea to have the checkout total and display a message according to it.

Thank you for your help

2 Answers 2

1

Try this to get the grand total:

define([
    'jquery',
    'mage/translate',
    'Magento_Checkout/js/checkout-data',
    'Magento_Checkout/js/model/quote',
], function ($, $t, $checkoutData, $quote) {
    'use strict';

    return function (defaultView) {
        return defaultView.extend({
            {inYourCustomMethod}: function (data, event) {
                 let getGrandTotal = parseFloat($quote.totals()['grand_total']);
            }
        });
    };
});

Good Luck !

0

To get the order total (subtotal + shipping + tax) as the Order Total shows in the Order Summary, you should use Magento_Checkout/js/model/totals JavaScript component to get totals.getSegment('grand_total') as vendor/magento/module-checkout/view/frontend/web/js/view/estimation.js did:

define(['Magento_Checkout/js/model/totals'], function (totals) { ... }
/**
 * @return {Number}
 */
getGrandTotal: function () {
    if (totals.totals()) {
        return parseFloat(totals.getSegment('grand_total').value);
    }

    return 0;
},

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.