Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

Ajax cart request error when removing last item of a line #529

Closed
StephenBrownski opened this issue Apr 19, 2016 · 0 comments
Closed

Ajax cart request error when removing last item of a line #529

StephenBrownski opened this issue Apr 19, 2016 · 0 comments
Assignees

Comments

@StephenBrownski
Copy link
Contributor

The Issue

This has come up with other Shopify themes based on Timber that use ajax-cart.js.liquid

The issue appears when modifying the cart when viewed in the pull out drawer on a theme like Brooklyn. When the last item of a cart line is removed, and the user clicks multiple times before the cart is updated, one of two things can happen.

  1. If the item is the last line in the cart, an alert with 'Bad Request' pops up:
    https://screenshot.click/19-15-17109-ef7qk.mp4
  2. If there is another line item after the item that was removed, the next item will be completely removed from the cart, no matter its quantity:
    https://screenshot.click/19-18-anfbg-iz6g7.mp4

Number 2 above can also trigger the first error, depending on how many times the [ - ] was clicked before the cart view is updated.

The Fix

Thankfully, the fix is quite simple. it involves utilizing the isUpdating boolean set and modified throughout other parts of the code in ajax-cart.js.liquid. Use this bool to prevent additional requests from being sent off until the cart has been updated. This prevents the Shopify API from trying to modify an item that is no longer present or make changes to the wrong line item.

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

No branches or pull requests

1 participant