Skip to content

Conversation

@kdaviduik
Copy link
Contributor

@kdaviduik kdaviduik commented Jun 20, 2025

Nicer diffs if you review commit by commit (and without whitespace diffs!) :)

  1. Fix bug with adding multiple discount codes when not all codes are applicable
    • A discount code can be added to a cart but might not be applicable. In that case, the code will appear in the discountCodes array, but there won't be any discount allocations.
    • Since we were using discount allocations to determine which discount codes existed, we would end up inadvertently removing discount codes that were added but not applicable.
  2. Fix bug where a shipping discount could appear as a line item discount (ie: fixes Discount allocation mapping "graceful abort" causing frontend to incorrectly show discounts (from #1032) #1040)
    • Our previous discount mapping logic did not properly map shipping discounts - they were treated the same as order-level discounts, but behave differently.
    • Unlike order-level discounts (which must get mapped onto line items), shipping discounts should ONLY appear in the checkout.discountApplications array.
    • Importantly, if a shipping discount has been added but there is no shipping address known, the Cart APIs behave differently than the Checkout APIs and we therefore have no way of knowing the value, target type, etc. This information was returned by the Checkout APIs in the checkout.discountApplications array, but now we cannot return shipping discounts in that array if we don't have a shipping address.

@kdaviduik kdaviduik self-assigned this Jun 20, 2025
@kdaviduik kdaviduik requested a review from juanpprieto June 20, 2025 21:08
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch from 878bc8c to f4b3f4b Compare June 20, 2025 21:09
@kdaviduik kdaviduik marked this pull request as draft June 20, 2025 21:11
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch 3 times, most recently from 21fc47a to ee368bb Compare June 20, 2025 21:18
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch from ee368bb to b2da846 Compare June 20, 2025 21:21
…plicable

A discount code can be added to a cart but might not be `applicable`. In that case, the code
will appear in the `discountCodes` array, but there won't be any discount allocations.

Since we were using discount allocations to determine which discount codes existed, we would
end up inadvertently removing discount codes that were added but not `applicable`.
We're going to use this in the next commit. Separating out this change makes the diffs much
easier to read
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch from b2da846 to 40b0e8a Compare June 20, 2025 21:25
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch 2 times, most recently from 11c9298 to c627b05 Compare June 24, 2025 00:33
Our previous discount mapping logic did not properly map shipping discounts -
they were treated the same as order-level discounts, but behave differently.

Unlike order-level discounts (which must get mapped onto line items), shipping
discounts should ONLY appear in the `checkout.discountApplications` array.

Importantly, if a shipping discount has been added but there is no shipping
address known, the Cart APIs behave differently than the Checkout APIs and
we therefore have no way of knowing the value, target type, etc. This information
was returned by the Checkout APIs in the `checkout.discountApplications` array,
but now we cannot return shipping discounts in that array if we don't have a
shipping address.
@kdaviduik kdaviduik force-pushed the kd-shipping-discount-fix branch from c627b05 to 245726e Compare June 24, 2025 00:44
@kdaviduik kdaviduik marked this pull request as ready for review June 24, 2025 00:44
@kdaviduik kdaviduik requested a review from juanpprieto June 24, 2025 00:47
Copy link
Contributor

@juanpprieto juanpprieto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks LGTM

@kdaviduik kdaviduik merged commit 1edd3d2 into main Jun 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discount allocation mapping "graceful abort" causing frontend to incorrectly show discounts (from #1032)

2 participants