Combined Listings in Hydrogen
This recipe lets you more precisely display and manage combined listings on product pages and in search results for your Hydrogen storefront. A combined listing groups separate products together into a single product listing using a shared option like color or size. Each product appears as a variant but can have its own title, description, URL, and images. In this recipe, you'll make the following changes:
- Set up the Combined Listings app in your Shopify admin and group relevant products together as combined listings.
- Configure how combined listings will be handled on your storefront.
- Update the
ProductForm
component to hide the Add to cart button for the parent products of combined listings. - Update the
ProductImage
component to support images from product variants and the product itself. - Show a range of prices for combined listings in
ProductItem
.
Anchor to RequirementsRequirements
- Your store must be on either a Shopify Plus or enterprise plan.
- Your store must have the Combined Listings app installed.
Anchor to IngredientsIngredients
New files added to the template by this recipe.
File | Description |
---|---|
app/lib/combined-listings.ts | The combined-listings.ts file contains utilities and settings for handling combined listings. |
Anchor to Step 1: Set up the Combined Listings appStep 1: Set up the Combined Listings app
-
Install the Combined Listings app.
-
Add tags to the parent products of combined listings to indicate that they're part of a combined listing (for example
combined
).
Anchor to Step 2: Configure combined listings behaviorStep 2: Configure combined listings behavior
You can customize how the parent products of combined listings are retrieved and displayed.
To make this process easier, we included a configuration object in the combined-listings.ts
file that you can edit to customize according to your preferences.
Anchor to Step 3: Add combined listings utilitiesStep 3: Add combined listings utilities
Create a new combined-listings.ts
file that contains utilities and settings for handling combined listings.
File
Anchor to Step 4: Update the ProductForm componentStep 4: Update the Product Form component
- Update the
ProductForm
component to hide the Add to cart button for the parent products of combined listings and for variants' selected state. - Update the
Link
component to not replace the current URL when the product is a combined listing parent product.
File
Anchor to Step 5: Extend the ProductImage componentStep 5: Extend the Product Image component
Update the ProductImage
component to support images from both product variants and the product itself.
Anchor to Step 6: Show a range of prices for combined listings in ProductItemStep 6: Show a range of prices for combined listings in Product Item
Update ProductItem.tsx
to show a range of prices for the combined listing parent product instead of the variant price.
Anchor to Step 7: (Optional) Add redirect utility to first variant of a combined listingStep 7: (Optional) Add redirect utility to first variant of a combined listing
If you want to redirect automatically to the first variant of a combined listing when the parent handle is selected, add a redirect utility that's called whenever the parent handle is requested.
Anchor to Step 8: Update queries for combined listingsStep 8: Update queries for combined listings
- Add the
tags
property to the items returned by the product query. - (Optional) Add the filtering query to the product query to exclude combined listings.
File
Anchor to Step 9: (Optional) Filter out combined listings from collections pagesStep 9: (Optional) Filter out combined listings from collections pages
Since it's not possible to directly apply query filters when retrieving collection products, you can manually filter out combined listings after they're retrieved based on their tags.
File
Anchor to Step 10: (Optional) Filter out combined listings from the collections index pageStep 10: (Optional) Filter out combined listings from the collections index page
Update the collections.all
route to filter out combined listings from the search results, and include the price range for combined listings.
Anchor to Step 11: Update the product pageStep 11: Update the product page
- Display a range of prices for combined listings instead of the variant price.
- Show the featured image of the combined listing parent product instead of the variant image.
- (Optional) Redirect to the first variant of a combined listing when the handle is requested.
File
Anchor to Step 12: Update stylesheetStep 12: Update stylesheet
Add a class to the product item to show a range of prices for combined listings.
Anchor to Next stepsNext steps
- Test your implementation by going to your store and searching for a combined listing. Make sure that the combined listing's details appear in the search results and on the product page.
- (Optional) Place a test order to see how orders for combined listings appear in your Shopify admin.