Question

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

Was it helpful?

Solution

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.

OTHER TIPS

You can reload it with section.

Create section.xml in your module etc/frontend/

<?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="your/url/here">
        <section name="checkout-data"/>
</action>

Second option is through js

require(['jquery','Magento_Customer/js/customer-data'], function ($,customerData) {
        var sections = ['checkout-data'];
        customerData.invalidate(sections);
        customerData.reload(sections, true);

 });

You need to keep below section in your sections.xml file,

<action name="referralcredit/loadsummary/index">
        <section name="checkout-data"/>
</action>
define([
    'uiComponent',
    'jquery',
    'Magento_Checkout/js/model/quote',
    'ko',
    'Magento_Checkout/js/model/cart/totals-processor/default',
], function (Component, $, quote, ko, totalsDefaultProvider) {
    'use strict';
    return Component.extend({
        updateTaxValue:function(){
            //Start Custom Changes//
                quote.shippingMethod.subscribe(function () {
                    console.log("1");
                    totalsDefaultProvider.estimateTotals(quote.shippingAddress());
                });

                quote.billingAddress.subscribe(function () {
                    var type = quote.billingAddress().getType();
                    if (quote.isVirtual()) {
                        // update totals block when estimated address was set
                        totalsProcessors['default'] = totalsDefaultProvider;
                        totalsProcessors[type] ?
                            totalsProcessors[type].estimateTotals(quote.billingAddress()) :
                            totalsProcessors['default'].estimateTotals(quote.billingAddress());
                    }
                });
            //End Custom Changes//
        }
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top