fix: for exact metada match for multiple items with same variant_id#14730
Open
jbrigbyjs wants to merge 5 commits intomedusajs:developfrom
Open
fix: for exact metada match for multiple items with same variant_id#14730jbrigbyjs wants to merge 5 commits intomedusajs:developfrom
jbrigbyjs wants to merge 5 commits intomedusajs:developfrom
Conversation
🦋 Changeset detectedLatest commit: aac390d 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, |
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 behavior in the add-to-cart workflow, which can affect quantities and pricing for existing carts. Scope is contained to action resolution logic and includes safeguards for per-item update aggregation.
Overview
Fixes cart add-to-cart line-item resolution when multiple existing items share the same
variant_idbut differ inmetadata. The step now groups existing items byvariant_id, matches using deep metadata equality, and accumulates quantity/price updates per line-itemidto avoid incorrect merges or duplicate updates.Also deduplicates queried
variant_ids, makes the empty-items guard null-safe, and adds a patch changeset for@medusajs/core-flows.Written by Cursor Bugbot for commit aac390d. This will update automatically on new commits. Configure here.