fix(core-flows): consider price and metadata for multiple items linked to a single variant when resolving line action#14834
fix(core-flows): consider price and metadata for multiple items linked to a single variant when resolving line action#14834NicolasGorga wants to merge 7 commits intodevelopfrom
Conversation
…gle variant due to custom unit price
|
The latest updates on your projects. Learn more about Vercel for GitHub. 9 Skipped Deployments
|
🦋 Changeset detectedLatest commit: 1a6cef0 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 |
|
Thank you for your contribution! 🎉 After an initial review, this PR looks good to us. Here's a summary: ✅ Linked to a verified issue (#14731) Notes:
A team member will do a final review before this is merged. We appreciate your patience! |
|
@NicolasGorga keeping it open as I think this is a valid concern:
|
| await addToCartWorkflow(appContainer).run({ | ||
| input: { | ||
| cart_id: cart.id, | ||
| items: [ | ||
| { | ||
| variant_id: variantId, | ||
| quantity: 1, | ||
| unit_price: 999, | ||
| metadata, | ||
| }, | ||
| ], | ||
| }, | ||
| }) |
There was a problem hiding this comment.
The edge case here is that you pass two items to the workflow having the same variant, price, and metadata
There was a problem hiding this comment.
Hey @shahednasser, that is tested below, starting from line 1722. Let me know if that is what you meant :)
Summary
What — What changes are introduced in this PR?
Update
getLineItemActionStepoperation (update/create) resolution logic, to handle scenarios where a single variant is linked to multiple line items, such as when having custom price line items, or having added items with normal pricing but different metadata than the existing line item.Why — Why are these changes relevant or necessary?
We were treating the map of variant <> line item as if it were a one-to-one relation, when in fact a variant can be linked to multiple items, such as when we add different items with different prices or when the metadata is different than the existing item. We were also only taking into consideration the metadata to determine if we should update/create, when in fact, for custom unit price items, we should also compare the unit price.
How — How have these changes been implemented?
Treat the map as a one-to-many relation, where a variant can be linked to multiple items. Also, take unit price into account when the item to be added has a custom price, when comparing against existing items linked to the variant, to determine if we should update/create.
Testing — How have these changes been tested, or how can the reviewer test the feature?
Please provide answer here
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.
closes CORE-1378
fixes #14731