4

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

2
  • what is your frontname for routes.xml of your module? Apr 4 '18 at 9:28
  • frontname="referralcredit" Apr 4 '18 at 9:29
5

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.

3
  • 1
    Try this but give an error in console 'TypeError: getTotalsAction is not a function' prntscr.com/p7k9ed Sep 18 '19 at 4:52
  • @ChiragGondaliya can you please add your js code Sep 18 '19 at 7:01
  • Don't forget to define 'Magento_Checkout/js/action/get-totals', as getTotalsAction May 18 at 17:45
3

You can reload it with section.

Create sections.xml in your module etc/frontend/ folder.

<?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);

 });
13
  • What to put in 'your/url/here' Apr 4 '18 at 8:03
  • It is your ajax request url. Apr 4 '18 at 8:28
  • I updated my question please review Apr 4 '18 at 9:15
  • @BunnyXudot <action name="grocebee_dev/loadSummary/index"> use this dear. Apr 4 '18 at 9:28
  • I have use it like <action name="frontname/controllerfolder/index"> and it's look like <action name="referralcredit/customer/index"> and it returns 200 now but section did not loads Apr 4 '18 at 9:37
0

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

<action name="referralcredit/loadsummary/index">
        <section name="checkout-data"/>
</action>
8
  • it returns 200 status now but Order Summary section did not reload Apr 4 '18 at 9:38
  • check my update you have to keep loadsummary instead of customer Apr 4 '18 at 9:40
  • but there is no folder like loadSummary in my controller so it will give me 404 Apr 4 '18 at 9:43
  • whats your actuall action url? Apr 4 '18 at 9:44
  • Let me clear i have a checkbox on checkout page from which i want to reload order summary section when checkbox checked So what I have to do Sir. Apr 4 '18 at 9:46
0
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//
        }
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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