Skip to content

Conversation

@fredericoo
Copy link
Contributor

@fredericoo fredericoo commented Jan 21, 2026

WHY are these changes introduced?

SFAPI 2025-10 introduces parentRelationship to line items. It means we can now access and render line items with hierarchy.

This PR adds support for displaying child line items in the cart, such as warranties or gift wrapping options that are associated with a parent product.

WHAT is this pull request doing?

  • Enhances the CartLineItem component to display child components nested under their parent line items
  • Adds a new CartLineChild component to render child line items with appropriate styling
  • Updates the GraphQL fragments to include lineComponents and parentRelationship data
  • Adds CSS styling for the nested child line items with indentation and a left border
  • Updates TypeScript definitions to support the new data structure

HOW to test your changes?

Because we don’t offer a way to add a child product in this (there are infinity ways of doing it and it’s down to the store manager to do it) you will have to make a few code changes.

  1. rebuild packages needed by skeleton (npm run build --filter=skeleton) and run the skeleton dev server cd templates/skeleton && npm run dev
  2. create or grab a product variant id from your store (2 would be ideal so you can tell them apart). Open http://localhost:3000/graphiql and call this:
query allProductVariants{
  products(first:10){
    nodes {
      title
      variants(first: 10){
        nodes {
          title
          id
        }
      }
    }
  }
}
  1. add this to ProductForm.tsx line 123, replacing YOUR_WARRANTY_VARIANT_ID with a variant id you got form step 2.
<AddToCartButton
        lines={
          selectedVariant
            ? [
                {
                  merchandiseId: selectedVariant.id,
                  quantity: 1,
                  selectedVariant,
                },
                {
                  merchandiseId: 'YOUR_WARRANTY_VARIANT_ID',
                  quantity: 1,
                  parent: {merchandiseId: selectedVariant.id},
                },
              ]
            : []
        }
      >
        {selectedVariant?.availableForSale ? 'Add to cart with warranty' : 'Sold out'}
      </AddToCartButton>
  1. View on the frontend

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor Author

fredericoo commented Jan 21, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shopify
Copy link
Contributor

shopify bot commented Jan 21, 2026

Oxygen deployed a preview of your 01-20-feat_add_support_for_nested_cart_lines branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment January 23, 202611:55 AM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment January 21, 2026 6:02 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment January 21, 2026 6:02 PM
sitemap ✅ Successful (Logs) Preview deployment Inspect deployment January 21, 2026 6:02 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment January 21, 2026 6:02 PM

Learn more about Hydrogen's GitHub integration.

@fredericoo fredericoo marked this pull request as ready for review January 21, 2026 14:43
@fredericoo fredericoo requested a review from a team as a code owner January 21, 2026 14:43
@fredericoo fredericoo force-pushed the 01-20-feat_add_support_for_nested_cart_lines branch 3 times, most recently from 828daa8 to aa8ea9b Compare January 21, 2026 17:59
@kdaviduik kdaviduik changed the base branch from 2025-10-sfapi-caapi-update to graphite-base/3398 January 22, 2026 04:25
Copy link
Contributor

@kdaviduik kdaviduik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have enough time for a full pass, I will continue tomorrow :)

Copy link
Contributor

@kdaviduik kdaviduik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cookbook stuff is very borked, but tomorrow we can pair to fix that if you want to learn how :) I'd recommend reverting all of the changes to the cookbook folder as it'll be easier to start fresh.

the regenerate command sounds like it would be what we want to use here, but it actually is for a very different use case. so using it here deleted a lot of the actual content of the recipes, since when you regenerated them the recipe wasn't already applied to the skeleton. the best thing to do (after reverting all of the cookbook changes) would be to manually (probably with AI assistance :P) update the patch files of the specific recipes that are failng validation, so that the patch files will now work as diffs against the new version of the skeleton with all of your changes. But since we're doing so many separate changes to the skeleton as part of this work, I think we're better off just ignoring "validate recipes" CI check and fixing it at the end once all PRs are merged into the stack. Discussion here

Imo the cookbook commands are very misleading and confusing, and there's no command to do what we need for the most common use case. I want to fix this in the future. I have a doc here with a bit more information and some very WIP/draft ideas to fix these

// 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'}}
Copy link
Contributor

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

@fredericoo fredericoo force-pushed the 01-20-feat_add_support_for_nested_cart_lines branch from aa8ea9b to d0bba38 Compare January 23, 2026 11:52
Copy link
Contributor Author

yeah will revert! it’s really hard to maintain the patches though, it’s not the most ergonomic of formats :(

your proposal is a good step to automate this, but i think there is no easy way to do these patches automatically

import {useAside} from './Aside';
import type {CartApiQueryFragment} from 'storefrontapi.generated';
import type {
CartApiQueryFragment,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(threading)
your tophatting instructions didn't work for me :(

Image

Claude suggested doing this:

Image

So I tried that but now no items are able to be added to the cart. Please update your instructions :)

Copy link
Contributor

Please re-request my review when you want me to take another look :) It looks like the tophatting instructions haven't been updated since my last review.

image.png

@kdaviduik kdaviduik changed the base branch from graphite-base/3398 to main January 27, 2026 18:59
@kdaviduik kdaviduik merged commit 0e61522 into main Jan 27, 2026
27 of 58 checks passed
@kdaviduik kdaviduik deleted the 01-20-feat_add_support_for_nested_cart_lines branch January 27, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants