- add an item to the cart
- add a discount code
- add an item that triggers an auto-discount
- remove the auto-discount item
- BUG: the manually applied discount isn't reflected in the line items or the total
The full story:
Stack: consuming the Buy API using the shopify-buy npm package in a React application.
Steps to reproduce:
- Add an item to the cart (but not an item that triggers an automatically applied discount).
- Apply a discount code to the cart.
- The response object show the discount in these places:
- in the `checkout.discountApplications`
- on the `lineItem`(s) in the cart, in each item's `discountAllocations`
- the order totals reflect the fact that discount is applied to the item(s) in the cart.
- Add an item/items to the cart, but this time add an item that triggers an auto-applied discount.
- The response object shows two discounts in `checkout.discountApplications` but only the auto-applied discount has any effect on the items or the total.
- Remove the item(s) that triggered the auto-applied discount from the cart. In my case, having two of a certain item triggers the auto-discount, so removing one of them removes the auto-discount.
BUG: The response object shows the manually applied discount code (from step 2) in `checkout.discountApplications`, but the total doesn't reflect the discount, and the `lineItems` do not have the discount in their `discountAllocations`.
EXPECTED BEHAVIOR: The response should show the manually applied discount in each of the `lineItems` that it applies to, and the total should reflect the manually applied discount as well.
The very next time you do anything to update the cart (or, just request the cart state (e.g. using `shopifyClient.checkout.fetch(checkoutId)`, it accurately reflects the manually applied discount code in the total, on the line items, and in `checkout.discountApplications`.
My workaround for the moment is:
- Each time a discount of any kind is applied or changed, I store whether is was an auto-applied discount.
- Any time the application changes from a state of "has auto applied discount" -> "does not have auto applied discount", we add an extra API call to `shopifyClient.checkout.fetch()`, and use that response object to update the UI.
Thanks in advance!