@rebuy/rebuy-hydrogen 1.0.0-rc.3 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -31
- package/RebuyWidgetContainer.client.jsx +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -48,13 +48,13 @@ If you want to [integrate with an existing React framework](https://shopify.dev/
|
|
48
48
|
|
49
49
|
#### 1. Navigate to your working directoy
|
50
50
|
Navigate to the directory where you want to create your project and run the following command:
|
51
|
-
```
|
51
|
+
```bash
|
52
52
|
cd <directory>
|
53
53
|
```
|
54
54
|
|
55
55
|
#### 2. Create your project
|
56
56
|
Create a new Hydrogen project with a default template linked to a demo-store with the following command:
|
57
|
-
```
|
57
|
+
```bash
|
58
58
|
npm init @shopify/hydrogen -- --template demo-store
|
59
59
|
```
|
60
60
|
|
@@ -70,12 +70,15 @@ Open `hydrogen.config.js` file located in the root of your project directory.
|
|
70
70
|
|
71
71
|
#### 2. Update your config file
|
72
72
|
Edit your `hydrogen.config.js` file with the following changes and save the file:
|
73
|
-
- Update storeDomain to specify your store's domain name.
|
74
|
-
- Update storefrontToken to specify your Storefront API access token.
|
75
|
-
- Update storefrontApiVersion to specify the Storefront API version that you want to use.
|
76
|
-
|
73
|
+
- Update `storeDomain` to specify your store's domain name.
|
74
|
+
- Update `storefrontToken` to specify your Storefront API access token.
|
75
|
+
- Update `storefrontApiVersion` to specify the Storefront API version that you want to use.
|
76
|
+
|
77
|
+
```javascript
|
77
78
|
export default defineConfig({
|
78
79
|
shopify: {
|
80
|
+
defaultCountryCode: 'US',
|
81
|
+
defaultLanguageCode: 'EN',
|
79
82
|
storeDomain: 'YOUR_STORE_NAME.myshopify.com',
|
80
83
|
storefrontToken: 'YOUR_STOREFRONT_ACCESS_TOKEN',
|
81
84
|
storefrontApiVersion: '2022-07',
|
@@ -89,13 +92,13 @@ Create a new local development server to start testing your changes.
|
|
89
92
|
|
90
93
|
#### 1. Navigate to your project directoy
|
91
94
|
Navigate to the root of your project directory:
|
92
|
-
```
|
95
|
+
```bash
|
93
96
|
cd <directory>
|
94
97
|
```
|
95
98
|
|
96
99
|
#### 2. Start the development server
|
97
100
|
Start up a new local development server on `localhost`:
|
98
|
-
```
|
101
|
+
```bash
|
99
102
|
npm run dev
|
100
103
|
```
|
101
104
|
|
@@ -107,13 +110,13 @@ Once you have successfully created your new Hydrogen app and linked it to your S
|
|
107
110
|
|
108
111
|
#### 1. Navigate to your project directoy
|
109
112
|
Navigate to the root of your project directory:
|
110
|
-
```
|
113
|
+
```bash
|
111
114
|
cd <directory>
|
112
115
|
```
|
113
116
|
|
114
117
|
#### 2. Install the Rebuy + Hydrogen package
|
115
118
|
Install the Rebuy + Hydrogen package from [npm](https://www.npmjs.com/) with the following command:
|
116
|
-
```
|
119
|
+
```bash
|
117
120
|
npm install @rebuy/rebuy-hydrogen
|
118
121
|
```
|
119
122
|
|
@@ -134,7 +137,8 @@ Once you have included Rebuy + Hydrogen in your project, it's time to start buil
|
|
134
137
|
|
135
138
|
#### 1. Create a Recommended Products Component
|
136
139
|
Create a new file in `src/components` called `ProductRecommendations.jsx`, and add the following to the file:
|
137
|
-
|
140
|
+
|
141
|
+
```javascript
|
138
142
|
import {
|
139
143
|
ProductOptionsProvider,
|
140
144
|
AddToCartButton,
|
@@ -145,7 +149,7 @@ import {
|
|
145
149
|
} from './Button.client';
|
146
150
|
|
147
151
|
function AddToCartMarkup({product}) {
|
148
|
-
const selectedVariant = product.variants.
|
152
|
+
const selectedVariant = product.variants.nodes[0];
|
149
153
|
const isOutOfStock = !selectedVariant.availableForSale;
|
150
154
|
|
151
155
|
return (
|
@@ -177,7 +181,7 @@ export default function ProductRecommendations(props) {
|
|
177
181
|
<ul className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-16">
|
178
182
|
{products.map((product) => (
|
179
183
|
<li key={product.id}>
|
180
|
-
<ProductOptionsProvider data={product} initialVariantId={product.variants.
|
184
|
+
<ProductOptionsProvider data={product} initialVariantId={product.variants.nodes[0].id}>
|
181
185
|
<ProductCard product={product} />
|
182
186
|
<AddToCartMarkup product={product} />
|
183
187
|
</ProductOptionsProvider>
|
@@ -191,7 +195,8 @@ export default function ProductRecommendations(props) {
|
|
191
195
|
|
192
196
|
#### 2. Create a Recently Viewed Products Component
|
193
197
|
Create a new file in `src/components` called `RecentlyViewedProducts.jsx`, and add the following to the file:
|
194
|
-
|
198
|
+
|
199
|
+
```javascript
|
195
200
|
import {
|
196
201
|
ProductOptionsProvider,
|
197
202
|
AddToCartButton,
|
@@ -202,7 +207,7 @@ import {
|
|
202
207
|
} from './Button.client';
|
203
208
|
|
204
209
|
function AddToCartMarkup({product}) {
|
205
|
-
const selectedVariant = product.variants.
|
210
|
+
const selectedVariant = product.variants.nodes[0];
|
206
211
|
const isOutOfStock = !selectedVariant.availableForSale;
|
207
212
|
|
208
213
|
return (
|
@@ -234,7 +239,7 @@ export default function RecentlyViewedProducts(props) {
|
|
234
239
|
<ul className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-16">
|
235
240
|
{products.map((product) => (
|
236
241
|
<li key={product.id}>
|
237
|
-
<ProductOptionsProvider data={product} initialVariantId={product.variants.
|
242
|
+
<ProductOptionsProvider data={product} initialVariantId={product.variants.nodes[0].id}>
|
238
243
|
<ProductCard product={product} />
|
239
244
|
<AddToCartMarkup product={product} />
|
240
245
|
</ProductOptionsProvider>
|
@@ -249,14 +254,14 @@ export default function RecentlyViewedProducts(props) {
|
|
249
254
|
#### 3. Install the RebuyContextProvider
|
250
255
|
Open `/src/App.server.jsx` file and install the `RebuyContextProvider`, so all Rebuy API calls are enriched with contextual information. Open the file and make the following edits:
|
251
256
|
|
252
|
-
##### Import
|
253
|
-
```
|
257
|
+
##### Import the provider
|
258
|
+
```javascript
|
254
259
|
import {RebuyContextProvider} from '@rebuy/rebuy-hydrogen/RebuyContextProvider.client';
|
255
260
|
```
|
256
261
|
|
257
262
|
##### Add RebuyContextProvider component
|
258
263
|
Wrap the `<Route>` component with the `RebuyContextProvider`, as follows:
|
259
|
-
```
|
264
|
+
```html
|
260
265
|
<RebuyContextProvider>
|
261
266
|
<Route path="*" page={<NotFound />} />
|
262
267
|
</RebuyContextProvider>
|
@@ -267,21 +272,21 @@ Let's include our new components to the `ProductDetails` client component, locat
|
|
267
272
|
|
268
273
|
##### Import your new UI components
|
269
274
|
Import the `ProductRecommendations` and `RecentlyViewedProducts` components in to the `ProductDetails.client.jsx` file.
|
270
|
-
```
|
275
|
+
```javascript
|
271
276
|
import ProductRecommendations from './ProductRecommendations';
|
272
277
|
import RecentlyViewedProducts from './RecentlyViewedProducts';
|
273
278
|
```
|
274
279
|
|
275
280
|
##### Import Rebuy components
|
276
281
|
Import the `RebuyWidgetContainer` and `RebuyProductViewed` components in to the `ProductDetails.client.jsx` file.
|
277
|
-
```
|
282
|
+
```javascript
|
278
283
|
import RebuyWidgetContainer from '@rebuy/rebuy-hydrogen/RebuyWidgetContainer.client';
|
279
284
|
import RebuyProductViewed from '@rebuy/rebuy-hydrogen/RebuyProductViewed.client';
|
280
285
|
```
|
281
286
|
|
282
287
|
##### Add imported components in to the `ProductDetails` functional component
|
283
288
|
Before the closing `</ProductOptionsProvider>` tag, insert our imported components:
|
284
|
-
```
|
289
|
+
```html
|
285
290
|
<RebuyWidgetContainer product={product} dataSource="/api/v1/products/recommended" limit="6">
|
286
291
|
<ProductRecommendations />
|
287
292
|
</RebuyWidgetContainer>
|
@@ -309,24 +314,30 @@ The `RebuyContextProvider` is a React provider component. It is responsible for
|
|
309
314
|
|
310
315
|
The `RebuyContextProvider` is a client component, which means it renders in the browser. It has two dependencies, which are `useUrl` and `useCart`, so the component should be located high up in the component tree but **below** the `ShopifyProvider` and `CartProvider`.
|
311
316
|
|
312
|
-
The recommended location is in `src/App.server.jsx` and wrapping the `<Route>`
|
317
|
+
The recommended location is in `src/App.server.jsx` inside `<Router>` and wrapping **both** `<FileRoutes>` and the `<Route>` components, which makes the `RebuyContext` automatically available on all pages across the site.
|
313
318
|
|
314
319
|
#### Import the RebuyContextProvider
|
315
|
-
```
|
320
|
+
```javascript
|
316
321
|
import {RebuyContextProvider} from '@rebuy/rebuy-hydrogen/RebuyContextProvider.client';
|
317
322
|
```
|
318
323
|
|
319
324
|
#### Wrap the Route compontent with RebuyContextProvider
|
320
|
-
```
|
321
|
-
<
|
322
|
-
<
|
323
|
-
|
325
|
+
```html
|
326
|
+
<Router>
|
327
|
+
<RebuyContextProvider>
|
328
|
+
<FileRoutes
|
329
|
+
basePath={countryCode ? `/${countryCode}/` : undefined}
|
330
|
+
routes={routes}
|
331
|
+
/>
|
332
|
+
<Route path="*" page={<NotFound />} />
|
333
|
+
</RebuyContextProvider>
|
334
|
+
</Router>
|
324
335
|
```
|
325
336
|
|
326
337
|
#### Access RebuyContext
|
327
338
|
Rebuy + Hydrogen components will automatically include and use `RebuyContext`, but if you would like to use this context information in your own components, you certainly can!
|
328
339
|
|
329
|
-
```
|
340
|
+
```javascript
|
330
341
|
import React from 'react';
|
331
342
|
import {RebuyContext} from '@rebuy/rebuy-hydrogen/RebuyContextProvider.client';
|
332
343
|
|
@@ -365,7 +376,7 @@ In the following example, we are using an example compontent called `ProductReco
|
|
365
376
|
|
366
377
|
When the components are rendered, it will display `6` products powered by Rebuy's AI algorithm based on the provided input `product`. So if the input product was ketchup, you would likely see recommended products like mustard, mayo, or other condiments.
|
367
378
|
|
368
|
-
```
|
379
|
+
```javascript
|
369
380
|
import ProductRecommendations from './ProductRecommendations';
|
370
381
|
import RebuyWidgetContainer from '@rebuy/rebuy-hydrogen/RebuyWidgetContainer.client';
|
371
382
|
|
@@ -389,7 +400,7 @@ The component accepts argments via props to allow for registering different prod
|
|
389
400
|
#### Example implementation
|
390
401
|
The following example would be included in the `ProductDetails.client.jsx` component to automatically register customer product view events. The current product displayed is passed to the `RebuyProductViewed` component via props as `product={product}`.
|
391
402
|
|
392
|
-
```
|
403
|
+
```javascript
|
393
404
|
import RebuyProductViewed from '@rebuy/rebuy-hydrogen/RebuyProductViewed.client';
|
394
405
|
|
395
406
|
<RebuyProductViewed product={product} />
|
@@ -56,7 +56,17 @@ export default function RebuyWidgetContainer(props) {
|
|
56
56
|
|
57
57
|
useEffect(() => {
|
58
58
|
fetchData();
|
59
|
-
}, [
|
59
|
+
}, [
|
60
|
+
product,
|
61
|
+
productId,
|
62
|
+
variant,
|
63
|
+
variantId,
|
64
|
+
collection,
|
65
|
+
collectionId,
|
66
|
+
dataSource,
|
67
|
+
limit,
|
68
|
+
options,
|
69
|
+
]);
|
60
70
|
|
61
71
|
const fetchData = async () => {
|
62
72
|
const response = await Rebuy.getStorefrontData(request.url, request.parameters);
|