-
Notifications
You must be signed in to change notification settings - Fork 382
feat: add support for nested cart lines #3398
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| '@shopify/hydrogen-react': patch | ||
| --- | ||
|
|
||
| Add `parent` prop to `AddToCartButton` for nested cart lines | ||
|
|
||
| The `AddToCartButton` component now accepts an optional `parent` prop, allowing you to add items as children of an existing cart line. This enables adding warranties, gift wrapping, or other add-ons that should be associated with a parent product. | ||
|
|
||
| ### Usage | ||
|
|
||
| ```tsx | ||
| import {AddToCartButton} from '@shopify/hydrogen-react'; | ||
|
|
||
| // Add a warranty as a child of an existing cart line (by line ID) | ||
| <AddToCartButton | ||
| variantId="gid://shopify/ProductVariant/warranty-123" | ||
| parent={{parentLineId: 'gid://shopify/CartLine/parent-456'}} | ||
| > | ||
| Add Extended Warranty | ||
| </AddToCartButton> | ||
|
|
||
| // Add a warranty as a child of a cart line (by merchandise ID) | ||
| // Useful when you know the product variant but not the cart line ID | ||
| <AddToCartButton | ||
| variantId="gid://shopify/ProductVariant/warranty-123" | ||
| parent={{merchandiseId: 'gid://shopify/ProductVariant/laptop-456'}} | ||
| > | ||
| Add Extended Warranty | ||
| </AddToCartButton> | ||
| ``` | ||
|
|
||
| ### Type | ||
|
|
||
| ```ts | ||
| interface AddToCartButtonPropsBase { | ||
| // ... existing props | ||
| /** The parent line item of the item being added to the cart. Used for nested cart lines. */ | ||
| parent?: CartLineParentInput; | ||
| } | ||
| ``` | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| '@shopify/cli-hydrogen': patch | ||
| 'skeleton': patch | ||
| --- | ||
|
|
||
| Add support for nested cart line items (warranties, gift wrapping, etc.) | ||
|
|
||
| Storefront API 2025-10 introduces `parentRelationship` on cart line items, enabling parent-child relationships for add-ons. This update displays nested line items in the cart. | ||
|
|
||
| ### Changes | ||
|
|
||
| - Updates GraphQL fragments to include `parentRelationship` and `lineComponents` fields | ||
| - Updates `CartMain` and `CartLineItem` to render child line items with visual hierarchy | ||
|
|
||
| ### Note | ||
|
|
||
| This update focuses on **displaying** nested line items. To add both a product and its child (e.g., warranty) in a single action: | ||
|
|
||
| ```tsx | ||
| <AddToCartButton | ||
| lines={[ | ||
| {merchandiseId: 'gid://shopify/ProductVariant/laptop-456', quantity: 1}, | ||
| { | ||
| merchandiseId: 'gid://shopify/ProductVariant/warranty-123', | ||
| quantity: 1, | ||
| parent: {merchandiseId: 'gid://shopify/ProductVariant/laptop-456'}, | ||
| }, | ||
| ]} | ||
| > | ||
| Add to Cart with Warranty | ||
| </AddToCartButton> | ||
| ``` |
kdaviduik marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
note for other reviewers: this is using the actual type from the SF API, so the parent line item ID is also accepted here. either one works