-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: carry over promotions toggle on exchanges #14128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 44398cd The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 8 Skipped Deployments
|
packages/core/core-flows/src/order/workflows/set-carry-over-promotion-flag.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on December 17
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
packages/core/core-flows/src/order/workflows/exchange/exchange-add-new-item.ts
Outdated
Show resolved
Hide resolved
olivermrbl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, few nits
...routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx
Show resolved
Hide resolved
.../dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/schema.ts
Outdated
Show resolved
Hide resolved
packages/core/core-flows/src/order/workflows/set-carry-over-promotion-flag.ts
Show resolved
Hide resolved
packages/core/core-flows/src/order/workflows/set-carry-over-promotion-flag.ts
Show resolved
Hide resolved
packages/core/core-flows/src/order/workflows/set-carry-over-promotion-flag.ts
Outdated
Show resolved
Hide resolved
| acc = | ||
| acc + | ||
| ((action?.details.quantity || 0) / item.quantity) * | ||
| item.total |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing optional chaining on details causes potential TypeError
The calculation for inbound total uses action?.details.quantity which only applies optional chaining to action, not to details. According to the type definition, details can be null (details: Record<string, unknown> | null). If action exists but action.details is null, accessing .quantity will throw a TypeError. The codebase elsewhere uses the safer pattern action?.details?.quantity with optional chaining on both properties.
| carry_over_promotions: checked, | ||
| }) | ||
| } | ||
| }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Toggle state not reverted on API failure
The onChange(checked) call updates the form state immediately before the updateOrderChange API call completes. If the API call fails, the form's carry_over_promotions value remains toggled while the backend retains the previous value. The onError handler only displays a toast without reverting the form state. Since the exchange confirmation uses the backend value (not the form value), users will see a toggle indicating promotions will carry over, but the actual exchange behavior won't apply promotions. The onChange call needs to be moved after the successful API call, or the state needs to be reverted in the error handling.
| acc = | ||
| acc + | ||
| ((action?.details.quantity || 0) / item.quantity) * | ||
| item.total |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Potential division by zero in inbound total calculation
The inbound total calculation divides by item.quantity without checking if it's zero. The expression ((action?.details.quantity || 0) / item.quantity) * item.total would produce NaN or Infinity if item.quantity is 0. While order items should typically always have a positive quantity, if there's any data integrity issue, this would cause incorrect monetary values to be displayed in the UI. Adding a guard like item.quantity || 1 or checking before division would prevent this edge case.
olivermrbl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice LGTM!
|
/snapshot-this |
🚀 A snapshot release has been made for this PRTest the snapshots by updating your yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]
|
|
tought: now when exchange is confirmed, and promotions are not carried over, it's not clear from the summary on the order details how the promotion has been applied. We might consider adding an indicator with promotions per line item as we did for edit items recently, wdyt - something to tackle in a follow up? |
|
/snapshot-this |
🚀 A snapshot release has been made for this PRTest the snapshots by updating your yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]
|
olivermrbl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge
packages/core/core-flows/src/order/workflows/set-carry-over-promotion-flag.ts
Outdated
Show resolved
Hide resolved
packages/core/core-flows/src/order/workflows/exchange/update-exchange-add-item.ts
Outdated
Show resolved
Hide resolved
packages/core/core-flows/src/order/workflows/compute-adjustments-for-preview.ts
Show resolved
Hide resolved
|
/snapshot-this |
🚀 A snapshot release has been made for this PRTest the snapshots by updating your yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add [email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]yarn add @medusajs/[email protected]
|
Summary
What — What changes are introduced in this PR?
Add ability to apply/remove promotions from outbound exchange item.
Checklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsScreen.Recording.2025-11-26.at.18.49.37.mov
TODO
CLOSES CORE-1291
Note
Adds a toggle to carry over promotions on exchanges/order changes, wiring DB, workflows, API/SDK, admin UI, and tests to apply/remove adjustments accordingly.
compute-adjustments-for-preview(generalized),on-carry-promotions-flag-set,update-order-changeworkflow, andlist-order-change-actions-by-typestep; compute or deleteITEM_ADJUSTMENTS_REPLACEbased onorder_change.carry_over_promotions.POST /admin/order-changes/:idto updatecarry_over_promotionsand returnorder_change.AdminOrderChangeand mutations/responses withcarry_over_promotions; addAdminOrderChangeResponse.carry_over_promotionstoorder_change(migration + model + query config).sdk.admin.order.updateOrderChange(id, { carry_over_promotions }).preview.order_changeand updates via new mutation; adjust totals calculation; show applied promo codes icon in order summary.useUpdateOrderChangehook; i18n strings/schema updates.Written by Cursor Bugbot for commit 44398cd. This will update automatically on new commits. Configure here.