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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion assets/js/theme/global/cart-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

resolve(0);
} else {
reject(err);
}
}
resolve(qty);
});
Expand Down