create-brainerce-store 1.68.0 → 1.72.0
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 +31 -10
- package/dist/index.js +197 -105
- package/messages/en.json +63 -3
- package/messages/he.json +63 -3
- package/package.json +1 -1
- package/templates/nextjs/base/TRANSLATIONS.md +14 -7
- package/templates/nextjs/base/src/app/checkout/page.tsx +1074 -1017
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +21 -2
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +1 -1
- package/templates/nextjs/base/src/app/register/page.tsx +67 -64
- package/templates/nextjs/base/src/components/account/order-history.tsx +25 -39
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +30 -11
- package/templates/nextjs/base/src/components/account/profile-section.tsx +303 -226
- package/templates/nextjs/base/src/components/auth/register-form.tsx +326 -245
- package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +306 -294
- package/templates/nextjs/base/src/components/checkout/date-picker.tsx +13 -1
- package/templates/nextjs/base/src/components/checkout/datetime-picker.tsx +61 -21
- package/templates/nextjs/base/src/components/shared/birthday-picker.tsx +258 -0
- package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +71 -2
- package/templates/nextjs/base/src/core/lib/auth.ts +155 -154
- package/templates/nextjs/base/src/core/lib/birthday.ts +74 -0
- package/templates/nextjs/base/src/core/lib/brainerce.ts.ejs +5 -16
- package/templates/nextjs/base/src/core/lib/store-info.ts +10 -0
- package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +3 -6
- package/templates/nextjs/base/src/ui/cart/cart-item.tsx +19 -1
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +42 -6
- package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +52 -10
- package/templates/nextjs/base/src/ui/layout/newsletter-signup.tsx +143 -0
- package/templates/nextjs/base/src/ui/layout/site-footer.tsx.ejs +18 -2
- package/templates/nextjs/base/src/ui/product/back-in-stock-form.tsx +173 -0
- package/templates/nextjs/base/src/ui/product/product-client-section.tsx +484 -455
- package/templates/nextjs/base/src/ui/product/review-form.tsx +136 -12
- package/templates/nextjs/base/src/ui/product/reviews-section.tsx.ejs +139 -108
- package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +21 -3
- package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +19 -1
- package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +44 -7
- package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +52 -10
- package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +155 -142
- package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +500 -477
- package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +135 -11
- package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +179 -148
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +15 -1
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +38 -4
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +54 -11
- package/templates/nextjs/ui-canvas/layout/newsletter-signup.tsx +122 -0
- package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +87 -83
- package/templates/nextjs/ui-canvas/product/back-in-stock-form.tsx +151 -0
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +373 -352
- package/templates/nextjs/ui-canvas/product/review-form.tsx +129 -11
- package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +127 -96
|
@@ -1,352 +1,373 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
4
|
-
import type { Product, ProductMetafield, DownloadFile } from 'brainerce';
|
|
5
|
-
import { useProductPage } from '@/core/hooks/use-product-page';
|
|
6
|
-
import { PriceDisplay } from '@/ui/product/price-display';
|
|
7
|
-
import { VariantSelector } from '@/ui/product/variant-selector';
|
|
8
|
-
import { StockBadge } from '@/ui/product/stock-badge';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
case '
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
/>
|
|
251
|
-
)}
|
|
252
|
-
|
|
253
|
-
{/*
|
|
254
|
-
{
|
|
255
|
-
<
|
|
256
|
-
{
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
</
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
4
|
+
import type { Product, ProductMetafield, DownloadFile } from 'brainerce';
|
|
5
|
+
import { useProductPage } from '@/core/hooks/use-product-page';
|
|
6
|
+
import { PriceDisplay } from '@/ui/product/price-display';
|
|
7
|
+
import { VariantSelector } from '@/ui/product/variant-selector';
|
|
8
|
+
import { StockBadge } from '@/ui/product/stock-badge';
|
|
9
|
+
import { BackInStockForm, canOfferStockAlert } from '@/ui/product/back-in-stock-form';
|
|
10
|
+
import { RecommendationSection } from '@/ui/product/recommendation-section';
|
|
11
|
+
import { FrequentlyBoughtTogether } from '@/ui/product/frequently-bought-together';
|
|
12
|
+
import { CustomizationFields } from '@/ui/product/customization-fields';
|
|
13
|
+
import { ModifierGroupSelector } from '@/ui/product/modifier-group-selector';
|
|
14
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
15
|
+
import { sanitizeProductHtml } from '@/core/lib/sanitize-html';
|
|
16
|
+
|
|
17
|
+
/** Render a metafield value based on its type */
|
|
18
|
+
function MetafieldValue({ field }: { field: ProductMetafield }) {
|
|
19
|
+
const tc = useTranslations('common');
|
|
20
|
+
switch (field.type) {
|
|
21
|
+
case 'IMAGE': {
|
|
22
|
+
if (!field.value) return <span>-</span>;
|
|
23
|
+
return <img src={field.value} alt={field.definitionName} className="h-16 w-16" />;
|
|
24
|
+
}
|
|
25
|
+
case 'GALLERY': {
|
|
26
|
+
let urls: string[] = [];
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(field.value);
|
|
29
|
+
urls = Array.isArray(parsed)
|
|
30
|
+
? parsed.filter((u: unknown) => typeof u === 'string' && u)
|
|
31
|
+
: [];
|
|
32
|
+
} catch {
|
|
33
|
+
urls = field.value ? [field.value] : [];
|
|
34
|
+
}
|
|
35
|
+
if (urls.length === 0) return <span>-</span>;
|
|
36
|
+
return (
|
|
37
|
+
<span className="flex flex-wrap gap-2">
|
|
38
|
+
{urls.map((url, i) => (
|
|
39
|
+
<img key={i} src={url} alt={`${field.definitionName} ${i + 1}`} className="h-16 w-16" />
|
|
40
|
+
))}
|
|
41
|
+
</span>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
case 'URL':
|
|
45
|
+
return field.value ? (
|
|
46
|
+
<a href={field.value} target="_blank" rel="noopener noreferrer">
|
|
47
|
+
{field.value}
|
|
48
|
+
</a>
|
|
49
|
+
) : (
|
|
50
|
+
<span>-</span>
|
|
51
|
+
);
|
|
52
|
+
case 'COLOR':
|
|
53
|
+
return field.value ? <span>{field.value}</span> : <span>-</span>;
|
|
54
|
+
case 'BOOLEAN':
|
|
55
|
+
return <span>{field.value === 'true' ? tc('yes') : tc('no')}</span>;
|
|
56
|
+
case 'DATE':
|
|
57
|
+
case 'DATETIME': {
|
|
58
|
+
if (!field.value) return <span>-</span>;
|
|
59
|
+
try {
|
|
60
|
+
const date = new Date(field.value);
|
|
61
|
+
return (
|
|
62
|
+
<span>
|
|
63
|
+
{field.type === 'DATETIME' ? date.toLocaleString() : date.toLocaleDateString()}
|
|
64
|
+
</span>
|
|
65
|
+
);
|
|
66
|
+
} catch {
|
|
67
|
+
return <span>{field.value}</span>;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
return <span>{field.value || '-'}</span>;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface ProductClientSectionProps {
|
|
76
|
+
product: Product;
|
|
77
|
+
/**
|
|
78
|
+
* From `getStoreInfo().stockAlertsEnabled` — the merchant switch for
|
|
79
|
+
* back-in-stock alerts on this storefront. Undefined on a public-storefront
|
|
80
|
+
* (storeId) client, where the setting does not apply and the feature is on.
|
|
81
|
+
*/
|
|
82
|
+
stockAlertsEnabled?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function ProductClientSection({
|
|
86
|
+
product: initialProduct,
|
|
87
|
+
stockAlertsEnabled,
|
|
88
|
+
}: ProductClientSectionProps) {
|
|
89
|
+
const t = useTranslations('productDetail');
|
|
90
|
+
|
|
91
|
+
const {
|
|
92
|
+
product,
|
|
93
|
+
recommendations,
|
|
94
|
+
images,
|
|
95
|
+
selectedImageIndex,
|
|
96
|
+
setSelectedImageIndex,
|
|
97
|
+
mainImageUrl,
|
|
98
|
+
selectedVariant,
|
|
99
|
+
setSelectedVariant,
|
|
100
|
+
priceInfo,
|
|
101
|
+
inventory,
|
|
102
|
+
canPurchase,
|
|
103
|
+
description,
|
|
104
|
+
quantity,
|
|
105
|
+
setQuantity,
|
|
106
|
+
addingToCart,
|
|
107
|
+
addedMessage,
|
|
108
|
+
handleAddToCart,
|
|
109
|
+
customizationFields,
|
|
110
|
+
customizationValues,
|
|
111
|
+
setCustomizationValues,
|
|
112
|
+
customizationErrors,
|
|
113
|
+
modifierGroups,
|
|
114
|
+
modifierSelections,
|
|
115
|
+
setModifierSelection,
|
|
116
|
+
modifierError,
|
|
117
|
+
} = useProductPage(initialProduct);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<article>
|
|
121
|
+
{/* DESIGN ME — product page (PDP): gallery, buy box (price/stock/variants/customization/modifiers/quantity/add-to-cart), description, specs, cross-sells; everything comes from useProductPage(initialProduct). Compose with the shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons. */}
|
|
122
|
+
<div className="grid grid-cols-1 gap-8 lg:grid-cols-2">
|
|
123
|
+
{/* Image Gallery */}
|
|
124
|
+
<figure>
|
|
125
|
+
{/* `relative` + `aspect-square` are layout-critical for next/image fill */}
|
|
126
|
+
<div className="relative aspect-square">
|
|
127
|
+
{mainImageUrl ? (
|
|
128
|
+
<Image
|
|
129
|
+
src={mainImageUrl}
|
|
130
|
+
alt={product.name}
|
|
131
|
+
fill
|
|
132
|
+
sizes="(max-width: 1024px) 100vw, 50vw"
|
|
133
|
+
priority
|
|
134
|
+
/>
|
|
135
|
+
) : (
|
|
136
|
+
<span className="sr-only">{product.name}</span>
|
|
137
|
+
)}
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{/* Thumbnails */}
|
|
141
|
+
{images.length > 1 && (
|
|
142
|
+
<div className="flex flex-wrap gap-2">
|
|
143
|
+
{images.map((img, idx) => (
|
|
144
|
+
<button
|
|
145
|
+
key={idx}
|
|
146
|
+
type="button"
|
|
147
|
+
onClick={() => setSelectedImageIndex(idx)}
|
|
148
|
+
aria-pressed={selectedImageIndex === idx}
|
|
149
|
+
className="relative h-16 w-16"
|
|
150
|
+
>
|
|
151
|
+
<Image
|
|
152
|
+
src={img.url}
|
|
153
|
+
alt={img.alt || `${product.name} ${idx + 1}`}
|
|
154
|
+
fill
|
|
155
|
+
sizes="64px"
|
|
156
|
+
/>
|
|
157
|
+
</button>
|
|
158
|
+
))}
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
<figcaption className="sr-only">{product.name}</figcaption>
|
|
162
|
+
</figure>
|
|
163
|
+
|
|
164
|
+
{/* Product Info / buy box */}
|
|
165
|
+
<section>
|
|
166
|
+
{/* Categories */}
|
|
167
|
+
{product.categories && product.categories.length > 0 && (
|
|
168
|
+
<ul className="flex flex-wrap gap-2">
|
|
169
|
+
{product.categories.map((cat) => (
|
|
170
|
+
<li key={cat.id}>{cat.name}</li>
|
|
171
|
+
))}
|
|
172
|
+
</ul>
|
|
173
|
+
)}
|
|
174
|
+
|
|
175
|
+
{/* Brand */}
|
|
176
|
+
{(product as { brands?: Array<{ id: string; name: string }> }).brands &&
|
|
177
|
+
(product as { brands: Array<{ id: string; name: string }> }).brands.length > 0 && (
|
|
178
|
+
<p>
|
|
179
|
+
{t('by')}{' '}
|
|
180
|
+
<span>
|
|
181
|
+
{(product as { brands: Array<{ id: string; name: string }> }).brands
|
|
182
|
+
.map((b) => b.name)
|
|
183
|
+
.join(', ')}
|
|
184
|
+
</span>
|
|
185
|
+
</p>
|
|
186
|
+
)}
|
|
187
|
+
|
|
188
|
+
{/* Title */}
|
|
189
|
+
<h1>{product.name}</h1>
|
|
190
|
+
|
|
191
|
+
{/* Tags */}
|
|
192
|
+
{(product as unknown as { tags?: Array<{ id: string; name: string }> }).tags &&
|
|
193
|
+
(product as unknown as { tags: Array<{ id: string; name: string }> }).tags.length >
|
|
194
|
+
0 && (
|
|
195
|
+
<ul className="flex flex-wrap gap-1">
|
|
196
|
+
{(product as unknown as { tags: Array<{ id: string; name: string }> }).tags.map(
|
|
197
|
+
(tag) => (
|
|
198
|
+
<li key={tag.id}>#{tag.name}</li>
|
|
199
|
+
)
|
|
200
|
+
)}
|
|
201
|
+
</ul>
|
|
202
|
+
)}
|
|
203
|
+
|
|
204
|
+
{/* Price */}
|
|
205
|
+
<PriceDisplay
|
|
206
|
+
price={priceInfo.originalPrice}
|
|
207
|
+
salePrice={priceInfo.isOnSale ? priceInfo.price : undefined}
|
|
208
|
+
size="lg"
|
|
209
|
+
/>
|
|
210
|
+
|
|
211
|
+
{/* Stock / Digital badge */}
|
|
212
|
+
{product.isDownloadable ? (
|
|
213
|
+
<p>{t('instantDownload')}</p>
|
|
214
|
+
) : (
|
|
215
|
+
<StockBadge inventory={inventory} lowStockThreshold={5} />
|
|
216
|
+
)}
|
|
217
|
+
|
|
218
|
+
{/* Downloadable files info */}
|
|
219
|
+
{product.isDownloadable && product.downloads && product.downloads.length > 0 && (
|
|
220
|
+
<section>
|
|
221
|
+
<h2>
|
|
222
|
+
{t('filesIncluded')} ({product.downloads.length})
|
|
223
|
+
</h2>
|
|
224
|
+
<ul>
|
|
225
|
+
{product.downloads.map((file: DownloadFile) => (
|
|
226
|
+
<li key={file.id}>
|
|
227
|
+
<span>{file.name}</span>
|
|
228
|
+
{file.size && (
|
|
229
|
+
<span>
|
|
230
|
+
{' '}
|
|
231
|
+
(
|
|
232
|
+
{file.size < 1024 * 1024
|
|
233
|
+
? `${(file.size / 1024).toFixed(0)} KB`
|
|
234
|
+
: `${(file.size / (1024 * 1024)).toFixed(1)} MB`}
|
|
235
|
+
)
|
|
236
|
+
</span>
|
|
237
|
+
)}
|
|
238
|
+
</li>
|
|
239
|
+
))}
|
|
240
|
+
</ul>
|
|
241
|
+
</section>
|
|
242
|
+
)}
|
|
243
|
+
|
|
244
|
+
{/* Variant Selector */}
|
|
245
|
+
{product.type === 'VARIABLE' && product.variants && product.variants.length > 0 && (
|
|
246
|
+
<VariantSelector
|
|
247
|
+
product={product}
|
|
248
|
+
selectedVariant={selectedVariant}
|
|
249
|
+
onVariantChange={setSelectedVariant}
|
|
250
|
+
/>
|
|
251
|
+
)}
|
|
252
|
+
|
|
253
|
+
{/* Customization Fields (buyer input) */}
|
|
254
|
+
{customizationFields.length > 0 && (
|
|
255
|
+
<CustomizationFields
|
|
256
|
+
fields={customizationFields}
|
|
257
|
+
values={customizationValues}
|
|
258
|
+
onChange={setCustomizationValues}
|
|
259
|
+
errors={customizationErrors}
|
|
260
|
+
/>
|
|
261
|
+
)}
|
|
262
|
+
|
|
263
|
+
{/* Modifier groups (toppings, sauce, bread type, …) */}
|
|
264
|
+
{modifierGroups.length > 0 && (
|
|
265
|
+
<div>
|
|
266
|
+
{modifierGroups.map((group) => (
|
|
267
|
+
<ModifierGroupSelector
|
|
268
|
+
key={group.attachmentId ?? group.id}
|
|
269
|
+
group={group}
|
|
270
|
+
value={modifierSelections[group.id] ?? []}
|
|
271
|
+
onChange={(next) => setModifierSelection(group.id, next)}
|
|
272
|
+
disabled={addingToCart}
|
|
273
|
+
/>
|
|
274
|
+
))}
|
|
275
|
+
{modifierError && <p role="alert">{modifierError}</p>}
|
|
276
|
+
</div>
|
|
277
|
+
)}
|
|
278
|
+
|
|
279
|
+
{/* Quantity + Add to Cart */}
|
|
280
|
+
<div className="flex items-center gap-4">
|
|
281
|
+
<div className="flex items-center gap-2">
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
onClick={() => setQuantity((q) => Math.max(1, q - 1))}
|
|
285
|
+
aria-label={t('decreaseQuantity')}
|
|
286
|
+
>
|
|
287
|
+
-
|
|
288
|
+
</button>
|
|
289
|
+
<span aria-live="polite">{quantity}</span>
|
|
290
|
+
<button
|
|
291
|
+
type="button"
|
|
292
|
+
onClick={() => setQuantity((q) => q + 1)}
|
|
293
|
+
aria-label={t('increaseQuantity')}
|
|
294
|
+
>
|
|
295
|
+
+
|
|
296
|
+
</button>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
<button type="button" onClick={handleAddToCart} disabled={!canPurchase || addingToCart}>
|
|
300
|
+
{addingToCart
|
|
301
|
+
? t('addingToCart')
|
|
302
|
+
: addedMessage
|
|
303
|
+
? t('addedToCart')
|
|
304
|
+
: !canPurchase
|
|
305
|
+
? t('outOfStock')
|
|
306
|
+
: t('addToCart')}
|
|
307
|
+
</button>
|
|
308
|
+
</div>
|
|
309
|
+
|
|
310
|
+
{/*
|
|
311
|
+
Sold out is not the end of the page. `canOfferStockAlert` is the whole
|
|
312
|
+
gate — it also covers the merchant's switch and backorderable items,
|
|
313
|
+
where an alert would tell someone to come back and do what they can
|
|
314
|
+
already do. Pass the selected variant: without it a shopper who wanted
|
|
315
|
+
the medium is mailed when the small returns.
|
|
316
|
+
*/}
|
|
317
|
+
{canOfferStockAlert(inventory, stockAlertsEnabled) && (
|
|
318
|
+
<BackInStockForm productId={product.id} variantId={selectedVariant?.id} />
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
{/* Download after purchase note */}
|
|
322
|
+
{product.isDownloadable && <p>{t('downloadAfterPurchase')}</p>}
|
|
323
|
+
|
|
324
|
+
{/* Description */}
|
|
325
|
+
{description && (
|
|
326
|
+
<section>
|
|
327
|
+
<h2>{t('description')}</h2>
|
|
328
|
+
{'html' in description ? (
|
|
329
|
+
<div dangerouslySetInnerHTML={{ __html: sanitizeProductHtml(description.html) }} />
|
|
330
|
+
) : (
|
|
331
|
+
<p className="whitespace-pre-wrap">{description.text}</p>
|
|
332
|
+
)}
|
|
333
|
+
</section>
|
|
334
|
+
)}
|
|
335
|
+
|
|
336
|
+
{/* Metafields / Specifications */}
|
|
337
|
+
{product.metafields && product.metafields.length > 0 && (
|
|
338
|
+
<section>
|
|
339
|
+
<h2>{t('specifications')}</h2>
|
|
340
|
+
<table>
|
|
341
|
+
<tbody>
|
|
342
|
+
{product.metafields.map((field) => (
|
|
343
|
+
<tr key={field.id}>
|
|
344
|
+
<th scope="row">{field.definitionName}</th>
|
|
345
|
+
<td>
|
|
346
|
+
<MetafieldValue field={field} />
|
|
347
|
+
</td>
|
|
348
|
+
</tr>
|
|
349
|
+
))}
|
|
350
|
+
</tbody>
|
|
351
|
+
</table>
|
|
352
|
+
</section>
|
|
353
|
+
)}
|
|
354
|
+
</section>
|
|
355
|
+
</div>
|
|
356
|
+
|
|
357
|
+
{/* Frequently Bought Together (cross-sells) */}
|
|
358
|
+
{recommendations?.crossSells && recommendations.crossSells.length > 0 && (
|
|
359
|
+
<FrequentlyBoughtTogether items={recommendations.crossSells} currentProduct={product} />
|
|
360
|
+
)}
|
|
361
|
+
|
|
362
|
+
{/* Upsells */}
|
|
363
|
+
{recommendations?.upsells && recommendations.upsells.length > 0 && (
|
|
364
|
+
<RecommendationSection title={t('upgradeYourChoice')} items={recommendations.upsells} />
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
{/* Related products */}
|
|
368
|
+
{recommendations?.related && recommendations.related.length > 0 && (
|
|
369
|
+
<RecommendationSection title={t('similarProducts')} items={recommendations.related} />
|
|
370
|
+
)}
|
|
371
|
+
</article>
|
|
372
|
+
);
|
|
373
|
+
}
|