fix: for exact metada match for multiple items with same variant_id#14730
Closed
jbrigbyjs wants to merge 7 commits intomedusajs:developfrom
Closed
fix: for exact metada match for multiple items with same variant_id#14730jbrigbyjs wants to merge 7 commits intomedusajs:developfrom
jbrigbyjs wants to merge 7 commits intomedusajs:developfrom
Conversation
🦋 Changeset detectedLatest commit: 6546491 The changes in this PR will be included in the next version bump. This PR includes changesets to release 76 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 |
|
@jbrigbyjs is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @jbrigbyjs, |
Contributor
|
Hey @jbrigbyjs thanks for the contribution. I will go ahead and close this, though, as I've included this fix as part of #14834 while also handling |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What — What changes are introduced in this PR?
Updated the cart line-item action resolution logic to correctly handle cases where multiple cart line items share the same
variant_idbut differ inmetadata.The step now:
variant_id(as an array, not a single item).idto avoid emitting duplicate updates for the same record.Why — Why are these changes relevant or necessary?
The previous approach implicitly assumed
variant_idis unique per cart line item. In real scenarios, the same variant can exist multiple times in the cart with different metadata (e.g., different dates, room details, bundle context).Using a
Map<variant_id, item>causes overwriting and can result in:How — How have these changes been implemented?
variant_ids.variant_id -> CartLineItemDTO[](list of candidates).deepEqualObj, with proper handling of missing metadata).line_item.idinupdatesById.itemsToCreate.{ itemsToCreate, itemsToUpdate }, whereitemsToUpdateis derived fromupdatesById.values().ISSUE
#14731
Note
Medium Risk
Changes cart line-item merge/update resolution logic used by add-to-cart workflows; incorrect matching could affect cart quantities/prices, but scope is limited and covered by a new integration test.
Overview
Fixes cart line-item action resolution so items are merged/updated only when both
variant_idandmetadatamatch, allowing multiple line items with the same variant to coexist.get-line-item-actions-stepnow groups existing items pervariant_id, deep-compares metadata to choose the correct line item, deduplicates requested variant IDs for lookups, and accumulates updates per line-itemidto avoid emitting multiple updates for the same record. Adds an integration test covering add-A/meta-A, add-A/meta-B, then add-A/meta-A merging quantities correctly, plus a patch changeset for@medusajs/core-flows.Written by Cursor Bugbot for commit 6546491. This will update automatically on new commits. Configure here.