7

We are sporadically facing the following problem when on /checkout/cart/. As an effect, clicking on "Proceed to checkout" does not work.

We believe the proceeding is not working because of the following javascript error being logged:

enter image description here

The problem was reproducible on two machines, even after reloading the full page. But now is no longer.

I had a look at the code in line 90

    getFromServer: function (sectionNames, forceNewSectionTimestamp) {
        var parameters;

        sectionNames = sectionConfig.filterClientSideSections(sectionNames);
        parameters = _.isArray(sectionNames) ? {
            sections: sectionNames.join(',')
        } : [];
        parameters['force_new_section_timestamp'] = forceNewSectionTimestamp;

/** Line 90 **/ return $.getJSON(options.sectionLoadUrl, parameters).fail(function (jqXHR) {
            throw new Error(jqXHR);
        });
    }
};

So obviously the options are not loaded somehow -- but they are in the constructor, so how can this be?

Happy for any help.

EDIT

I traced the problem down to a module where we interact with customer-data.

We have the following code:

define([
    'jquery',
    'Magento_Customer/js/model/authentication-popup',
    'Magento_Customer/js/customer-data'
], function ($, authenticationPopup, customerData) {

    customerData.reload(['minvalue'],true).done(function(){

In some cases this code seems to be called before the constructor

vendor/magento/module-customer/view/frontend/web/js/customer-data.js:366


    'Magento_Customer/js/customer-data': function (settings) {
        options = settings;
        invalidateCacheBySessionTimeOut(settings);
        invalidateCacheByCloseCookieSession();
        customerData.init();
    }

Question: How can I force my code to be run, after the constructor was run?

  • 1
    Maybe it's an timing problem? – Daniel May 3 at 7:49
  • 2
  • @alex Can you post the full JS trace error stack ? – obscure May 3 at 9:02
  • @obscure I can't because I cannot reproduce – Alex May 3 at 9:36
  • @TuyenNguyen We made a Magento Update from 2.2.6 to 2.2.8 recently ... So if I understand you link correctly, this happens for people who viewed the 2.2.6 shop and no the 2.2.8 shop? The comment suggests to clear the browser cache and local storage --- but that would need custom code, right? Magento does not take care of that? – Alex May 3 at 9:42
2

Usually the customer-data.js errors are caused by browser local storage issues after disabling modules that add sections to the customer data object (from my experience).

So 1 customer (pc) might see the error but others won't.

The solution in my case (although a bit different than yours) was to clear the browser local storage which can be done through the browser debugging tools on the storage tab in Firefox or the application tab in Chrome. And clear Magento's cache.

If that doesn't work, I would check any recently installed modules that modify the customer-data object or Magento functionality which is connected to the customer (i.e. try disabling the custom modules 1 by 1).

  • Thanks. Problem is still that I can not reproduce it. so disabling modules 1 by 1 etc. does not help, cause I have no way to verify if it works after disabling a module – Alex May 3 at 9:42
  • 1
    Without being able to reproduce the issue, no suggestion/solution offered can truely be tested... so it might have been a temporary problem caused by some external factor (which you can't account for) or a specific combination of customer/user actions. I would suggest first being able to reproduce the issue before attempting to fix it. – Lez May 3 at 10:25
  • 1
    You could try to reproduce it by clearing all session and local storage, downgrading back to 2.2.6, going to /checkout/cart and click on the "Proceed to Checkout" then upgrading again and see if you get the error again. It is quite some effort but might help you verifying it is an issue with local storage. – Daniel May 3 at 10:43
  • @Lez: The Question is asking about how I can reproduce this :-) – Alex May 3 at 14:47
  • 1
    @Alex hehe I totally missed that in the heading... although I would never try to reproduce this personally (since I had many headaches from debugging issues like these when I started with M2), but if you want to "torture" yourself, I would go with Daniel's answer. But if I was to take an educated guess, the issue was most probably caused by the difference of customer sections being loaded by new or adjusted modules after upgrading to M2.2.8 – Lez May 3 at 15:14
2
+500

As mentioned in this issue comment it is likely that this error is caused by an local storage issue after you upgrade from 2.2.6 to 2.2.8.

In order to reproduce your error you could try the following steps:

  1. In your browser delete all local data of your website
  2. Downgrade Magento back to 2.2.6
  3. Visit the cart and proceed to checkout
  4. Upgrade your Magento again
  5. Go to the cart again and try proceeding to checkout

I think this is quite some effort but might help you to reproduce and verify whether this error is caused by the local storage or not.

  • I tried it but forgot step 1... Will try again I think – Alex May 4 at 15:34
1

We tracked this down to a custom component which overwrites

vendor/magento/module-checkout/view/frontend/web/js/proceed-to-checkout.js

return function (config, element) {
    ### basically our change
    customerData.reload(['minvalue'], true);
    var minOrderValue = customerData.get('minvalue');
    ## end of our changee
    $(element).click(function (event) {
        var cart = customerData.get('cart'),
            customer = customerData.get('customer');

        ## do something with minOrderValue here

        event.preventDefault();

        if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
            authenticationPopup.showModal();

            return false;
        }
        $(element).attr('disabled', true);
        location.href = config.checkoutUrl;
    });

};

This seems to cause very rare but ugly race conditions. customerData.reload can be called, even the constructor of customerData did not run.

We now simply moved

 customerData.reload(['minvalue'], true);

into the click handler, so it definitely should be called a bit later.

But I feel this is very ugly. The constructor is called by Magento's main.js and I guess if somebody clicks fast enough, it still does not work properly.

But as the core is doing it the same, this should work; and at least the user can click again (which they couldn't before, because the initialization failed)

We have a javascript error logger running on the system, and will know after some days, if the error appeared again.

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.