2

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

  • what is your frontname for routes.xml of your module? – Rakesh Jesadiya Apr 4 '18 at 9:28
  • frontname="referralcredit" – Abdullah Shahid Apr 4 '18 at 9:29
3

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.

2

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

 });
  • What to put in 'your/url/here' – Abdullah Shahid Apr 4 '18 at 8:03
  • It is your ajax request url. – Qaisar Satti Apr 4 '18 at 8:28
  • I updated my question please review – Abdullah Shahid Apr 4 '18 at 9:15
  • @BunnyXudot <action name="grocebee_dev/loadSummary/index"> use this dear. – Qaisar Satti 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 – Abdullah Shahid 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>
  • it returns 200 status now but Order Summary section did not reload – Abdullah Shahid Apr 4 '18 at 9:38
  • check my update you have to keep loadsummary instead of customer – Rakesh Jesadiya Apr 4 '18 at 9:40
  • but there is no folder like loadSummary in my controller so it will give me 404 – Abdullah Shahid Apr 4 '18 at 9:43
  • whats your actuall action url? – Rakesh Jesadiya 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. – Abdullah Shahid Apr 4 '18 at 9:46

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.