@okendo/shopify-hydrogen 1.0.3 → 1.2.1
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/LICENSE.txt +2 -2
- package/README.md +628 -628
- package/dist/esnext/client-components/OkendoClientStarRating.client.js +2 -3
- package/dist/esnext/client-components/OkendoWidget.client.js +7 -4
- package/dist/esnext/components/OkendoProvider.server.js +13 -14
- package/dist/esnext/components/OkendoReviewsWidget.server.js +16 -17
- package/dist/esnext/components/OkendoStarRating.server.js +9 -10
- package/dist/esnext/fragments/index.js +9 -9
- package/dist/esnext/framework/plugins/plugin.js +0 -2
- package/dist/node/framework/plugins/plugin.js +0 -2
- package/package.json +58 -61
- package/plugin.cjs +1 -1
- package/dist/esnext/framework/plugins/extendViteOptimizeDeps.d.ts +0 -2
- package/dist/esnext/framework/plugins/extendViteOptimizeDeps.js +0 -10
- package/dist/node/framework/plugins/extendViteOptimizeDeps.d.ts +0 -2
- package/dist/node/framework/plugins/extendViteOptimizeDeps.js +0 -14
package/README.md
CHANGED
|
@@ -1,628 +1,628 @@
|
|
|
1
|
-
# Okendo Hydrogen React Components
|
|
2
|
-
|
|
3
|
-
This is the React component library to support Okendo Widget Plus Widgets in Shopify Hydrogen Projects.
|
|
4
|
-
|
|
5
|
-
Currently we provide the following components:
|
|
6
|
-
|
|
7
|
-
### Server Components
|
|
8
|
-
|
|
9
|
-
1. [Reviews List](#components--okendo-reviews-widget)
|
|
10
|
-
2. [Star Ratings](#components--okendo-star-rating)
|
|
11
|
-
|
|
12
|
-
### Client Components
|
|
13
|
-
|
|
14
|
-
1. [Star Ratings](#components--okendo-client-star-rating)
|
|
15
|
-
|
|
16
|
-
<br/>
|
|
17
|
-
|
|
18
|
-
# Table of contents
|
|
19
|
-
|
|
20
|
-
1. [What is Okendo Shopify Hydrogen](#introduction)
|
|
21
|
-
2. [Guided Installation](#installation)
|
|
22
|
-
- [Configure Hydrogen App](#configure-hydrogen-app-config)
|
|
23
|
-
- [Expose Shopify Metafields](#expose-shopify-metafields)
|
|
24
|
-
3. [How to Use Okendo Hydrogen Components In Your Hydrogen Apps](#how-to-use-okendo-hydrogen-components-in-your-hydrogen-app)
|
|
25
|
-
4. [Components](#components)
|
|
26
|
-
5. [GraphQL Fragments](#graphql-fragments)
|
|
27
|
-
6. [View Our Okendo Sample Hydrogen App](#view-our-okendo-sample-hydrogen-app)
|
|
28
|
-
|
|
29
|
-
<br/><br/>
|
|
30
|
-
|
|
31
|
-
# What is Okendo Shopify Hydrogen? <a id="introduction" name="introduction"></a>
|
|
32
|
-
|
|
33
|
-
Okendo Shopify Hydrogen is a React component library to be used in Shopify Hydrogen apps. This utilises [Shopify’s Hydrogen framework](https://shopify.dev/custom-storefronts/hydrogen/framework) which is used to create custom storefronts using both server-side rendered and client-side rendered React components.
|
|
34
|
-
|
|
35
|
-
The purpose of this library is for a Hydrogen-based React Shopify storefront to import this library so that the Okendo Reviews List and Okendo Star Ratings components can be rendered within their React application, providing [Okendo’s reviews display functionality](https://www.okendo.io/blog/widget-plus/).
|
|
36
|
-
|
|
37
|
-
<br/>
|
|
38
|
-
|
|
39
|
-
# Guided Installation <a id="installation" name="installation"></a>
|
|
40
|
-
|
|
41
|
-
The purpose of this documentation is to guide you on the following:
|
|
42
|
-
|
|
43
|
-
- How to configure your Shopify store ready for Okendo Shopify Hydrogen.
|
|
44
|
-
- How to install and configure Okendo Shopify Hydrogen components in your Shopify Hydrogen app.
|
|
45
|
-
|
|
46
|
-
<br/>
|
|
47
|
-
|
|
48
|
-
## Requirements
|
|
49
|
-
|
|
50
|
-
- You have an existing Shopify store.
|
|
51
|
-
- You have an existing Hydrogen app. ([Learn how to create a Hydrogen app](https://shopify.dev/custom-storefronts/hydrogen/getting-started/create))
|
|
52
|
-
- You have a current Okendo Reviews subscription and have the **Okendo: Product Reviews & UCG** app installed and configured.
|
|
53
|
-
- You have an existing Shopify custom app with Storefront access token. ([Learn how to configure Shopify Storefront](https://github.com/okendo/okendo-shopify-hydrogen-demo/wiki/Configure-Shopify-Storefront-API))
|
|
54
|
-
|
|
55
|
-
<br/>
|
|
56
|
-
|
|
57
|
-
## Configure Hydrogen app config <a id="configure-hydrogen-app-config" name="configure-hydrogen-app-config"></a>
|
|
58
|
-
|
|
59
|
-
1. Open **hydrogen.config.ts** in your project.
|
|
60
|
-
2. Make the following changes and save the file:
|
|
61
|
-
- Update `storeDomain` to specify your store's domain name.
|
|
62
|
-
- Update `storefrontToken` to specify your Storefront API access token.
|
|
63
|
-
|
|
64
|
-
<br/>
|
|
65
|
-
|
|
66
|
-
## Expose Shopify Metafields <a id="expose-shopify-metafields" name="expose-shopify-metafields"></a>
|
|
67
|
-
|
|
68
|
-
Okendo Reviews utilise Product and Shop specific [metafields](https://shopify.dev/api/examples/metafields) in order to function and provide a seamless user experience. You will need to expose these metafields so that they can be retrieved by your Hydrogen app.
|
|
69
|
-
|
|
70
|
-
At this point in time, unfortunately Shopify does not have a way of exposing Shop Metafields through their admin UI.
|
|
71
|
-
|
|
72
|
-
The preferred method to expose Metafields is to [contact Okendo Support](mailto:support@okendo.io).
|
|
73
|
-
|
|
74
|
-
<br/>
|
|
75
|
-
|
|
76
|
-
### For Technical/Advanced Users
|
|
77
|
-
|
|
78
|
-
<details>
|
|
79
|
-
<summary>Learn How to Expose Metafields Via The Storefront API</summary>
|
|
80
|
-
|
|
81
|
-
## Exposing Metafields via GraphQL
|
|
82
|
-
|
|
83
|
-
### Using Curl
|
|
84
|
-
|
|
85
|
-
You can also expose the required Okendo Shopify Metafields by using GraphQL with curl.
|
|
86
|
-
|
|
87
|
-
1. Open a new terminal or PowerShell window.
|
|
88
|
-
2. Run the following command to expose the `WidgetPreRenderStyleTag` Shop Metafield.
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
curl -X POST \
|
|
92
|
-
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
93
|
-
-H 'Content-Type: application/graphql' \
|
|
94
|
-
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
95
|
-
-d '
|
|
96
|
-
mutation {
|
|
97
|
-
metafieldStorefrontVisibilityCreate(
|
|
98
|
-
input: {
|
|
99
|
-
namespace: "okendo"
|
|
100
|
-
key: "WidgetPreRenderStyleTags"
|
|
101
|
-
ownerType: SHOP
|
|
102
|
-
}
|
|
103
|
-
) {
|
|
104
|
-
metafieldStorefrontVisibility {
|
|
105
|
-
id
|
|
106
|
-
}
|
|
107
|
-
userErrors {
|
|
108
|
-
field
|
|
109
|
-
message
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
'
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
3. Run the following command to expose the `WidgetPreRenderBodyStyleTags` Shop Metafield.
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
curl -X POST \
|
|
120
|
-
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
121
|
-
-H 'Content-Type: application/graphql' \
|
|
122
|
-
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
123
|
-
-d '
|
|
124
|
-
mutation {
|
|
125
|
-
metafieldStorefrontVisibilityCreate(
|
|
126
|
-
input: {
|
|
127
|
-
namespace: "okendo"
|
|
128
|
-
key: "WidgetPreRenderBodyStyleTags"
|
|
129
|
-
ownerType: SHOP
|
|
130
|
-
}
|
|
131
|
-
) {
|
|
132
|
-
metafieldStorefrontVisibility {
|
|
133
|
-
id
|
|
134
|
-
}
|
|
135
|
-
userErrors {
|
|
136
|
-
field
|
|
137
|
-
message
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
'
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
4. Run the following command to expose the `ReviewsWidgetSnippet` Product Metafield.
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
curl -X POST \
|
|
148
|
-
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
149
|
-
-H 'Content-Type: application/graphql' \
|
|
150
|
-
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
151
|
-
-d '
|
|
152
|
-
mutation {
|
|
153
|
-
metafieldStorefrontVisibilityCreate(
|
|
154
|
-
input: {
|
|
155
|
-
namespace: "okendo"
|
|
156
|
-
key: "ReviewsWidgetSnippet"
|
|
157
|
-
ownerType: PRODUCT
|
|
158
|
-
}
|
|
159
|
-
) {
|
|
160
|
-
metafieldStorefrontVisibility {
|
|
161
|
-
id
|
|
162
|
-
}
|
|
163
|
-
userErrors {
|
|
164
|
-
field
|
|
165
|
-
message
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
'
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
5. Run the following command to expose the `StarRatingSnippet` the Product Metafield.
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
curl -X POST \
|
|
176
|
-
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
177
|
-
-H 'Content-Type: application/graphql' \
|
|
178
|
-
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
179
|
-
-d '
|
|
180
|
-
mutation {
|
|
181
|
-
metafieldStorefrontVisibilityCreate(
|
|
182
|
-
input: {
|
|
183
|
-
namespace: "okendo"
|
|
184
|
-
key: "StarRatingSnippet"
|
|
185
|
-
ownerType: PRODUCT
|
|
186
|
-
}
|
|
187
|
-
) {
|
|
188
|
-
metafieldStorefrontVisibility {
|
|
189
|
-
id
|
|
190
|
-
}
|
|
191
|
-
userErrors {
|
|
192
|
-
field
|
|
193
|
-
message
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
'
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Using GraphQL IDE
|
|
201
|
-
|
|
202
|
-
1. Open your GraphQL IDE (such as Postman) and make a `POST` request with the following details:
|
|
203
|
-
- **URL:** https://{shop}.myshopify.com/admin/api/2022-04/graphql.json
|
|
204
|
-
- **Headers:** - X-Shopify-Access-Token: {access_token} - Content-Type: application/json
|
|
205
|
-
2. Execute the following request to expose the `WidgetPreRenderStyleTag` Shop Metafield.
|
|
206
|
-
|
|
207
|
-
```graphql
|
|
208
|
-
mutation {
|
|
209
|
-
metafieldStorefrontVisibilityCreate(
|
|
210
|
-
input: {
|
|
211
|
-
namespace: "okendo"
|
|
212
|
-
key: "WidgetPreRenderStyleTags"
|
|
213
|
-
ownerType: SHOP
|
|
214
|
-
}
|
|
215
|
-
) {
|
|
216
|
-
metafieldStorefrontVisibility {
|
|
217
|
-
id
|
|
218
|
-
}
|
|
219
|
-
userErrors {
|
|
220
|
-
field
|
|
221
|
-
message
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
3. Execute the following request to expose the `WidgetPreRenderBodyStyleTags` Shop Metafield.
|
|
228
|
-
|
|
229
|
-
```graphql
|
|
230
|
-
mutation {
|
|
231
|
-
metafieldStorefrontVisibilityCreate(
|
|
232
|
-
input: {
|
|
233
|
-
namespace: "okendo"
|
|
234
|
-
key: "WidgetPreRenderBodyStyleTags"
|
|
235
|
-
ownerType: SHOP
|
|
236
|
-
}
|
|
237
|
-
) {
|
|
238
|
-
metafieldStorefrontVisibility {
|
|
239
|
-
id
|
|
240
|
-
}
|
|
241
|
-
userErrors {
|
|
242
|
-
field
|
|
243
|
-
message
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
4. Execute the following request to expose the `ReviewsWidgetSnippet` Product Metafield.
|
|
250
|
-
|
|
251
|
-
```graphql
|
|
252
|
-
mutation {
|
|
253
|
-
metafieldStorefrontVisibilityCreate(
|
|
254
|
-
input: {
|
|
255
|
-
namespace: "okendo"
|
|
256
|
-
key: "ReviewsWidgetSnippet"
|
|
257
|
-
ownerType: PRODUCT
|
|
258
|
-
}
|
|
259
|
-
) {
|
|
260
|
-
metafieldStorefrontVisibility {
|
|
261
|
-
id
|
|
262
|
-
}
|
|
263
|
-
userErrors {
|
|
264
|
-
field
|
|
265
|
-
message
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
5. Execute the following request to expose the `StarRatingSnippet` the Product Metafield.
|
|
272
|
-
|
|
273
|
-
```graphql
|
|
274
|
-
mutation {
|
|
275
|
-
metafieldStorefrontVisibilityCreate(
|
|
276
|
-
input: { namespace: "okendo", key: "StarRatingSnippet", ownerType: PRODUCT }
|
|
277
|
-
) {
|
|
278
|
-
metafieldStorefrontVisibility {
|
|
279
|
-
id
|
|
280
|
-
}
|
|
281
|
-
userErrors {
|
|
282
|
-
field
|
|
283
|
-
message
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
**References**
|
|
290
|
-
|
|
291
|
-
- [https://shopify.dev/api/examples/metafields#step-1-expose-metafields](https://shopify.dev/api/examples/metafields#step-1-expose-metafields)
|
|
292
|
-
- [https://shopify.dev/api/admin-graphql/2022-04/mutations/metafieldstorefrontvisibilitycreate](https://shopify.dev/api/admin-graphql/2022-04/mutations/metafieldstorefrontvisibilitycreate)
|
|
293
|
-
</details>
|
|
294
|
-
|
|
295
|
-
<br/><br/>
|
|
296
|
-
|
|
297
|
-
# How to Use Okendo Hydrogen Components In Your Hydrogen App <a id="how-to-use-okendo-hydrogen-components-in-your-hydrogen-app" name="3-how-to-use-okendo-hydrogen-components-in-your-hydrogen-app"></a>
|
|
298
|
-
|
|
299
|
-
## Installation
|
|
300
|
-
|
|
301
|
-
1. In your Hydrogen app directory, run `npm install @okendo/shopify-hydrogen` inside a terminal or PowerShell window.
|
|
302
|
-
2. **Optional:** Create (or add to) your `.env` file at the top level of your project (next to **hydrogen.config.ts**) the following, where `<your_subscriber_id>` is replaced with your Okendo Subscriber ID:
|
|
303
|
-
|
|
304
|
-
```sh
|
|
305
|
-
# .env
|
|
306
|
-
VITE_OKENDO_SUBSCRIBER_ID=<your_subscriber_id>
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
3. Open **vite.config.ts** and add `import okendo from '@okendo/shopify-hydrogen/plugin';` to the list of imports.
|
|
310
|
-
4. Add `okendo()` to the list of `plugins`.
|
|
311
|
-
|
|
312
|
-
```tsx
|
|
313
|
-
/* vite.config.ts */
|
|
314
|
-
/// <reference types="vitest" />
|
|
315
|
-
import { defineConfig } from "vite";
|
|
316
|
-
import hydrogen from "@shopify/hydrogen/plugin";
|
|
317
|
-
import okendo from "@okendo/shopify-hydrogen/plugin";
|
|
318
|
-
|
|
319
|
-
export default defineConfig({
|
|
320
|
-
plugins: [hydrogen(), okendo()],
|
|
321
|
-
resolve: {
|
|
322
|
-
alias: [{ find: /^~\/(.*)/, replacement: "/src/$1" }],
|
|
323
|
-
},
|
|
324
|
-
optimizeDeps: {
|
|
325
|
-
include: ["@headlessui/react", "clsx", "react-use", "typographic-base"],
|
|
326
|
-
},
|
|
327
|
-
test: {
|
|
328
|
-
globals: true,
|
|
329
|
-
testTimeout: 10000,
|
|
330
|
-
hookTimeout: 10000,
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
5. Open **App.server.tsx** and import `OkendoProvider`.
|
|
336
|
-
6. Include the `OkendoProvider` as shown below, passing through your `subscriberId` from your Vite environment variables.
|
|
337
|
-
|
|
338
|
-
```tsx
|
|
339
|
-
/* App.server.tsx */
|
|
340
|
-
import {OkendoProvider} from '@okendo/shopify-hydrogen';
|
|
341
|
-
|
|
342
|
-
function App() {
|
|
343
|
-
return (
|
|
344
|
-
<Suspense fallback={<LoadingFallback />}>
|
|
345
|
-
<ShopifyProvider>
|
|
346
|
-
<!-- *** Include OkendoProvider HERE *** -->
|
|
347
|
-
<OkendoProvider
|
|
348
|
-
subscriberId={import.meta.env.VITE_OKENDO_SUBSCRIBER_ID}
|
|
349
|
-
/>
|
|
350
|
-
<ServerCartProvider>
|
|
351
|
-
<DefaultSeo />
|
|
352
|
-
<Router>
|
|
353
|
-
<FileRoutes />
|
|
354
|
-
<Route path="*" page={<NotFound />} />
|
|
355
|
-
</Router>
|
|
356
|
-
</ServerCartProvider>
|
|
357
|
-
<PerformanceMetrics />
|
|
358
|
-
{import.meta.env.DEV && <PerformanceMetricsDebug />}
|
|
359
|
-
</ShopifyProvider>
|
|
360
|
-
</Suspense>
|
|
361
|
-
);
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
If your app doesn't use Vite environment variables from a `.env` file, you could also provide your Okendo Subscriber ID through other means, i.e. directly:
|
|
365
|
-
|
|
366
|
-
```tsx
|
|
367
|
-
<OkendoProvider subscriberId={okendoSubscriberId} />
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
## Widget Usage
|
|
371
|
-
|
|
372
|
-
### Server Components
|
|
373
|
-
|
|
374
|
-
Import `OkendoReviewsWidget` and `OkendoStarRating` and use as JSX components. Pass in the Shopify Product ID as a prop.
|
|
375
|
-
|
|
376
|
-
The `productId` prop is optional for the `OkendoReviewsWidget`. Not providing it will mean that the widget will display reviews for all products, which is ideal for homepages or collection pages.
|
|
377
|
-
|
|
378
|
-
```tsx
|
|
379
|
-
import {
|
|
380
|
-
OkendoReviewsWidget,
|
|
381
|
-
OkendoStarRating,
|
|
382
|
-
} from '@okendo/shopify-hydrogen';
|
|
383
|
-
|
|
384
|
-
...
|
|
385
|
-
|
|
386
|
-
const okendoReviewsWidget = <OkendoReviewsWidget productId={product.id} />;
|
|
387
|
-
const okendoStarRating = <OkendoStarRating productId={product.id} />;
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
> ℹ️ Okendo `OkendoReviewsWidget` and `OkendoStarRating` widgets are server components. If you want to use them within a client component, you must pass the widget components as props to your client component. Widget components can be used directly in a server component. [Learn more here](#graphql-fragments).
|
|
391
|
-
|
|
392
|
-
<br />
|
|
393
|
-
|
|
394
|
-
### Client Components
|
|
395
|
-
|
|
396
|
-
#### Star Rating Widget Usage in Client Components
|
|
397
|
-
|
|
398
|
-
We also include an `OkendoClientStarRating` component for use within client-side (e.g.`<your component>.client.tsx`) components.
|
|
399
|
-
|
|
400
|
-
Import the `OkendoClientStarRating` component inside a client component and use as a JSX component as seen below:
|
|
401
|
-
|
|
402
|
-
```tsx
|
|
403
|
-
import { OkendoClientStarRating } from '@okendo/shopify-hydrogen';
|
|
404
|
-
|
|
405
|
-
...
|
|
406
|
-
|
|
407
|
-
const okendoClientStarRating = <OkendoClientStarRating productId={product.id} />;
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
> ℹ️ OPTIONAL: You can render the `OkendoClientStarRating` component without making any client-side network requests by using an optional prop `okendoStarRatingSnippet`. This can be achieved using a GraphQL Fragment. [Learn more here](#graphql-fragments).
|
|
411
|
-
|
|
412
|
-
<br />
|
|
413
|
-
|
|
414
|
-
# Components <a id="components" name="components"></a>
|
|
415
|
-
|
|
416
|
-
### OkendoProvider
|
|
417
|
-
|
|
418
|
-
Top level component for enabling Okendo Widgets.
|
|
419
|
-
|
|
420
|
-
We recommend using it directly inside the `<ShopifyProvider>` as its first child in **App.server.tsx**.
|
|
421
|
-
|
|
422
|
-
It will provide:
|
|
423
|
-
|
|
424
|
-
- Okendo Subscriber settings
|
|
425
|
-
- Okendo widget CSS, including:
|
|
426
|
-
- Base variables
|
|
427
|
-
- Custom CSS specified in the Okendo Admin (if applicable)
|
|
428
|
-
- "Above the fold" CSS essential for Server-Side Rendered (SSR) widgets. This ensures styled widgets prior to client-side hydration.
|
|
429
|
-
- Okendo widget initialisation script
|
|
430
|
-
- Used to render/hydrate widgets on the page
|
|
431
|
-
|
|
432
|
-
| Name | Type | Description | Required |
|
|
433
|
-
| ------------------------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
434
|
-
| <code>subscriberId</code> | <code>string</code> | The Okendo subscriber ID. | yes |
|
|
435
|
-
| <code>apiDomain</code> | <code>string</code> | To override the default Okendo API Domain. (Default: <code>api.okendo.io/v1</code>) | no |
|
|
436
|
-
| <code>cdnDomain</code> | <code>string</code> | To override the default Okendo CDN domain. (Default: <code>cdn-static.okendo.io</code>) | no |
|
|
437
|
-
| <code>productUrlFormatOverride</code> | <code>(product: ReviewProduct) => string</code> | By default, we use Hydrogen's out of the box product routing.<br />**Advanced Usage Only:** Function hook which allows the custom configuration of the Shopify product URLs from the Okendo Reviews Widget. | no |
|
|
438
|
-
|
|
439
|
-
### OkendoReviewsWidget<a id="components--okendo-reviews-widget" name="components--okendo-reviews-widget"></a>
|
|
440
|
-
|
|
441
|
-
The Okendo Reviews List widget.
|
|
442
|
-
|
|
443
|
-
| Name | Type | Description | Required |
|
|
444
|
-
| ---------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
445
|
-
| <code>productId</code> | <code>string</code> | The Shopify Product ID. If provided, the Reviews Widget will be configured to display reviews specific to that product. Otherwise, the Reviews Widget will display reviews for all products. | no |
|
|
446
|
-
|
|
447
|
-
### OkendoStarRating<a id="components--okendo-star-rating" name="components--okendo-star-rating"></a>
|
|
448
|
-
|
|
449
|
-
The Okendo Star Rating widget - **For use in _server_ components**.
|
|
450
|
-
|
|
451
|
-
| Name | Type | Description | Required |
|
|
452
|
-
| ---------------------- | ------------------- | ----------------------- | -------- |
|
|
453
|
-
| <code>productId</code> | <code>string</code> | The Shopify Product ID. | yes |
|
|
454
|
-
|
|
455
|
-
<br/>
|
|
456
|
-
|
|
457
|
-
### OkendoClientStarRating<a id="components--okendo-client-star-rating" name="components--okendo-client-star-rating"></a>
|
|
458
|
-
|
|
459
|
-
The Okendo Star Rating widget - **For use in _client_ components**.
|
|
460
|
-
|
|
461
|
-
| Name | Type | Description | Required |
|
|
462
|
-
| ------------------------------------ | -------------------------------------------------- | --------------------------------------------------------------- | -------- |
|
|
463
|
-
| <code>productId</code> | <code>string</code> | The Shopify Product ID. | yes |
|
|
464
|
-
| <code>okendoStarRatingSnippet</code> | <code>Pick<Metafield, "value"> \| undefined</code> | The server-side pre-rendered markup representing a star snippet | no |
|
|
465
|
-
|
|
466
|
-
<br/>
|
|
467
|
-
|
|
468
|
-
---
|
|
469
|
-
|
|
470
|
-
# GraphQL Fragments <a id="graphql-fragments" name="graphql-fragments"></a>
|
|
471
|
-
|
|
472
|
-
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations.
|
|
473
|
-
|
|
474
|
-
We offer performance benefits even when using our client Star Rating Widget by exposing an `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` GraphQL Fragment for use in your server components.
|
|
475
|
-
|
|
476
|
-
This allows you to fetch pre-rendered markup in a **server component** for use within the client component (usually passed down as a property from the server component to the client).
|
|
477
|
-
|
|
478
|
-
If the pre-rendered mark-up is present, the star rating widget initialization does not occur in the client, offering performance benefits.
|
|
479
|
-
|
|
480
|
-
<br/>
|
|
481
|
-
|
|
482
|
-
## Example: Using GraphQL Framgment with OkendoClientStarRating
|
|
483
|
-
|
|
484
|
-
> ℹ️ NOTE: The following example usage is based on our Okendo Hydrogen Demo Store. Refer to the [Github repo](https://github.com/okendo/okendo-shopify-hydrogen-demo) to see a working example.
|
|
485
|
-
|
|
486
|
-
<br/>
|
|
487
|
-
|
|
488
|
-
In the sample [Okendo Hydrogen Demo Store](https://github.com/okendo/okendo-shopify-hydrogen-demo) we extend the `PRODUCT_CARD_FRAGMENT` with our `OKENDO_PRODUCT_STAR_RATING_FRAGMENT`.
|
|
489
|
-
|
|
490
|
-
Open `ProductGrid.client.tsx` and make the changes to the `PRODUCT_CARD_FRAGMENT` as seen below:
|
|
491
|
-
|
|
492
|
-
<br/>
|
|
493
|
-
|
|
494
|
-
**Before**
|
|
495
|
-
|
|
496
|
-
```tsx
|
|
497
|
-
export const PRODUCT_CARD_FRAGMENT = gql`
|
|
498
|
-
fragment ProductCard on Product {
|
|
499
|
-
id
|
|
500
|
-
title
|
|
501
|
-
publishedAt
|
|
502
|
-
handle
|
|
503
|
-
variants(first: 1) {
|
|
504
|
-
nodes {
|
|
505
|
-
id
|
|
506
|
-
image {
|
|
507
|
-
url
|
|
508
|
-
altText
|
|
509
|
-
width
|
|
510
|
-
height
|
|
511
|
-
}
|
|
512
|
-
priceV2 {
|
|
513
|
-
amount
|
|
514
|
-
currencyCode
|
|
515
|
-
}
|
|
516
|
-
compareAtPriceV2 {
|
|
517
|
-
amount
|
|
518
|
-
currencyCode
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
`;
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
**After**
|
|
527
|
-
|
|
528
|
-
```tsx
|
|
529
|
-
export const PRODUCT_CARD_FRAGMENT = gql`
|
|
530
|
-
${OKENDO_PRODUCT_STAR_RATING_FRAGMENT}
|
|
531
|
-
fragment ProductCard on Product {
|
|
532
|
-
id
|
|
533
|
-
title
|
|
534
|
-
publishedAt
|
|
535
|
-
handle
|
|
536
|
-
...OkendoStarRatingSnippet
|
|
537
|
-
variants(first: 1) {
|
|
538
|
-
nodes {
|
|
539
|
-
id
|
|
540
|
-
image {
|
|
541
|
-
url
|
|
542
|
-
altText
|
|
543
|
-
width
|
|
544
|
-
height
|
|
545
|
-
}
|
|
546
|
-
priceV2 {
|
|
547
|
-
amount
|
|
548
|
-
currencyCode
|
|
549
|
-
}
|
|
550
|
-
compareAtPriceV2 {
|
|
551
|
-
amount
|
|
552
|
-
currencyCode
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
`;
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
Adding the `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` GraphQL Fragment allows you to access and include an `okendoStarRatingSnippet` in your `Product` query.
|
|
561
|
-
|
|
562
|
-
The `okendoStarRatingSnippet` is a server-side rendered version of the output of your star rating contents. This is supplied to your `Product`/`Collection` queries using the `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` to fetch a metafield containg the markup.
|
|
563
|
-
|
|
564
|
-
To help with typing we have exposed an `OkendoProductFragment` type which can be used as a union type with an existing Hydrogen `Product` type.
|
|
565
|
-
|
|
566
|
-
For this example we have used `ProductCard.client.tsx` from our Okendo Hydrogen Demo App.
|
|
567
|
-
|
|
568
|
-
The `ProductCard.client.tsx` component has the result of a server-side `useShopQuery` passed down as props to it.
|
|
569
|
-
|
|
570
|
-
Because we have implemented our `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` we can express the resulting type as a union:
|
|
571
|
-
|
|
572
|
-
```tsx
|
|
573
|
-
Product & OkendoProductFragment
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
In the `ProductCard.client.tsx` import the `OkendoProductFragment` type and the `OkendoClientStarRating` component:
|
|
577
|
-
|
|
578
|
-
```tsx
|
|
579
|
-
import type { OkendoProductFragment } from "@okendo/shopify-hydrogen";
|
|
580
|
-
import { OkendoClientStarRating } from "@okendo/shopify-hydrogen/client";
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
The constructor of the `ProductCard.client.tsx` component can then be modified to use a union-type for the `Product` being passed in to the constructor:
|
|
584
|
-
|
|
585
|
-
```tsx
|
|
586
|
-
export function ProductCard({
|
|
587
|
-
product,
|
|
588
|
-
label,
|
|
589
|
-
className,
|
|
590
|
-
loading,
|
|
591
|
-
onClick,
|
|
592
|
-
}: {
|
|
593
|
-
product: Product & OkendoProductFragment;
|
|
594
|
-
label?: string;
|
|
595
|
-
className?: string;
|
|
596
|
-
loading?: HTMLImageElement['loading'];
|
|
597
|
-
onClick?: () => void;
|
|
598
|
-
}) {
|
|
599
|
-
...
|
|
600
|
-
}
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
Import the `OkendoClientStarRating` component inside the client component and use as seen below. Pass in `product.okendoStarRatingSnippet` as the value for the optional prop `okendoStarRatingSnippet`. This will use the pre-rendered value of the star rating markup without having to make any client-side network requests.
|
|
604
|
-
|
|
605
|
-
```tsx
|
|
606
|
-
{
|
|
607
|
-
product.okendoStarRatingSnippet?.value ? (
|
|
608
|
-
<OkendoClientStarRating
|
|
609
|
-
productId={product.id}
|
|
610
|
-
okendoStarRatingSnippet={product.okendoStarRatingSnippet}
|
|
611
|
-
/>
|
|
612
|
-
) : null;
|
|
613
|
-
}
|
|
614
|
-
```
|
|
615
|
-
|
|
616
|
-
**References**
|
|
617
|
-
|
|
618
|
-
- [GraphQL Fragments](https://www.apollographql.com/docs/react/data/fragments/)
|
|
619
|
-
|
|
620
|
-
---
|
|
621
|
-
|
|
622
|
-
<br/>
|
|
623
|
-
|
|
624
|
-
## View Our Okendo Sample Hydrogen App <a id="view-our-okendo-sample-hydrogen-app" name="view-our-okendo-sample-hydrogen-app"></a>
|
|
625
|
-
|
|
626
|
-
We have created a Shopify Hydrogen sample application with our widgets pre-installed.
|
|
627
|
-
|
|
628
|
-
- [View our Sample Okendo Shopify Hydrogen Demo Repository](https://github.com/okendo/okendo-shopify-hydrogen-demo)
|
|
1
|
+
# Okendo Hydrogen React Components
|
|
2
|
+
|
|
3
|
+
This is the React component library to support Okendo Widget Plus Widgets in Shopify Hydrogen Projects.
|
|
4
|
+
|
|
5
|
+
Currently we provide the following components:
|
|
6
|
+
|
|
7
|
+
### Server Components
|
|
8
|
+
|
|
9
|
+
1. [Reviews List](#components--okendo-reviews-widget)
|
|
10
|
+
2. [Star Ratings](#components--okendo-star-rating)
|
|
11
|
+
|
|
12
|
+
### Client Components
|
|
13
|
+
|
|
14
|
+
1. [Star Ratings](#components--okendo-client-star-rating)
|
|
15
|
+
|
|
16
|
+
<br/>
|
|
17
|
+
|
|
18
|
+
# Table of contents
|
|
19
|
+
|
|
20
|
+
1. [What is Okendo Shopify Hydrogen](#introduction)
|
|
21
|
+
2. [Guided Installation](#installation)
|
|
22
|
+
- [Configure Hydrogen App](#configure-hydrogen-app-config)
|
|
23
|
+
- [Expose Shopify Metafields](#expose-shopify-metafields)
|
|
24
|
+
3. [How to Use Okendo Hydrogen Components In Your Hydrogen Apps](#how-to-use-okendo-hydrogen-components-in-your-hydrogen-app)
|
|
25
|
+
4. [Components](#components)
|
|
26
|
+
5. [GraphQL Fragments](#graphql-fragments)
|
|
27
|
+
6. [View Our Okendo Sample Hydrogen App](#view-our-okendo-sample-hydrogen-app)
|
|
28
|
+
|
|
29
|
+
<br/><br/>
|
|
30
|
+
|
|
31
|
+
# What is Okendo Shopify Hydrogen? <a id="introduction" name="introduction"></a>
|
|
32
|
+
|
|
33
|
+
Okendo Shopify Hydrogen is a React component library to be used in Shopify Hydrogen apps. This utilises [Shopify’s Hydrogen framework](https://shopify.dev/custom-storefronts/hydrogen/framework) which is used to create custom storefronts using both server-side rendered and client-side rendered React components.
|
|
34
|
+
|
|
35
|
+
The purpose of this library is for a Hydrogen-based React Shopify storefront to import this library so that the Okendo Reviews List and Okendo Star Ratings components can be rendered within their React application, providing [Okendo’s reviews display functionality](https://www.okendo.io/blog/widget-plus/).
|
|
36
|
+
|
|
37
|
+
<br/>
|
|
38
|
+
|
|
39
|
+
# Guided Installation <a id="installation" name="installation"></a>
|
|
40
|
+
|
|
41
|
+
The purpose of this documentation is to guide you on the following:
|
|
42
|
+
|
|
43
|
+
- How to configure your Shopify store ready for Okendo Shopify Hydrogen.
|
|
44
|
+
- How to install and configure Okendo Shopify Hydrogen components in your Shopify Hydrogen app.
|
|
45
|
+
|
|
46
|
+
<br/>
|
|
47
|
+
|
|
48
|
+
## Requirements
|
|
49
|
+
|
|
50
|
+
- You have an existing Shopify store.
|
|
51
|
+
- You have an existing Hydrogen app. ([Learn how to create a Hydrogen app](https://shopify.dev/custom-storefronts/hydrogen/getting-started/create))
|
|
52
|
+
- You have a current Okendo Reviews subscription and have the **Okendo: Product Reviews & UCG** app installed and configured.
|
|
53
|
+
- You have an existing Shopify custom app with Storefront access token. ([Learn how to configure Shopify Storefront](https://github.com/okendo/okendo-shopify-hydrogen-demo/wiki/Configure-Shopify-Storefront-API))
|
|
54
|
+
|
|
55
|
+
<br/>
|
|
56
|
+
|
|
57
|
+
## Configure Hydrogen app config <a id="configure-hydrogen-app-config" name="configure-hydrogen-app-config"></a>
|
|
58
|
+
|
|
59
|
+
1. Open **hydrogen.config.ts** in your project.
|
|
60
|
+
2. Make the following changes and save the file:
|
|
61
|
+
- Update `storeDomain` to specify your store's domain name.
|
|
62
|
+
- Update `storefrontToken` to specify your Storefront API access token.
|
|
63
|
+
|
|
64
|
+
<br/>
|
|
65
|
+
|
|
66
|
+
## Expose Shopify Metafields <a id="expose-shopify-metafields" name="expose-shopify-metafields"></a>
|
|
67
|
+
|
|
68
|
+
Okendo Reviews utilise Product and Shop specific [metafields](https://shopify.dev/api/examples/metafields) in order to function and provide a seamless user experience. You will need to expose these metafields so that they can be retrieved by your Hydrogen app.
|
|
69
|
+
|
|
70
|
+
At this point in time, unfortunately Shopify does not have a way of exposing Shop Metafields through their admin UI.
|
|
71
|
+
|
|
72
|
+
The preferred method to expose Metafields is to [contact Okendo Support](mailto:support@okendo.io).
|
|
73
|
+
|
|
74
|
+
<br/>
|
|
75
|
+
|
|
76
|
+
### For Technical/Advanced Users
|
|
77
|
+
|
|
78
|
+
<details>
|
|
79
|
+
<summary>Learn How to Expose Metafields Via The Storefront API</summary>
|
|
80
|
+
|
|
81
|
+
## Exposing Metafields via GraphQL
|
|
82
|
+
|
|
83
|
+
### Using Curl
|
|
84
|
+
|
|
85
|
+
You can also expose the required Okendo Shopify Metafields by using GraphQL with curl.
|
|
86
|
+
|
|
87
|
+
1. Open a new terminal or PowerShell window.
|
|
88
|
+
2. Run the following command to expose the `WidgetPreRenderStyleTag` Shop Metafield.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
curl -X POST \
|
|
92
|
+
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
93
|
+
-H 'Content-Type: application/graphql' \
|
|
94
|
+
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
95
|
+
-d '
|
|
96
|
+
mutation {
|
|
97
|
+
metafieldStorefrontVisibilityCreate(
|
|
98
|
+
input: {
|
|
99
|
+
namespace: "okendo"
|
|
100
|
+
key: "WidgetPreRenderStyleTags"
|
|
101
|
+
ownerType: SHOP
|
|
102
|
+
}
|
|
103
|
+
) {
|
|
104
|
+
metafieldStorefrontVisibility {
|
|
105
|
+
id
|
|
106
|
+
}
|
|
107
|
+
userErrors {
|
|
108
|
+
field
|
|
109
|
+
message
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
3. Run the following command to expose the `WidgetPreRenderBodyStyleTags` Shop Metafield.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
curl -X POST \
|
|
120
|
+
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
121
|
+
-H 'Content-Type: application/graphql' \
|
|
122
|
+
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
123
|
+
-d '
|
|
124
|
+
mutation {
|
|
125
|
+
metafieldStorefrontVisibilityCreate(
|
|
126
|
+
input: {
|
|
127
|
+
namespace: "okendo"
|
|
128
|
+
key: "WidgetPreRenderBodyStyleTags"
|
|
129
|
+
ownerType: SHOP
|
|
130
|
+
}
|
|
131
|
+
) {
|
|
132
|
+
metafieldStorefrontVisibility {
|
|
133
|
+
id
|
|
134
|
+
}
|
|
135
|
+
userErrors {
|
|
136
|
+
field
|
|
137
|
+
message
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
4. Run the following command to expose the `ReviewsWidgetSnippet` Product Metafield.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
curl -X POST \
|
|
148
|
+
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
149
|
+
-H 'Content-Type: application/graphql' \
|
|
150
|
+
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
151
|
+
-d '
|
|
152
|
+
mutation {
|
|
153
|
+
metafieldStorefrontVisibilityCreate(
|
|
154
|
+
input: {
|
|
155
|
+
namespace: "okendo"
|
|
156
|
+
key: "ReviewsWidgetSnippet"
|
|
157
|
+
ownerType: PRODUCT
|
|
158
|
+
}
|
|
159
|
+
) {
|
|
160
|
+
metafieldStorefrontVisibility {
|
|
161
|
+
id
|
|
162
|
+
}
|
|
163
|
+
userErrors {
|
|
164
|
+
field
|
|
165
|
+
message
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
'
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
5. Run the following command to expose the `StarRatingSnippet` the Product Metafield.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
curl -X POST \
|
|
176
|
+
https://{shop}.myshopify.com/admin/api/2022-04/graphql.json \
|
|
177
|
+
-H 'Content-Type: application/graphql' \
|
|
178
|
+
-H 'X-Shopify-Access-Token: {access_token}' \
|
|
179
|
+
-d '
|
|
180
|
+
mutation {
|
|
181
|
+
metafieldStorefrontVisibilityCreate(
|
|
182
|
+
input: {
|
|
183
|
+
namespace: "okendo"
|
|
184
|
+
key: "StarRatingSnippet"
|
|
185
|
+
ownerType: PRODUCT
|
|
186
|
+
}
|
|
187
|
+
) {
|
|
188
|
+
metafieldStorefrontVisibility {
|
|
189
|
+
id
|
|
190
|
+
}
|
|
191
|
+
userErrors {
|
|
192
|
+
field
|
|
193
|
+
message
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
'
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Using GraphQL IDE
|
|
201
|
+
|
|
202
|
+
1. Open your GraphQL IDE (such as Postman) and make a `POST` request with the following details:
|
|
203
|
+
- **URL:** https://{shop}.myshopify.com/admin/api/2022-04/graphql.json
|
|
204
|
+
- **Headers:** - X-Shopify-Access-Token: {access_token} - Content-Type: application/json
|
|
205
|
+
2. Execute the following request to expose the `WidgetPreRenderStyleTag` Shop Metafield.
|
|
206
|
+
|
|
207
|
+
```graphql
|
|
208
|
+
mutation {
|
|
209
|
+
metafieldStorefrontVisibilityCreate(
|
|
210
|
+
input: {
|
|
211
|
+
namespace: "okendo"
|
|
212
|
+
key: "WidgetPreRenderStyleTags"
|
|
213
|
+
ownerType: SHOP
|
|
214
|
+
}
|
|
215
|
+
) {
|
|
216
|
+
metafieldStorefrontVisibility {
|
|
217
|
+
id
|
|
218
|
+
}
|
|
219
|
+
userErrors {
|
|
220
|
+
field
|
|
221
|
+
message
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
3. Execute the following request to expose the `WidgetPreRenderBodyStyleTags` Shop Metafield.
|
|
228
|
+
|
|
229
|
+
```graphql
|
|
230
|
+
mutation {
|
|
231
|
+
metafieldStorefrontVisibilityCreate(
|
|
232
|
+
input: {
|
|
233
|
+
namespace: "okendo"
|
|
234
|
+
key: "WidgetPreRenderBodyStyleTags"
|
|
235
|
+
ownerType: SHOP
|
|
236
|
+
}
|
|
237
|
+
) {
|
|
238
|
+
metafieldStorefrontVisibility {
|
|
239
|
+
id
|
|
240
|
+
}
|
|
241
|
+
userErrors {
|
|
242
|
+
field
|
|
243
|
+
message
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
4. Execute the following request to expose the `ReviewsWidgetSnippet` Product Metafield.
|
|
250
|
+
|
|
251
|
+
```graphql
|
|
252
|
+
mutation {
|
|
253
|
+
metafieldStorefrontVisibilityCreate(
|
|
254
|
+
input: {
|
|
255
|
+
namespace: "okendo"
|
|
256
|
+
key: "ReviewsWidgetSnippet"
|
|
257
|
+
ownerType: PRODUCT
|
|
258
|
+
}
|
|
259
|
+
) {
|
|
260
|
+
metafieldStorefrontVisibility {
|
|
261
|
+
id
|
|
262
|
+
}
|
|
263
|
+
userErrors {
|
|
264
|
+
field
|
|
265
|
+
message
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
5. Execute the following request to expose the `StarRatingSnippet` the Product Metafield.
|
|
272
|
+
|
|
273
|
+
```graphql
|
|
274
|
+
mutation {
|
|
275
|
+
metafieldStorefrontVisibilityCreate(
|
|
276
|
+
input: { namespace: "okendo", key: "StarRatingSnippet", ownerType: PRODUCT }
|
|
277
|
+
) {
|
|
278
|
+
metafieldStorefrontVisibility {
|
|
279
|
+
id
|
|
280
|
+
}
|
|
281
|
+
userErrors {
|
|
282
|
+
field
|
|
283
|
+
message
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**References**
|
|
290
|
+
|
|
291
|
+
- [https://shopify.dev/api/examples/metafields#step-1-expose-metafields](https://shopify.dev/api/examples/metafields#step-1-expose-metafields)
|
|
292
|
+
- [https://shopify.dev/api/admin-graphql/2022-04/mutations/metafieldstorefrontvisibilitycreate](https://shopify.dev/api/admin-graphql/2022-04/mutations/metafieldstorefrontvisibilitycreate)
|
|
293
|
+
</details>
|
|
294
|
+
|
|
295
|
+
<br/><br/>
|
|
296
|
+
|
|
297
|
+
# How to Use Okendo Hydrogen Components In Your Hydrogen App <a id="how-to-use-okendo-hydrogen-components-in-your-hydrogen-app" name="3-how-to-use-okendo-hydrogen-components-in-your-hydrogen-app"></a>
|
|
298
|
+
|
|
299
|
+
## Installation
|
|
300
|
+
|
|
301
|
+
1. In your Hydrogen app directory, run `npm install @okendo/shopify-hydrogen` inside a terminal or PowerShell window.
|
|
302
|
+
2. **Optional:** Create (or add to) your `.env` file at the top level of your project (next to **hydrogen.config.ts**) the following, where `<your_subscriber_id>` is replaced with your Okendo Subscriber ID:
|
|
303
|
+
|
|
304
|
+
```sh
|
|
305
|
+
# .env
|
|
306
|
+
VITE_OKENDO_SUBSCRIBER_ID=<your_subscriber_id>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
3. Open **vite.config.ts** and add `import okendo from '@okendo/shopify-hydrogen/plugin';` to the list of imports.
|
|
310
|
+
4. Add `okendo()` to the list of `plugins`.
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
/* vite.config.ts */
|
|
314
|
+
/// <reference types="vitest" />
|
|
315
|
+
import { defineConfig } from "vite";
|
|
316
|
+
import hydrogen from "@shopify/hydrogen/plugin";
|
|
317
|
+
import okendo from "@okendo/shopify-hydrogen/plugin";
|
|
318
|
+
|
|
319
|
+
export default defineConfig({
|
|
320
|
+
plugins: [hydrogen(), okendo()],
|
|
321
|
+
resolve: {
|
|
322
|
+
alias: [{ find: /^~\/(.*)/, replacement: "/src/$1" }],
|
|
323
|
+
},
|
|
324
|
+
optimizeDeps: {
|
|
325
|
+
include: ["@headlessui/react", "clsx", "react-use", "typographic-base"],
|
|
326
|
+
},
|
|
327
|
+
test: {
|
|
328
|
+
globals: true,
|
|
329
|
+
testTimeout: 10000,
|
|
330
|
+
hookTimeout: 10000,
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
5. Open **App.server.tsx** and import `OkendoProvider`.
|
|
336
|
+
6. Include the `OkendoProvider` as shown below, passing through your `subscriberId` from your Vite environment variables.
|
|
337
|
+
|
|
338
|
+
```tsx
|
|
339
|
+
/* App.server.tsx */
|
|
340
|
+
import {OkendoProvider} from '@okendo/shopify-hydrogen';
|
|
341
|
+
|
|
342
|
+
function App() {
|
|
343
|
+
return (
|
|
344
|
+
<Suspense fallback={<LoadingFallback />}>
|
|
345
|
+
<ShopifyProvider>
|
|
346
|
+
<!-- *** Include OkendoProvider HERE *** -->
|
|
347
|
+
<OkendoProvider
|
|
348
|
+
subscriberId={import.meta.env.VITE_OKENDO_SUBSCRIBER_ID}
|
|
349
|
+
/>
|
|
350
|
+
<ServerCartProvider>
|
|
351
|
+
<DefaultSeo />
|
|
352
|
+
<Router>
|
|
353
|
+
<FileRoutes />
|
|
354
|
+
<Route path="*" page={<NotFound />} />
|
|
355
|
+
</Router>
|
|
356
|
+
</ServerCartProvider>
|
|
357
|
+
<PerformanceMetrics />
|
|
358
|
+
{import.meta.env.DEV && <PerformanceMetricsDebug />}
|
|
359
|
+
</ShopifyProvider>
|
|
360
|
+
</Suspense>
|
|
361
|
+
);
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
If your app doesn't use Vite environment variables from a `.env` file, you could also provide your Okendo Subscriber ID through other means, i.e. directly:
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
<OkendoProvider subscriberId={okendoSubscriberId} />
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Widget Usage
|
|
371
|
+
|
|
372
|
+
### Server Components
|
|
373
|
+
|
|
374
|
+
Import `OkendoReviewsWidget` and `OkendoStarRating` and use as JSX components. Pass in the Shopify Product ID as a prop.
|
|
375
|
+
|
|
376
|
+
The `productId` prop is optional for the `OkendoReviewsWidget`. Not providing it will mean that the widget will display reviews for all products, which is ideal for homepages or collection pages.
|
|
377
|
+
|
|
378
|
+
```tsx
|
|
379
|
+
import {
|
|
380
|
+
OkendoReviewsWidget,
|
|
381
|
+
OkendoStarRating,
|
|
382
|
+
} from '@okendo/shopify-hydrogen';
|
|
383
|
+
|
|
384
|
+
...
|
|
385
|
+
|
|
386
|
+
const okendoReviewsWidget = <OkendoReviewsWidget productId={product.id} />;
|
|
387
|
+
const okendoStarRating = <OkendoStarRating productId={product.id} />;
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
> ℹ️ Okendo `OkendoReviewsWidget` and `OkendoStarRating` widgets are server components. If you want to use them within a client component, you must pass the widget components as props to your client component. Widget components can be used directly in a server component. [Learn more here](#graphql-fragments).
|
|
391
|
+
|
|
392
|
+
<br />
|
|
393
|
+
|
|
394
|
+
### Client Components
|
|
395
|
+
|
|
396
|
+
#### Star Rating Widget Usage in Client Components
|
|
397
|
+
|
|
398
|
+
We also include an `OkendoClientStarRating` component for use within client-side (e.g.`<your component>.client.tsx`) components.
|
|
399
|
+
|
|
400
|
+
Import the `OkendoClientStarRating` component inside a client component and use as a JSX component as seen below:
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
import { OkendoClientStarRating } from '@okendo/shopify-hydrogen';
|
|
404
|
+
|
|
405
|
+
...
|
|
406
|
+
|
|
407
|
+
const okendoClientStarRating = <OkendoClientStarRating productId={product.id} />;
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
> ℹ️ OPTIONAL: You can render the `OkendoClientStarRating` component without making any client-side network requests by using an optional prop `okendoStarRatingSnippet`. This can be achieved using a GraphQL Fragment. [Learn more here](#graphql-fragments).
|
|
411
|
+
|
|
412
|
+
<br />
|
|
413
|
+
|
|
414
|
+
# Components <a id="components" name="components"></a>
|
|
415
|
+
|
|
416
|
+
### OkendoProvider
|
|
417
|
+
|
|
418
|
+
Top level component for enabling Okendo Widgets.
|
|
419
|
+
|
|
420
|
+
We recommend using it directly inside the `<ShopifyProvider>` as its first child in **App.server.tsx**.
|
|
421
|
+
|
|
422
|
+
It will provide:
|
|
423
|
+
|
|
424
|
+
- Okendo Subscriber settings
|
|
425
|
+
- Okendo widget CSS, including:
|
|
426
|
+
- Base variables
|
|
427
|
+
- Custom CSS specified in the Okendo Admin (if applicable)
|
|
428
|
+
- "Above the fold" CSS essential for Server-Side Rendered (SSR) widgets. This ensures styled widgets prior to client-side hydration.
|
|
429
|
+
- Okendo widget initialisation script
|
|
430
|
+
- Used to render/hydrate widgets on the page
|
|
431
|
+
|
|
432
|
+
| Name | Type | Description | Required |
|
|
433
|
+
| ------------------------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
434
|
+
| <code>subscriberId</code> | <code>string</code> | The Okendo subscriber ID. | yes |
|
|
435
|
+
| <code>apiDomain</code> | <code>string</code> | To override the default Okendo API Domain. (Default: <code>api.okendo.io/v1</code>) | no |
|
|
436
|
+
| <code>cdnDomain</code> | <code>string</code> | To override the default Okendo CDN domain. (Default: <code>cdn-static.okendo.io</code>) | no |
|
|
437
|
+
| <code>productUrlFormatOverride</code> | <code>(product: ReviewProduct) => string</code> | By default, we use Hydrogen's out of the box product routing.<br />**Advanced Usage Only:** Function hook which allows the custom configuration of the Shopify product URLs from the Okendo Reviews Widget. | no |
|
|
438
|
+
|
|
439
|
+
### OkendoReviewsWidget<a id="components--okendo-reviews-widget" name="components--okendo-reviews-widget"></a>
|
|
440
|
+
|
|
441
|
+
The Okendo Reviews List widget.
|
|
442
|
+
|
|
443
|
+
| Name | Type | Description | Required |
|
|
444
|
+
| ---------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
|
445
|
+
| <code>productId</code> | <code>string</code> | The Shopify Product ID. If provided, the Reviews Widget will be configured to display reviews specific to that product. Otherwise, the Reviews Widget will display reviews for all products. | no |
|
|
446
|
+
|
|
447
|
+
### OkendoStarRating<a id="components--okendo-star-rating" name="components--okendo-star-rating"></a>
|
|
448
|
+
|
|
449
|
+
The Okendo Star Rating widget - **For use in _server_ components**.
|
|
450
|
+
|
|
451
|
+
| Name | Type | Description | Required |
|
|
452
|
+
| ---------------------- | ------------------- | ----------------------- | -------- |
|
|
453
|
+
| <code>productId</code> | <code>string</code> | The Shopify Product ID. | yes |
|
|
454
|
+
|
|
455
|
+
<br/>
|
|
456
|
+
|
|
457
|
+
### OkendoClientStarRating<a id="components--okendo-client-star-rating" name="components--okendo-client-star-rating"></a>
|
|
458
|
+
|
|
459
|
+
The Okendo Star Rating widget - **For use in _client_ components**.
|
|
460
|
+
|
|
461
|
+
| Name | Type | Description | Required |
|
|
462
|
+
| ------------------------------------ | -------------------------------------------------- | --------------------------------------------------------------- | -------- |
|
|
463
|
+
| <code>productId</code> | <code>string</code> | The Shopify Product ID. | yes |
|
|
464
|
+
| <code>okendoStarRatingSnippet</code> | <code>Pick<Metafield, "value"> \| undefined</code> | The server-side pre-rendered markup representing a star snippet | no |
|
|
465
|
+
|
|
466
|
+
<br/>
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
|
|
470
|
+
# GraphQL Fragments <a id="graphql-fragments" name="graphql-fragments"></a>
|
|
471
|
+
|
|
472
|
+
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations.
|
|
473
|
+
|
|
474
|
+
We offer performance benefits even when using our client Star Rating Widget by exposing an `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` GraphQL Fragment for use in your server components.
|
|
475
|
+
|
|
476
|
+
This allows you to fetch pre-rendered markup in a **server component** for use within the client component (usually passed down as a property from the server component to the client).
|
|
477
|
+
|
|
478
|
+
If the pre-rendered mark-up is present, the star rating widget initialization does not occur in the client, offering performance benefits.
|
|
479
|
+
|
|
480
|
+
<br/>
|
|
481
|
+
|
|
482
|
+
## Example: Using GraphQL Framgment with OkendoClientStarRating
|
|
483
|
+
|
|
484
|
+
> ℹ️ NOTE: The following example usage is based on our Okendo Hydrogen Demo Store. Refer to the [Github repo](https://github.com/okendo/okendo-shopify-hydrogen-demo) to see a working example.
|
|
485
|
+
|
|
486
|
+
<br/>
|
|
487
|
+
|
|
488
|
+
In the sample [Okendo Hydrogen Demo Store](https://github.com/okendo/okendo-shopify-hydrogen-demo) we extend the `PRODUCT_CARD_FRAGMENT` with our `OKENDO_PRODUCT_STAR_RATING_FRAGMENT`.
|
|
489
|
+
|
|
490
|
+
Open `ProductGrid.client.tsx` and make the changes to the `PRODUCT_CARD_FRAGMENT` as seen below:
|
|
491
|
+
|
|
492
|
+
<br/>
|
|
493
|
+
|
|
494
|
+
**Before**
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
export const PRODUCT_CARD_FRAGMENT = gql`
|
|
498
|
+
fragment ProductCard on Product {
|
|
499
|
+
id
|
|
500
|
+
title
|
|
501
|
+
publishedAt
|
|
502
|
+
handle
|
|
503
|
+
variants(first: 1) {
|
|
504
|
+
nodes {
|
|
505
|
+
id
|
|
506
|
+
image {
|
|
507
|
+
url
|
|
508
|
+
altText
|
|
509
|
+
width
|
|
510
|
+
height
|
|
511
|
+
}
|
|
512
|
+
priceV2 {
|
|
513
|
+
amount
|
|
514
|
+
currencyCode
|
|
515
|
+
}
|
|
516
|
+
compareAtPriceV2 {
|
|
517
|
+
amount
|
|
518
|
+
currencyCode
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
`;
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
**After**
|
|
527
|
+
|
|
528
|
+
```tsx
|
|
529
|
+
export const PRODUCT_CARD_FRAGMENT = gql`
|
|
530
|
+
${OKENDO_PRODUCT_STAR_RATING_FRAGMENT}
|
|
531
|
+
fragment ProductCard on Product {
|
|
532
|
+
id
|
|
533
|
+
title
|
|
534
|
+
publishedAt
|
|
535
|
+
handle
|
|
536
|
+
...OkendoStarRatingSnippet
|
|
537
|
+
variants(first: 1) {
|
|
538
|
+
nodes {
|
|
539
|
+
id
|
|
540
|
+
image {
|
|
541
|
+
url
|
|
542
|
+
altText
|
|
543
|
+
width
|
|
544
|
+
height
|
|
545
|
+
}
|
|
546
|
+
priceV2 {
|
|
547
|
+
amount
|
|
548
|
+
currencyCode
|
|
549
|
+
}
|
|
550
|
+
compareAtPriceV2 {
|
|
551
|
+
amount
|
|
552
|
+
currencyCode
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
`;
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Adding the `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` GraphQL Fragment allows you to access and include an `okendoStarRatingSnippet` in your `Product` query.
|
|
561
|
+
|
|
562
|
+
The `okendoStarRatingSnippet` is a server-side rendered version of the output of your star rating contents. This is supplied to your `Product`/`Collection` queries using the `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` to fetch a metafield containg the markup.
|
|
563
|
+
|
|
564
|
+
To help with typing we have exposed an `OkendoProductFragment` type which can be used as a union type with an existing Hydrogen `Product` type.
|
|
565
|
+
|
|
566
|
+
For this example we have used `ProductCard.client.tsx` from our Okendo Hydrogen Demo App.
|
|
567
|
+
|
|
568
|
+
The `ProductCard.client.tsx` component has the result of a server-side `useShopQuery` passed down as props to it.
|
|
569
|
+
|
|
570
|
+
Because we have implemented our `OKENDO_PRODUCT_STAR_RATING_FRAGMENT` we can express the resulting type as a union:
|
|
571
|
+
|
|
572
|
+
```tsx
|
|
573
|
+
Product & OkendoProductFragment
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
In the `ProductCard.client.tsx` import the `OkendoProductFragment` type and the `OkendoClientStarRating` component:
|
|
577
|
+
|
|
578
|
+
```tsx
|
|
579
|
+
import type { OkendoProductFragment } from "@okendo/shopify-hydrogen";
|
|
580
|
+
import { OkendoClientStarRating } from "@okendo/shopify-hydrogen/client";
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
The constructor of the `ProductCard.client.tsx` component can then be modified to use a union-type for the `Product` being passed in to the constructor:
|
|
584
|
+
|
|
585
|
+
```tsx
|
|
586
|
+
export function ProductCard({
|
|
587
|
+
product,
|
|
588
|
+
label,
|
|
589
|
+
className,
|
|
590
|
+
loading,
|
|
591
|
+
onClick,
|
|
592
|
+
}: {
|
|
593
|
+
product: Product & OkendoProductFragment;
|
|
594
|
+
label?: string;
|
|
595
|
+
className?: string;
|
|
596
|
+
loading?: HTMLImageElement['loading'];
|
|
597
|
+
onClick?: () => void;
|
|
598
|
+
}) {
|
|
599
|
+
...
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
Import the `OkendoClientStarRating` component inside the client component and use as seen below. Pass in `product.okendoStarRatingSnippet` as the value for the optional prop `okendoStarRatingSnippet`. This will use the pre-rendered value of the star rating markup without having to make any client-side network requests.
|
|
604
|
+
|
|
605
|
+
```tsx
|
|
606
|
+
{
|
|
607
|
+
product.okendoStarRatingSnippet?.value ? (
|
|
608
|
+
<OkendoClientStarRating
|
|
609
|
+
productId={product.id}
|
|
610
|
+
okendoStarRatingSnippet={product.okendoStarRatingSnippet}
|
|
611
|
+
/>
|
|
612
|
+
) : null;
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**References**
|
|
617
|
+
|
|
618
|
+
- [GraphQL Fragments](https://www.apollographql.com/docs/react/data/fragments/)
|
|
619
|
+
|
|
620
|
+
---
|
|
621
|
+
|
|
622
|
+
<br/>
|
|
623
|
+
|
|
624
|
+
## View Our Okendo Sample Hydrogen App <a id="view-our-okendo-sample-hydrogen-app" name="view-our-okendo-sample-hydrogen-app"></a>
|
|
625
|
+
|
|
626
|
+
We have created a Shopify Hydrogen sample application with our widgets pre-installed.
|
|
627
|
+
|
|
628
|
+
- [View our Sample Okendo Shopify Hydrogen Demo Repository](https://github.com/okendo/okendo-shopify-hydrogen-demo)
|