reactioncommerce/example-storefront

`buildOrder` should use itemTotal instead of total

Closed this issue · 1 comments

Type: minor

Describe the bug
This bug will only be apparent when you apply a discount for your order.

Placing the order with a discount applied fails with the error:

Client provided total price ${the discounted value with the discount applied twice} for order group, but actual total price is ${the discounted value}

To Reproduce
Steps to reproduce the behavior:

  1. Add item to cart
  2. Find your cart in the db, add discount: 10 to it
  3. Go to checkout / refresh checkout and try to place your order
  4. Get error

Expected behavior
There should be no error during checkout.

Additional context
The price check fails as the fulfillmentGroup is expected to have a total that does not include the discount. (For reference: updateGroupTotals.js#L77 in the orders plugin)

The storefront currently uses something that seems like a workaround, so every fulfillmentGroup has the the checkout total as totalPrice:

https://github.com/reactioncommerce/example-storefront/blob/develop/src/components/CheckoutActions/CheckoutActions.js#L230

(This certainly wouldn't work for multiple fulfillmentGroups during checkout.)

This will fail, as the checkout total already includes the total.
Instead, while keeping this workaround, this should use checkout.summary.itemTotal.amount instead of checkout.summary.total.amount

Hey, I'm facing the same problem, did you find any solution for multiple fulfillmentGroups?