feat(core): filter out child cart line items #2827
Open
+91
−3
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.
What/Why?
Filter out child cart items (items with
parentEntityId) from cart and cart analytics to prevent duplicate line items when products have parent-child relationships, such as product bundles.Simplified this implementation over #2726 because it's not easy to know which
CartSelectedMultipleChoiceOptionfrom the product options/modifiers has attached this child product to the parent item, so we would get duplicate information (in the product options list, shown below, as well as a separate product item below the parent product). I opted for less duplication and code simplicity.Testing
Migration steps
Step 1: GraphQL Fragment Updates
The
parentEntityIdfield has been added to both physical and digital cart item fragments to identify child items.Update
core/app/[locale]/(default)/cart/page-data.ts:export const PhysicalItemFragment = graphql(` fragment PhysicalItemFragment on CartPhysicalItem { entityId quantity productEntityId variantEntityId + parentEntityId listPrice { currencyCode value } } `); export const DigitalItemFragment = graphql(` fragment DigitalItemFragment on CartDigitalItem { entityId quantity productEntityId variantEntityId + parentEntityId listPrice { currencyCode value } } `);Step 2: Cart Display Filtering
Cart line items are now filtered to exclude child items when displaying the cart.
Update
core/app/[locale]/(default)/cart/page.tsx:const lineItems = [ ...cart.lineItems.giftCertificates, ...cart.lineItems.physicalItems, ...cart.lineItems.digitalItems, - ]; + ].filter((item) => !('parentEntityId' in item) || !item.parentEntityId);Step 3: Analytics Data Filtering
Analytics data collection now only includes top-level items to prevent duplicate tracking.
Update
core/app/[locale]/(default)/cart/page.tsxin thegetAnalyticsDatafunction:Step 4: Styling Update
Cart subtitle text color has been updated for improved contrast.
Update
core/vibes/soul/sections/cart/client.tsx: