Skip to content

Commit 2c91fe4

Browse files
feat(checkout): ✨ Add parent/parentRelationship property to CartLines for Checkout. (#3072)
### Background This PR adds parent/parentRelationship properties to CartLines for Checkout, enabling the representation of relationships between cart lines. Follow up to the [private repo change](https://app.graphite.dev/github/pr/shop/world/62239). ### Solution Added support for parent-child relationships between cart lines in the Checkout API: 1. Added a new `CartLineParentRelationship` interface that contains parent line information 2. Added the `parentRelationship` property to the `CartLine` interface 3. Added optional `parent` property to `CartLineAddChange` and `CartLineUpdateChange` interfaces to allow setting parent relationships when adding or updating cart lines 4. Exported the new `CartLineParentRelationship` type These changes enable extensions to work with hierarchical cart line structures, such as bundles or add-ons that are associated with a parent product. ### 🎩 - Test adding a cart line with a parent relationship - Test updating a cart line to associate it with a parent - Verify parent relationships are correctly displayed in the UI ### Checklist - [ ] I have 🎩'd these changes - [x] I have updated relevant documentation
2 parents a5e3714 + c364a95 commit 2c91fe4

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

.changeset/violet-eggs-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': minor
3+
---
4+
5+
Add parent/parentRelationship property to CartLines for Checkout.

packages/ui-extensions/src/surfaces/checkout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type {
3131
AppMetafieldEntryTarget,
3232
AppMetafieldEntry,
3333
CartLine,
34+
CartLineParentRelationship,
3435
PaymentOption,
3536
SelectedPaymentOption,
3637
CartDiscountCode,

packages/ui-extensions/src/surfaces/checkout/api/checkout/checkout.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ export interface CartLineAddChange {
183183
* with.
184184
*/
185185
sellingPlanId?: SellingPlan['id'];
186+
187+
/**
188+
* The identifier for the associated parent cart line.
189+
*/
190+
parent?: {lineId: string} | {merchandiseId: string};
186191
}
187192

188193
export interface CartLineRemoveChange {
@@ -236,6 +241,11 @@ export interface CartLineUpdateChange {
236241
* with or `null` to remove the the product from the selling plan.
237242
*/
238243
sellingPlanId?: SellingPlan['id'] | null;
244+
245+
/**
246+
* The identifier for the associated parent cart line.
247+
*/
248+
parent?: {lineId: string} | {merchandiseId: string};
239249
}
240250

241251
export type DiscountCodeChange =

packages/ui-extensions/src/surfaces/checkout/api/standard/standard.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,26 @@ export interface CartLine {
977977
* Sub lines of the merchandise line. If no sub lines are present, this will be an empty array.
978978
*/
979979
lineComponents: CartLineComponentType[];
980+
981+
/**
982+
* The relationship details between cart lines.
983+
*/
984+
parentRelationship: CartLineParentRelationship | null;
985+
}
986+
export interface CartLineParentRelationship {
987+
/**
988+
* The parent cart line that a cart line is associated with.
989+
*/
990+
parent: {
991+
/**
992+
* These line item IDs are not stable at the moment, they might change after
993+
* any operations on the line items. You should always look up for an updated
994+
* ID before any call to `applyCartLinesChange` because you'll need the ID to
995+
* create a `CartLineChange` object.
996+
* @example 'gid://shopify/CartLine/123'
997+
*/
998+
id: string;
999+
};
9801000
}
9811001

9821002
type CartLineComponentType = CartBundleLineComponent;

0 commit comments

Comments
 (0)