Home > database >  Getting window.checkout.quoteData or store code are undefined error when cart item count updated usi
Getting window.checkout.quoteData or store code are undefined error when cart item count updated usi

Time:11-26

I have created a custom page with free text ordering functionality and called custom add to cart API to add items to the cart.

Once the item is added I need to update the cart item count with updated quantity. I tried to use

require([
    'jquery',
    'Magento_Checkout/js/action/get-totals'
], function ($, getTotalsAction) {
    'use strict';

    var deferred = $.Deferred();
    getTotalsAction([], deferred);
});

But It is throwing error: Uncaught TypeError: Cannot read property 'quoteData' of undefined at quote.js:34

And

url-builder.js:12 Uncaught TypeError: Cannot read property 'storeCode' of undefined at url-builder.js:12

Anything missing here?

I referred https://magento.stackexchange.com/questions/210517/error-javascript-define-magento2-window-checkout-quotedata-or-store-code-are-u which doesn't have any working solutions.

CodePudding user response:

The issue is that quoteData lives in window.checkoutConfig - this data will only be set on the checkout pages, you won't have many of required js the modules loaded on a custom page that set this data correctly.

this may be a useful read: https://www.yireo.com/blog/2017-08-20-do-not-depend-on-window-checkoutconfig

CodePudding user response:

I was able to achieve this for my scenario using the below code. It might help someone

    require([
       'Magento_Customer/js/customer-data'
    ], function (customerData) {
        var sections = ['cart'];
        customerData.invalidate(sections);
        customerData.reload(sections, true);
    });
  • Related