BUG REPORT: Removing auto-discount doesn't re-apply discount code

jwalkerps
New Member
2 0 0

tl;dr

  1. add an item to the cart
  2. add a discount code
  3. add an item that triggers an auto-discount
  4. remove the auto-discount item
  5. 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:

  1. Add an item to the cart (but not an item that triggers an automatically applied discount).

 

shopifyClient.checkout.addLineItems(checkoutId, lineItemsToAdd);

 

  • Apply a discount code to the cart.

 

shopifyClient.checkout.addDiscount(checkoutId, discountCode);

 

  • 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.

 

shopifyClient.checkout.updateLineItems(checkoutId, lineItemsToUpdate);

 

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.

 

Please help.

Thanks in advance!

Replies 0 (0)