Magento2 Order Summary Section – How to Reload

checkoutmagento2magento2.2.2ordersPHP

I have some custom discount applied through custom ajax after ajax completion, I want to reload Order summary section on checkout page.

mysite.com/rest/default/V1/carts/mine/shipping-information

After debugging I observe that The above link when called the Order Summary section reloads but, How to reload it with my custom ajax request ?

=> section.xml :

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">

<action name="http://127.0.0.1/grocebee_dev/loadSummary">
        <section name="checkout-data"/>
</action>

ajax request

// baseurl return 'http://127.0.0.1/grocebee_dev'
    var newUrl = baseUrl+'/loadSummary';

                                $.ajax({
                                    type : 'post',
                                    url : newUrl,
                                    success:function(newData)
                                    {
                                        console.log(newData);
                                    }
                                });

But it shows 404 error

Best Answer

You can use 'Magento_Checkout/js/action/get-totals' to update the order summary .

Please check this code

define([
    'uiComponent',
    'jquery',
    'Magento_Checkout/js/action/get-totals',
    'ko',

], function (Component, $, getTotalsAction, ko) {
    'use strict';
    return Component.extend({
        validatevat:function(){
            var newUrl = baseUrl+'/loadSummary';
            $.ajax({
                url: newUrl,

                data:  {
                },
                type: "post",
                cache: false,
                success: function (data) {
                    var deferred = $.Deferred();
                    getTotalsAction([], deferred); //this will reload the order summary section I have used it in my custom module 
                }
            });
        }
    });
});

Hope this helps.