Skip to content

Commit 8f3f4e0

Browse files
committed
experiment with contextual prompting
1 parent e9ae1f7 commit 8f3f4e0

File tree

5 files changed

+164
-20
lines changed

5 files changed

+164
-20
lines changed

.cursor/rules/cookbook-recipe-subscriptions.mdc

+59-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ globs: templates/**/*
44
alwaysApply: false
55
---
66

7-
This rule describes how to implement "`Subscriptions (subscriptions)`" in a Hydrogen storefront. Below is a "recipe" that contains the steps to apply to a basic Hydrogen skeleton template to achieve the desired outcome.
7+
# Overview
8+
9+
This rule describes how to implement "Subscriptions (subscriptions)" in a Hydrogen storefront. Below is a "recipe" that contains the steps to apply to a basic Hydrogen skeleton template to achieve the desired outcome.
810
The same logic can be applied to any other Hydrogen storefront project, adapting the implementation details to the specific needs/structure/conventions of the project, but it's up to the developer to do so.
911

1012
If there are any prerequisites, the recipe below will explain them; if the user is trying to implement the feature described in this recipe, make sure to prominently mention the prerequisites and any other preliminary instructions, as well as followups.
@@ -15,15 +17,60 @@ If the user is asking on how to implement the feature from scratch, please first
1517

1618
Please note that the recipe steps below are not necessarily ordered in the way they should be executed, as it depends on the user's needs and the specific details of the project. The recipe steps descriptions should allow you to understand what is required to be done in a certain order and what is not. Remember that file names in the recipe are related to the Hydrogen skeleton template, not the user's project, so make sure to adapt the file names to the user's project.
1719

20+
# User Intent Recognition
21+
<user_queries>
22+
- How do I add subscription options to my Hydrogen store?
23+
- I want to let customers subscribe to products in my Shopify Hydrogen site
24+
- Can you help me implement recurring orders in Hydrogen?
25+
- How to show subscription pricing on product page in Hydrogen?
26+
- Need help adding a 'Subscribe and Save' option to my products
27+
- How do I modify the cart to show subscription details?
28+
- Making a subscription box with Hydrogen and Shopify
29+
- I've set up selling plans in Shopify admin, how do I display them in Hydrogen?
30+
- Help implementing Shopify subscriptions in my Hydrogen storefront
31+
- My selling plans aren't showing up in my Hydrogen store
32+
- How to calculate and display subscription discounts in Hydrogen?
33+
- Adding monthly subscription billing to Hydrogen products
34+
- Implementing 'delivery every X weeks' options in Hydrogen
35+
- How to let customers choose between one-time purchase and subscription?
36+
- Setting up recurring delivery options on my Hydrogen product page
37+
</user_queries>
38+
39+
# Troubleshooting
40+
<troubleshooting>
41+
- **Issue: Subscription options not appearing on product page**
42+
**Solution**: Verify that you've created selling plans in Shopify admin and attached them to the product. Also ensure the `sellingPlanGroups` fragment is included in your product query.
43+
- **Issue: Price calculations for subscriptions appear incorrect**
44+
**Solution**: Check the selling plan price adjustments in your query. Make sure you're handling all three types of price adjustments: fixed amount, fixed price, and percentage.
45+
- **Issue: Getting "Cannot read properties of undefined" when accessing selling plan data**
46+
**Solution**: Add null checks when accessing selling plan data, as not all products have selling plans. Use optional chaining (`?.`) and nullish coalescing (`??`) operators.
47+
- **Issue: Subscription options appear but selecting them doesn't affect the price**
48+
**Solution**: Ensure the `SellingPlanPrice` component correctly calculates discounted prices based on the price adjustment type.
49+
- **Issue: Selected subscription doesn't persist when navigating back to product**
50+
**Solution**: Make sure your URL includes the `selling_plan` parameter and that your product route correctly processes this parameter.
51+
- **Issue: Subscription details not appearing in cart**
52+
**Solution**: Verify that your cart query includes the `sellingPlanAllocation` fragment and that the Cart component displays this information.
53+
- **Issue: Subscribe button disabled even though selling plans are available**
54+
**Solution**: Check the condition in your AddToCartButton component. It should only be disabled if no selling plan is selected when selling plans are available.
55+
- **Issue: Multiple subscription groups causing UI confusion**
56+
**Solution**: Implement a tabbed interface or clear labeling if your products have multiple subscription group options.
57+
- **Issue: CSS for subscription selector not applying**
58+
**Solution**: Ensure you've added the `selling-plan.css` import and that the stylesheet is correctly linked in your component.
59+
- **Issue: Cannot read `sellingPlanGroups.nodes` of undefined**
60+
**Solution**: Add null check logic: `{product?.sellingPlanGroups?.nodes?.length > 0 ? ... : ...}`
61+
</troubleshooting>
62+
63+
# Recipe Implementation
64+
1865
Here's the subscriptions recipe for the base Hydrogen skeleton template:
1966

20-
--- BEGIN RECIPE DATA ---
67+
<recipe_implementation>
2168

2269
## Description
2370

24-
This folder contains an example implementation of [subscriptions](https://shopify.dev/docs/apps/selling-strategies/subscriptions) for Hydrogen. It shows how to display selling plans on a product page.
71+
This folder contains an example implementation of [subscriptions](mdc:https:/shopify.dev/docs/apps/selling-strategies/subscriptions) for Hydrogen. It shows how to display selling plans on a product page.
2572

26-
![subscriptions-example](https://github.com/Shopify/hydrogen/assets/12080141/1cea5fbf-5a56-4562-95a7-4821facb3c6d)
73+
![subscriptions-example](mdc:https:/github.com/Shopify/hydrogen/assets/12080141/1cea5fbf-5a56-4562-95a7-4821facb3c6d)
2774

2875
## Ingredients
2976

@@ -39,7 +86,7 @@ This example is connected to the `hydrogen-preview` storefront which contains on
3986

4087
To run this example on your own store, you'll need to:
4188

42-
- Install a [subscription app](https://apps.shopify.com/shopify-subscriptions).
89+
- Install a [subscription app](mdc:https:/apps.shopify.com/shopify-subscriptions).
4390
- Use the subscription app to create a selling plan for a product.
4491

4592
### 2. Copy ingredients
@@ -55,7 +102,7 @@ Copy the ingredients from the template directory to the current directory.
55102
- get the selling plan allocation.
56103
- Optionally render the selling plan name if available.
57104

58-
#### File: [`app/components/CartLineItem.tsx`](/templates/skeleton/app/components/CartLineItem.tsx)
105+
#### File: [`app/components/CartLineItem.tsx`](mdc:templates/skeleton/app/components/CartLineItem.tsx)
59106

60107
```diff
61108
index 26102b61..dcab4454 100644
@@ -103,7 +150,7 @@ index 26102b61..dcab4454 100644
103150

104151

105152

106-
#### File: [`app/lib/fragments.ts`](/templates/skeleton/app/lib/fragments.ts)
153+
#### File: [`app/lib/fragments.ts`](mdc:templates/skeleton/app/lib/fragments.ts)
107154

108155
<details>
109156

@@ -199,7 +246,7 @@ index dc4426a9..92b8da62 100644
199246

200247

201248

202-
#### File: [`app/routes/_index.tsx`](/templates/skeleton/app/routes/_index.tsx)
249+
#### File: [`app/routes/_index.tsx`](mdc:templates/skeleton/app/routes/_index.tsx)
203250

204251
<details>
205252

@@ -412,7 +459,7 @@ index 9fa33642..2023c689 100644
412459
- Add the SellingPlanGroup fragment to the Product fragment.
413460
- Add the SellingPlanGroup fragment to the Product fragment.
414461

415-
#### File: [`app/routes/products.$handle.tsx`](/templates/skeleton/app/routes/products.$handle.tsx)
462+
#### File: [`app/routes/products.$handle.tsx`](mdc:templates/skeleton/app/routes/products.$handle.tsx)
416463

417464
<details>
418465

@@ -1205,7 +1252,7 @@ index 0028b423..a8081f02 100644
12051252

12061253

12071254

1208-
#### File: [`storefrontapi.generated.d.ts`](/templates/skeleton/storefrontapi.generated.d.ts)
1255+
#### File: [`storefrontapi.generated.d.ts`](mdc:templates/skeleton/storefrontapi.generated.d.ts)
12091256

12101257
<details>
12111258

@@ -1992,6 +2039,6 @@ index d27c5942..5696f7c9 100644
19922039

19932040
## Deleted Files
19942041

1995-
- [`templates/skeleton/app/components/ProductForm.tsx`](templates/skeleton/app/components/ProductForm.tsx)
2042+
- [`templates/skeleton/app/components/ProductForm.tsx`](mdc:templates/skeleton/app/components/ProductForm.tsx)
19962043

1997-
--- END RECIPE DATA ---
2044+
</recipe_implementation>

cookbook/recipes/subscriptions/recipe.json

+61-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
11
{
22
"title": "Subscriptions",
33
"image": null,
4+
"userQueries": [
5+
"How do I add subscription options to my Hydrogen store?",
6+
"I want to let customers subscribe to products in my Shopify Hydrogen site",
7+
"Can you help me implement recurring orders in Hydrogen?",
8+
"How to show subscription pricing on product page in Hydrogen?",
9+
"Need help adding a 'Subscribe and Save' option to my products",
10+
"How do I modify the cart to show subscription details?",
11+
"Making a subscription box with Hydrogen and Shopify",
12+
"I've set up selling plans in Shopify admin, how do I display them in Hydrogen?",
13+
"Help implementing Shopify subscriptions in my Hydrogen storefront",
14+
"My selling plans aren't showing up in my Hydrogen store",
15+
"How to calculate and display subscription discounts in Hydrogen?",
16+
"Adding monthly subscription billing to Hydrogen products",
17+
"Implementing 'delivery every X weeks' options in Hydrogen",
18+
"How to let customers choose between one-time purchase and subscription?",
19+
"Setting up recurring delivery options on my Hydrogen product page"
20+
],
21+
"troubleshooting": [
22+
{
23+
"issue": "Subscription options not appearing on product page",
24+
"solution": "Verify that you've created selling plans in Shopify admin and attached them to the product. Also ensure the `sellingPlanGroups` fragment is included in your product query."
25+
},
26+
{
27+
"issue": "Price calculations for subscriptions appear incorrect",
28+
"solution": "Check the selling plan price adjustments in your query. Make sure you're handling all three types of price adjustments: fixed amount, fixed price, and percentage."
29+
},
30+
{
31+
"issue": "Getting \"Cannot read properties of undefined\" when accessing selling plan data",
32+
"solution": "Add null checks when accessing selling plan data, as not all products have selling plans. Use optional chaining (`?.`) and nullish coalescing (`??`) operators."
33+
},
34+
{
35+
"issue": "Subscription options appear but selecting them doesn't affect the price",
36+
"solution": "Ensure the `SellingPlanPrice` component correctly calculates discounted prices based on the price adjustment type."
37+
},
38+
{
39+
"issue": "Selected subscription doesn't persist when navigating back to product",
40+
"solution": "Make sure your URL includes the `selling_plan` parameter and that your product route correctly processes this parameter."
41+
},
42+
{
43+
"issue": "Subscription details not appearing in cart",
44+
"solution": "Verify that your cart query includes the `sellingPlanAllocation` fragment and that the Cart component displays this information."
45+
},
46+
{
47+
"issue": "Subscribe button disabled even though selling plans are available",
48+
"solution": "Check the condition in your AddToCartButton component. It should only be disabled if no selling plan is selected when selling plans are available."
49+
},
50+
{
51+
"issue": "Multiple subscription groups causing UI confusion",
52+
"solution": "Implement a tabbed interface or clear labeling if your products have multiple subscription group options."
53+
},
54+
{
55+
"issue": "CSS for subscription selector not applying",
56+
"solution": "Ensure you've added the `selling-plan.css` import and that the stylesheet is correctly linked in your component."
57+
},
58+
{
59+
"issue": "Cannot read `sellingPlanGroups.nodes` of undefined",
60+
"solution": "Add null check logic: `{product?.sellingPlanGroups?.nodes?.length > 0 ? ... : ...}`"
61+
}
62+
],
463
"description": "This folder contains an example implementation of [subscriptions](https://shopify.dev/docs/apps/selling-strategies/subscriptions) for Hydrogen. It shows how to display selling plans on a product page.\n\n![subscriptions-example](https://github.com/Shopify/hydrogen/assets/12080141/1cea5fbf-5a56-4562-95a7-4821facb3c6d)",
564
"notes": [],
6-
"deletedFiles": [
7-
"templates/skeleton/app/components/ProductForm.tsx"
8-
],
65+
"deletedFiles": ["templates/skeleton/app/components/ProductForm.tsx"],
966
"ingredients": [
1067
{
1168
"path": "templates/skeleton/app/components/Cart.tsx",
@@ -92,4 +149,4 @@
92149
}
93150
],
94151
"commit": "bc81bbdd33dc2bccf6d3535e0d89b13de1400e1a"
95-
}
152+
}

cookbook/src/lib/generate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export async function generateRecipe(params: {
9898
const recipe: Recipe = {
9999
title: existingRecipe?.title ?? recipeName,
100100
image: existingRecipe?.image ?? null,
101+
userQueries: existingRecipe?.userQueries ?? [],
102+
troubleshooting: existingRecipe?.troubleshooting ?? [],
101103
description: existingRecipe?.description ?? TODO,
102104
notes: existingRecipe?.notes ?? [],
103105
deletedFiles,

cookbook/src/lib/llms.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ function renderRecipeRuleBlocks(
137137

138138
// preamble
139139
mdParagraph(
140-
`This rule describes how to implement "\`${recipe.title} (${recipeName})\`" in a Hydrogen storefront. Below is a "recipe" that contains the steps to apply to a basic Hydrogen skeleton template to achieve the desired outcome.
140+
`
141+
# Overview
142+
143+
This rule describes how to implement "${
144+
recipe.title
145+
} (${recipeName})" in a Hydrogen storefront. Below is a "recipe" that contains the steps to apply to a basic Hydrogen skeleton template to achieve the desired outcome.
141146
The same logic can be applied to any other Hydrogen storefront project, adapting the implementation details to the specific needs/structure/conventions of the project, but it's up to the developer to do so.
142147
143148
If there are any prerequisites, the recipe below will explain them; if the user is trying to implement the feature described in this recipe, make sure to prominently mention the prerequisites and any other preliminary instructions, as well as followups.
@@ -148,11 +153,29 @@ If the user is asking on how to implement the feature from scratch, please first
148153
149154
Please note that the recipe steps below are not necessarily ordered in the way they should be executed, as it depends on the user's needs and the specific details of the project. The recipe steps descriptions should allow you to understand what is required to be done in a certain order and what is not. Remember that file names in the recipe are related to the Hydrogen skeleton template, not the user's project, so make sure to adapt the file names to the user's project.
150155
151-
Here's the ${recipeName} recipe for the base Hydrogen skeleton template:`,
156+
# User Intent Recognition
157+
<user_queries>
158+
${recipe.userQueries.map((query) => `- ${query}`).join('\n')}
159+
</user_queries>
160+
161+
# Troubleshooting
162+
<troubleshooting>
163+
${recipe.troubleshooting
164+
.map(
165+
(troubleshooting) =>
166+
`- **Issue: ${troubleshooting.issue}**\n **Solution**: ${troubleshooting.solution}`,
167+
)
168+
.join('\n')}
169+
</troubleshooting>
170+
171+
# Recipe Implementation
172+
173+
Here's the ${recipeName} recipe for the base Hydrogen skeleton template:
174+
`.trim(),
152175
),
153176

154177
// recipe data
155-
mdParagraph(`--- BEGIN RECIPE DATA ---`),
178+
mdParagraph(`<recipe_implementation>`),
156179
...[
157180
mdHeading(2, 'Description'),
158181
mdParagraph(recipe.description),
@@ -189,7 +212,7 @@ Here's the ${recipeName} recipe for the base Hydrogen skeleton template:`,
189212
]
190213
: []),
191214
],
192-
mdParagraph(`--- END RECIPE DATA ---`),
215+
mdParagraph(`</recipe_implementation>`),
193216
];
194217
}
195218

cookbook/src/lib/recipe.ts

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ const RecipeSchema = z.object({
5252
.optional()
5353
.describe('The deleted files of the recipe'),
5454
commit: z.string().describe('The commit hash the recipe is based on'),
55+
userQueries: z
56+
.array(z.string())
57+
.optional()
58+
.describe('The user queries of the recipe')
59+
.default([]),
60+
troubleshooting: z
61+
.array(
62+
z.object({
63+
issue: z.string().describe('The issue of the troubleshooting'),
64+
solution: z.string().describe('The solution of the troubleshooting'),
65+
}),
66+
)
67+
.optional()
68+
.describe('The troubleshooting of the recipe')
69+
.default([]),
5570
});
5671

5772
export type Recipe = z.infer<typeof RecipeSchema>;

0 commit comments

Comments
 (0)