Bundles in Hydrogen
This recipe adds special styling for product bundles on your Hydrogen storefront. Customers will see badges and relevant cover images for bundles when they're viewing product and collection pages.
In this recipe you'll make the following changes:
- Set up the Shopify Bundles app in your Shopify admin and create a new product bundle.
- Update the GraphQL fragments to query for bundles to identify bundled products.
- Update the product and collection templates to display badges on product listings, update the copy for the cart buttons, and display bundle-specific information on product and collection pages.
- Update the cart line item template to display the bundle badge as needed.
Anchor to RequirementsRequirements
To use product bundles, you need to install a bundles app in your Shopify admin. In this recipe, we'll use the Shopify Bundles app.
Anchor to IngredientsIngredients
New files added to the template by this recipe.
File | Description |
---|---|
app/components/BundleBadge.tsx | A badge displayed on bundle product listings. |
app/components/BundledVariants.tsx | A component that wraps the variants of a bundle product in a single product listing. |
Anchor to Step 1: Set up the Shopify Bundles appStep 1: Set up the Shopify Bundles app
-
Install the Shopify Bundles app in your Shopify admin.
-
Make sure your store meets the eligibility requirements.
-
From the Bundles page, create a new bundle.
Anchor to Step 2: Create the BundleBadge componentStep 2: Create the Bundle Badge component
Create a new BundleBadge component to be displayed on bundle product listings.
File
Anchor to Step 3: Create a new BundledVariants componentStep 3: Create a new Bundled Variants component
Create a new BundledVariants
component that wraps the variants of a bundle product in a single product listing.
File
Anchor to Step 4: Add maxVariantPrice to the product fields for RecommendedProductsStep 4: Add max Variant Price to the product fields for Recommended Products
Add maxVariantPrice
to the RecommendedProducts
query's product fields.
Anchor to Step 5: Update the product fragment to query for bundles and display BundledVariantsStep 5: Update the product fragment to query for bundles and display Bundled Variants
- Add the
requiresComponents
field to theProduct
fragment, which is used to identify bundled products. - Pass the
isBundle
flag to theProductImage
component.
File
Anchor to Step 6: Update the collections fragment to query for bundlesStep 6: Update the collections fragment to query for bundles
Like the previous step, use the requiresComponents
field to detect if the product item is a bundle.
Anchor to Step 7: Update the cart fragment to query for bundlesStep 7: Update the cart fragment to query for bundles
Use the requiresComponents
field to determine if a cart line item is a bundle.
Anchor to Step 8: Conditionally render the BundleBadge in cart line itemsStep 8: Conditionally render the Bundle Badge in cart line items
If a product is a bundle, show the BundleBadge
component in the cart line item.
Anchor to Step 9: Conditionally render "Add bundle to cart" in ProductFormStep 9: Conditionally render "Add bundle to cart" in Product Form
If a product is a bundle, update the text of the product button.
Anchor to Step 10: Conditionally render the BundleBadge in ProductImageStep 10: Conditionally render the Bundle Badge in Product Image
If a product is a bundle, show the BundleBadge
component in the ProductImage
component.
Anchor to Step 11: Conditionally render the BundleBadge in ProductItemStep 11: Conditionally render the Bundle Badge in Product Item
If a product is a bundle, show the BundleBadge
component in the ProductItem
component.
File
Anchor to Step 12: Add a product-image class to the app stylesheetStep 12: Add a product-image class to the app stylesheet
Make sure the bundle badge is positioned relative to the product image.
Anchor to Next stepsNext steps
- Test your implementation by going to your store and adding a bundle to the cart. Make sure that the bundle's badge appears on the product page and in the cart.
- (Optional) Place a test order to see how orders for bundles appear in your Shopify admin.