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

Reset cart quantity to 0 if we get a 404 for the cart #1661

Merged
merged 1 commit into from
Apr 22, 2020

Conversation

bookernath
Copy link
Contributor

@bookernath bookernath commented Apr 22, 2020

What?

If we get a 404 for the cart, set the quantity to 0 for the cart preview.

Fixes a bug where the quantity will not update back to 0 after a successful checkout.

Tickets / Documentation

@bigbot
Copy link

bigbot commented Apr 22, 2020

Autotagging @bigcommerce/storefront-team @davidchin

@@ -69,7 +69,12 @@ export default function (secureBaseUrl, cartId) {
const cartQtyPromise = new Promise((resolve, reject) => {
utils.api.cart.getCartQuantity({ baseUrl: secureBaseUrl, cartId }, (err, qty) => {
if (err) {
reject(err);
// If this appears to be a 404 for the cart ID, set cart quantity to 0
if (err === 'Not Found') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the messy string comparison?

Our request implementation only returns the string of the response code, not the actual error object:

https://github.com/bigcommerce/stencil-utils/blob/master/src/lib/request.js#L127

As such, I have nothing else to match on without a significant refactor.

Fortunately, the fallback behavior here is pretty elegant.

Copy link
Contributor

@bc-jz bc-jz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM considering that the change has been tested.

@bookernath bookernath merged commit 4c165ad into bigcommerce:master Apr 22, 2020
@bookernath bookernath deleted the fix-cart-404-quantity branch April 22, 2020 17:42
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.

None yet

3 participants