Question

I am updating the cart total price dynamically without page reload. I wrote code in js file

require(
[
    'Magento_Checkout/js/model/cart/cache',
    'Magento_Checkout/js/model/cart/totals-processor/default',
    'Magento_Checkout/js/model/quote'
],
function (cartCache, totalsProcessor, quote) {
    var form = jQuery('#discount-coupon-form');
    jQuery.ajax(
        {
            type: "POST",
            url: form.attr('action'),
            data: form.serialize(),
            success: function (response) {
                console.log(response);
                cartCache.clear('cartVersion');
                totalsProcessor.estimateTotals(quote.shippingAddress());
            }
        }
    );
 }
)();

But i get this error in my chrome console,

customer-data.js:89 Uncaught TypeError: Cannot read property 'sectionLoadUrl' of undefined
at Object.getFromServer (customer-data.js:89)
at Object.reload (customer-data.js:353)
at totals.js:26
at Object.execCb (require.js:1650)
at Module.check (require.js:866)
at Module.<anonymous> (require.js:1113)
at require.js:132
at require.js:1156
at each (require.js:57)
at Module.emit (require.js:1155)

How to fix this.

Was it helpful?

Solution

Fixed this using window on load:

    <script type="text/javascript">
require([
        'jquery'
    ],
    function($) {
        $(window).on("load", function() {
            require([
                'Magento_Checkout/js/model/cart/totals-processor/default',
                'Magento_Customer/js/customer-data',
                'Magento_Checkout/js/model/quote',
                'Magento_Checkout/js/model/shipping-rate-processor/new-address',
                'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
                'Magento_Checkout/js/model/shipping-rate-registry'
            ], function(defaultTotal, customerData, quote, defaultProcessor, customerAddressProcessor, rateRegistry) {
                $(document).ready(function() {

                    /** Do your code here */
                });

            });
        });
    });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top