Magento – Magento 2 – How to update grand total when shipping method is changed

checkoutgrand-totalmagento2shippingtotals

How can I update the grand total value when shipping method is changed to reflect new calculation?

When you change the shipping method here,

It must reflect the new calculation in TOTAL section.

Best Answer

I have the solution First of I found its easier to copy all the files into my theme directory.

  1. Create the theme directory

    http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-create.html

  2. Overwrite Checkout pages

    app/design/frontend/[Vendor]/[Theme]/Magento_Checkout/
    
  3. Copy web folder from default theme to your Magento_Checkout

    vendor/magento/module-checkout/view/frontend/Magento_Checkout/web
    
  4. Edit Magento_Checkout/web/template/summary/ (totals & grand-total) remove code below from both files.

    <!-- ko if: isDisplayed() -->
    <!-- /ko -->
    
  5. Edit Magento_Checkout/web/js/view/shipping.js

    Find selectShippingMethod Function line 215 and add

    setShippingInformationAction();
    

    Should look like this

    selectShippingMethod: function (shippingMethod) {
        selectShippingMethodAction(shippingMethod);
        checkoutData.setSelectedShippingRate(shippingMethod.carrier_code + '_' + shippingMethod.method_code);
        setShippingInformationAction();
        return true;
    },
    
  6. Run following commands

    php bin/magento setup:static-content:deploy
    php bin/magento indexer:reindex 
    php bin/magento cache:flush
    
Related Topic