Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error processor breaking checkout when a shipping request fails #580

Closed
wants to merge 1 commit into from

Conversation

sippsolutions
Copy link
Contributor

When a request fails during the shipping step (before the payment step) and does not return valid JSON, the error processor mixin fails because responseJSON is undefined:

error-processor-mixin.js:52 Uncaught TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')
    at Object.<anonymous> (error-processor-mixin.js:52:51)
    at Object.process (wrapper.js:78:32)
    at Object.<anonymous> (fee-service.js:64:32)
    at fire (jquery.js:3223:50)
    at Object.fireWith [as rejectWith] (jquery.js:3353:29)
    at done (jquery.js:9629:30)
    at XMLHttpRequest.<anonymous> (jquery.js:9888:37)

Additionally, quote.paymentMethod() is not given within shipping step, which also fails even if we fix the the first issue.

This currently results in the loading screen remaining visible and prevents checkout in some cases (especially with custom functionality in the shipping step).

This issue can be resolved with minimal changes by using optional chaining: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

@janteuber
Copy link
Contributor

Hello @sippsolutions ,

Thank you so much for creating the pull request on GitHub. Our developer will review it shortly, and we will get back to you with feedback afterward.

Best regards,
Jan

FatchipRobert added a commit to FatchipRobert/magento-2 that referenced this pull request Jan 6, 2025
@FatchipRobert
Copy link
Contributor

Fix looks fine and works for me.

I converted it to a fix without optional chaining for a better browser compatibility in PR #581

@janteuber janteuber closed this Jan 7, 2025
@sippsolutions
Copy link
Contributor Author

sippsolutions commented Jan 7, 2025

@FatchipRobert @janteuber
Thanks for merging a fix.
Please note that in my case, not only the responseJSON was the problem, but also the quote.paymentMethod() which is null during the shipping step. Can you please check for paymentMethod() as well (see my commit)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants