fix(core-flows): force cart refresh on updatePromotionsWorkflow when refreshing items#14569
Conversation
🦋 Changeset detectedLatest commit: f7fa0dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 77 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. 9 Skipped Deployments
|
fPolic
left a comment
There was a problem hiding this comment.
LGTM! Would it make sense to add a test case for this scenario?
|
Thank you for your contribution! 🎉 After an initial review, this PR looks good to us. Here's a summary: ✅ Linked to a verified issue (#14484) The root cause analysis in the PR description is accurate: Notes:
A team member will do a final review before this is merged. We appreciate your patience! |
Summary
What — What changes are introduced in this PR?
Guarantee that
updateCartPromotionsWorkflowhas the latest snapshot of the cart.Why — Why are these changes relevant or necessary?
We were avoiding refetching the cart in
updateCartPromotionsWorkflow, which doesn't cause issues unless:item_subtotal >= 100.In this case, if we don't force the refresh inside the workflow,
refreshCartShippingMethodsWorkflowruns and updates the shipping totals correctly, but we pass a cart object with stale data for the shipping totals and thus, adding/removing an item from the cart will compute the promotion based on the shipping total before the modification happened.How — How have these changes been implemented?
Force the cart to be refreshed inside
updateCartPromotionsWorkflowso that if the shipping total changed because it had a calculated price dependent on the cart context, then the promotion is computed using the latest information of the cart.Testing — How have these changes been tested, or how can the reviewer test the feature?
Examples
Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.
// Example usageChecklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional Context
Add any additional context, related issues, or references that might help the reviewer understand this PR.
fixes #14484
Note
Ensures promotions are computed against the latest cart state when items change, avoiding stale shipping totals.
refresh-cart-items.ts, remove passingcarttoupdateCartPromotionsWorkflow, forcing it to refetch the cart before applyingREPLACEonpromo_codes.@medusajs/core-flows.Written by Cursor Bugbot for commit 937ae7a. This will update automatically on new commits. Configure here.