Skip to content

Commit 4f5db28

Browse files
authored
Fixed cookbook steps, rendering issues, image inlining
* Fixed cookbook steps, only try to read actual text files * Trying triple tildes for code blocks * Regenerating all cookbook recipes * Fixing shopify.dev rendering of recipes * fix formatting of notes on shopify.dev render * Update recipes from feedback on shopify.dev versions * Update render command to render all recipes if none specified * in Hydrogen in Hydrogen * More shopify.dev format fixing * Switch to string only steps * Regenerate all recipes * Fixing schema * Pulling across new step names from shopify.dev PR * Fixing null descriptions in recipes * I'd accidentally overwritten descriptions rather than names
1 parent 83d81fc commit 4f5db28

File tree

128 files changed

+9880
-21654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+9880
-21654
lines changed

cookbook/llms/b2b.prompt.md

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,9 @@ with buyer information (company location + customer token) to ensure accurate B2
4747

4848
## Notes
4949

50-
> [!NOTE]
51-
> This recipe requires a Shopify Plus plan for B2B functionality
52-
53-
> [!NOTE]
54-
> Your store must use new customer accounts (not classic accounts)
55-
56-
> [!NOTE]
57-
> Only the product display page uses contextualized queries in this example
58-
5950
> [!NOTE]
6051
> For production, all product queries should be contextualized with buyer information
6152
62-
> [!NOTE]
63-
> The location selector appears automatically for customers with multiple company locations
64-
6553
## Requirements
6654

6755
- Shopify Plus plan with B2B enabled
@@ -80,13 +68,13 @@ with buyer information (company location + customer token) to ensure accurate B2
8068

8169
## Steps
8270

83-
### Step 1: README.md
84-
71+
### Step 1: Document B2B features, requirements, and implementation details in the project README
8572

73+
Update the README file with comprehensive B2B commerce documentation, explaining features like company locations, quantity rules, and volume pricing implementation
8674

8775
#### File: /README.md
8876

89-
```diff
77+
~~~diff
9078
@@ -18,6 +18,45 @@ Hydrogen is Shopify’s stack for headless commerce. Hydrogen is designed to dov
9179
- TypeScript and JavaScript flavors
9280
- Minimal setup of components and routes
@@ -133,15 +121,15 @@ with buyer information (company location + customer token) to ensure accurate B2
133121
## Getting started
134122

135123
**Requirements:**
136-
```
124+
~~~
137125

138-
### Step 1: app/components/B2BLocationProvider.tsx
126+
### Step 2: Create a React context provider to manage company location state across the app
139127

128+
Create a React context provider that manages the selected company location state and provides location switching functionality throughout the B2B application
140129

130+
#### File: [B2BLocationProvider.tsx](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/B2BLocationProvider.tsx)
141131

142-
#### File: [B2BLocationProvider.tsx](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/B2BLocationProvider.tsx)
143-
144-
```tsx
132+
~~~tsx
145133
import {createContext, useContext, useEffect, useState, useMemo} from 'react';
146134
import {useFetcher} from 'react-router';
147135
import {type CustomerCompany} from '~/root';
@@ -193,15 +181,15 @@ export function B2BLocationProvider({children}: {children: React.ReactNode}) {
193181
export function useB2BLocation(): B2BLocationContextValue {
194182
return useContext(B2BLocationContext);
195183
}
196-
```
197-
198-
### Step 2: app/components/CartLineItem.tsx
184+
~~~
199185

186+
### Step 3: Update quantity controls to respect B2B minimum, maximum, and increment rules
200187

188+
Update cart line item quantity controls to honor B2B quantity rules including minimum order quantities, maximum limits, and increment requirements
201189

202190
#### File: /app/components/CartLineItem.tsx
203191

204-
```diff
192+
~~~diff
205193
@@ -76,8 +76,13 @@ export function CartLineItem({
206194
function CartLineQuantity({line}: {line: CartLine}) {
207195
if (!line || typeof line?.quantity === 'undefined') return null;
@@ -238,15 +226,15 @@ export function useB2BLocation(): B2BLocationContextValue {
238226
>
239227
<span>&#43;</span>
240228
</button>
241-
```
229+
~~~
242230

243-
### Step 2: app/components/B2BLocationSelector.tsx
231+
### Step 4: Build a modal that lets customers choose which company location to use for pricing
244232

233+
Create a modal component that displays available company locations and allows B2B customers to select the appropriate location for contextualized pricing
245234

235+
#### File: [B2BLocationSelector.tsx](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/B2BLocationSelector.tsx)
246236

247-
#### File: [B2BLocationSelector.tsx](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/B2BLocationSelector.tsx)
248-
249-
```tsx
237+
~~~tsx
250238
import {CartForm} from '@shopify/hydrogen';
251239
import type {
252240
CustomerCompanyLocation,
@@ -317,15 +305,15 @@ export function B2BLocationSelector() {
317305
</div>
318306
);
319307
}
320-
```
321-
322-
### Step 3: app/components/Header.tsx
308+
~~~
323309

310+
### Step 5: Add a location selector button to the header for switching between company locations
324311

312+
Add a location selector button to the site header that allows B2B customers to easily switch between their company's different locations
325313

326314
#### File: /app/components/Header.tsx
327315

328-
```diff
316+
~~~diff
329317
@@ -7,6 +7,9 @@ import {
330318
} from '@shopify/hydrogen';
331319
import type {HeaderQuery, CartApiQueryFragment} from 'storefrontapi.generated';
@@ -375,15 +363,15 @@ export function B2BLocationSelector() {
375363
const FALLBACK_HEADER_MENU = {
376364
id: 'gid://shopify/Menu/199655587896',
377365
items: [
378-
```
379-
380-
### Step 3: app/components/PriceBreaks.tsx
366+
~~~
381367

368+
### Step 6: Display volume pricing tiers that show bulk purchase discounts
382369

370+
Create a component that displays volume pricing breaks, showing customers the discounted prices they'll receive for bulk purchases at different quantity thresholds
383371

384-
#### File: [PriceBreaks.tsx](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/PriceBreaks.tsx)
372+
#### File: [PriceBreaks.tsx](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/PriceBreaks.tsx)
385373

386-
```tsx
374+
~~~tsx
387375
import {Money} from '@shopify/hydrogen';
388376
import type {MoneyV2} from '@shopify/hydrogen/storefront-api-types';
389377

@@ -423,15 +411,15 @@ export function PriceBreaks({priceBreaks}: PriceBreaksProps) {
423411
</>
424412
);
425413
}
426-
```
427-
428-
### Step 4: app/components/ProductForm.tsx
414+
~~~
429415

416+
### Step 7: Accept quantity parameter to support B2B minimum quantity and increment rules
430417

418+
Update the ProductForm component to accept and handle quantity parameters that enforce B2B minimum quantities and increment rules when adding products to cart
431419

432420
#### File: /app/components/ProductForm.tsx
433421

434-
```diff
422+
~~~diff
435423
@@ -8,12 +8,15 @@ import {AddToCartButton} from './AddToCartButton';
436424
import {useAside} from './Aside';
437425
import type {ProductFragment} from 'storefrontapi.generated';
@@ -458,15 +446,15 @@ export function PriceBreaks({priceBreaks}: PriceBreaksProps) {
458446
selectedVariant,
459447
},
460448
]
461-
```
462-
463-
### Step 4: app/components/QuantityRules.tsx
449+
~~~
464450

451+
### Step 8: Show minimum, maximum, and increment quantity requirements for B2B products
465452

453+
Create a component that displays B2B quantity rules to customers, showing minimum order quantities, maximum limits, and required increments for business products
466454

467-
#### File: [QuantityRules.tsx](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/QuantityRules.tsx)
455+
#### File: [QuantityRules.tsx](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/components/QuantityRules.tsx)
468456

469-
```tsx
457+
~~~tsx
470458
import type {Maybe} from '@shopify/hydrogen/customer-account-api-types';
471459

472460
export type QuantityRulesProps = {
@@ -511,15 +499,15 @@ export function QuantityRules({
511499
</>
512500
);
513501
}
514-
```
515-
516-
### Step 5: app/lib/fragments.ts
502+
~~~
517503

504+
### Step 9: Add quantity rules and price breaks to cart GraphQL fragments
518505

506+
Update GraphQL fragments to include quantity rules and price break data needed for B2B functionality in cart queries
519507

520508
#### File: /app/lib/fragments.ts
521509

522-
```diff
510+
~~~diff
523511
@@ -52,6 +52,21 @@ export const CART_QUERY_FRAGMENT = `#graphql
524512
name
525513
value
@@ -564,15 +552,15 @@ export function QuantityRules({
564552
}
565553
}
566554
}
567-
```
555+
~~~
568556

569-
### Step 5: app/graphql/customer-account/CustomerLocationsQuery.ts
557+
### Step 10: Query company locations from the Customer Account API for B2B customers
570558

559+
Create a GraphQL query that fetches all available company locations for B2B customers from the Customer Account API
571560

561+
#### File: [CustomerLocationsQuery.ts](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/graphql/customer-account/CustomerLocationsQuery.ts)
572562

573-
#### File: [CustomerLocationsQuery.ts](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/graphql/customer-account/CustomerLocationsQuery.ts)
574-
575-
```ts
563+
~~~ts
576564
// NOTE: https://shopify.dev/docs/api/customer/latest/objects/Customer
577565
export const CUSTOMER_LOCATIONS_QUERY = `#graphql
578566
query CustomerLocations {
@@ -606,15 +594,15 @@ export const CUSTOMER_LOCATIONS_QUERY = `#graphql
606594
}
607595
}
608596
` as const;
609-
```
610-
611-
### Step 6: app/root.tsx
597+
~~~
612598

599+
### Step 11: Wrap the app with B2B location provider and add company location types
613600

601+
Wrap the application with the B2B location provider context and add TypeScript type definitions for company location data
614602

615603
#### File: /app/root.tsx
616604

617-
```diff
605+
~~~diff
618606
@@ -16,9 +16,39 @@ import {FOOTER_QUERY, HEADER_QUERY} from '~/lib/fragments';
619607
import resetStyles from '~/styles/reset.css?url';
620608
import appStyles from '~/styles/app.css?url';
@@ -672,15 +660,15 @@ export const CUSTOMER_LOCATIONS_QUERY = `#graphql
672660
</Analytics.Provider>
673661
);
674662
}
675-
```
676-
677-
### Step 6: app/routes/b2blocations.tsx
663+
~~~
678664

665+
### Step 12: Handle location selection and automatically set location if customer has only one
679666

667+
Create a route handler that processes location selection requests and automatically sets the location if a B2B customer only has access to one company location
680668

681-
#### File: [b2blocations.tsx](https://github.com/Shopify/hydrogen/blob/25290311dd1d135ab90bca26fb496d2b92c8631a/cookbook/recipes/b2b/ingredients/templates/skeleton/app/routes/b2blocations.tsx)
669+
#### File: [b2blocations.tsx](https://github.com/Shopify/hydrogen/blob/0511444a026f5b80c3927fbc2e31b1ab827cfeae/cookbook/recipes/b2b/ingredients/templates/skeleton/app/routes/b2blocations.tsx)
682670

683-
```tsx
671+
~~~tsx
684672
import {useLoaderData} from 'react-router';
685673
import type {Route} from './+types/b2blocations';
686674
import {B2BLocationSelector} from '../components/B2BLocationSelector';
@@ -719,15 +707,15 @@ export async function loader({context}: Route.LoaderArgs) {
719707
export default function CartRoute() {
720708
return <B2BLocationSelector />;
721709
}
722-
```
723-
724-
### Step 7: app/routes/account_.logout.tsx
710+
~~~
725711

712+
### Step 13: Clear company location and customer data from cart when logging out
726713

714+
Update the logout process to clear B2B-specific data including selected company location and customer context from the cart session
727715

728716
#### File: /app/routes/account_.logout.tsx
729717

730-
```diff
718+
~~~diff
731719
@@ -7,5 +7,10 @@ export async function loader() {
732720
}
733721

@@ -739,15 +727,15 @@ export default function CartRoute() {
739727
+ });
740728
return context.customerAccount.logout();
741729
}
742-
```
743-
744-
### Step 8: app/routes/products.$handle.tsx
730+
~~~
745731

732+
### Step 14: Contextualize product queries with buyer information and display B2B pricing details
746733

734+
Update product queries to include buyer context (company location and customer token) and display B2B-specific pricing, quantity rules, and volume discounts on product pages
747735

748736
#### File: /app/routes/products.$handle.tsx
749737

750-
```diff
738+
~~~diff
751739
@@ -15,6 +15,19 @@ import {ProductPrice} from '~/components/ProductPrice';
752740
import {ProductImage} from '~/components/ProductImage';
753741
import {ProductForm} from '~/components/ProductForm';
@@ -889,6 +877,6 @@ export default function CartRoute() {
889877
product(handle: $handle) {
890878
...Product
891879
}
892-
```
880+
~~~
893881

894882
</recipe_implementation>

0 commit comments

Comments
 (0)