create-brainerce-store 1.78.0 → 1.80.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/dist/index.js +27 -2
- package/messages/en.json +12 -3
- package/messages/he.json +12 -3
- package/package.json +10 -1
- package/templates/nextjs/base/.eslintrc.json +2 -0
- package/templates/nextjs/base/AGENTS.md.ejs +23 -5
- package/templates/nextjs/base/CLAUDE.md.ejs +23 -5
- package/templates/nextjs/base/src/app/checkout/page.tsx +19 -2
- package/templates/nextjs/base/src/app/order-status/page.tsx +18 -3
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +220 -214
- package/templates/nextjs/base/src/components/account/order-history.tsx +11 -4
- package/templates/nextjs/base/src/components/account/profile-section.tsx +7 -1
- package/templates/nextjs/base/src/components/auth/register-form.tsx +18 -1
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +14 -2
- package/templates/nextjs/base/src/components/tracking-bootstrap.tsx +1 -1
- package/templates/nextjs/base/src/core/hooks/use-product-page.ts +343 -328
- package/templates/nextjs/base/src/core/lib/kit.ts +88 -0
- package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +87 -12
- package/templates/nextjs/base/src/ui/layout/newsletter-signup.tsx +59 -12
- package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +205 -197
- package/templates/nextjs/base/src/ui/product/product-card.tsx +230 -221
- package/templates/nextjs/base/src/ui/product/product-client-section.tsx +524 -493
- package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +117 -108
- package/templates/nextjs/base/src/ui/product/stock-badge.tsx +23 -3
- package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +210 -202
- package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +251 -242
- package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +540 -509
- package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +110 -101
- package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +22 -2
- package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +41 -11
- package/templates/nextjs/ui-canvas/layout/newsletter-signup.tsx +50 -8
- package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +182 -174
- package/templates/nextjs/ui-canvas/product/product-card.tsx +174 -165
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +31 -0
- package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +114 -105
- package/templates/nextjs/ui-canvas/product/stock-badge.tsx +22 -2
|
@@ -1,242 +1,251 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useRef } from 'react';
|
|
4
|
-
import { Link, useRouter } from '@/core/lib/navigation';
|
|
5
|
-
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
6
|
-
import type { Product } from 'brainerce';
|
|
7
|
-
import { getProductPriceInfo, formatPrice } from 'brainerce';
|
|
8
|
-
import { pickDisplayPrice, pickDisplayPriceRange } from '@/core/lib/display-price';
|
|
9
|
-
import { useTranslations } from '@/core/lib/translations';
|
|
10
|
-
import { PriceDisplay } from '@/ui/product/price-display';
|
|
11
|
-
import { StockBadge } from '@/ui/product/stock-badge';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// carries NO `inventory` object
|
|
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
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useRef } from 'react';
|
|
4
|
+
import { Link, useRouter } from '@/core/lib/navigation';
|
|
5
|
+
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
6
|
+
import type { Product } from 'brainerce';
|
|
7
|
+
import { getProductPriceInfo, formatPrice } from 'brainerce';
|
|
8
|
+
import { pickDisplayPrice, pickDisplayPriceRange } from '@/core/lib/display-price';
|
|
9
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
10
|
+
import { PriceDisplay } from '@/ui/product/price-display';
|
|
11
|
+
import { StockBadge } from '@/ui/product/stock-badge';
|
|
12
|
+
import { canPurchaseProduct } from '@/core/lib/kit';
|
|
13
|
+
import { DiscountBadge } from '@/ui/product/discount-badge';
|
|
14
|
+
import { useCart } from '@/core/providers/store-provider';
|
|
15
|
+
import { flyToCart } from '@/ui/shared/fly-to-cart';
|
|
16
|
+
import { openCartDrawer } from '@/ui/cart/cart-drawer';
|
|
17
|
+
import { useCurrency } from '@/core/lib/use-currency';
|
|
18
|
+
import { trackAddToCart } from '@/core/lib/tracking';
|
|
19
|
+
import { cn } from '@/core/lib/utils';
|
|
20
|
+
import { IconBag, IconCheck, IconDownload, IconStar } from '@/ui/shared/icons';
|
|
21
|
+
|
|
22
|
+
interface ProductCardProps {
|
|
23
|
+
product: Product;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function VariantPriceRange({ product }: { product: Product }) {
|
|
28
|
+
const fallbackCurrency = useCurrency();
|
|
29
|
+
// ⛔ Region-aware. A range built from priceMin/priceMax alone stays in the
|
|
30
|
+
// store currency while the single-price card beside it converts, so a
|
|
31
|
+
// variable product would quote a different currency from its neighbours.
|
|
32
|
+
const range = pickDisplayPriceRange(product, fallbackCurrency);
|
|
33
|
+
if (!range) return null;
|
|
34
|
+
const { min, max, currency } = range;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<span className="text-foreground text-base font-semibold">
|
|
38
|
+
{min === max
|
|
39
|
+
? (formatPrice(min, { currency }) as string)
|
|
40
|
+
: `${formatPrice(min, { currency })} – ${formatPrice(max, { currency })}`}
|
|
41
|
+
</span>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function ProductCard({ product, className }: ProductCardProps) {
|
|
46
|
+
const t = useTranslations('common');
|
|
47
|
+
const tp = useTranslations('productDetail');
|
|
48
|
+
const tProd = useTranslations('products');
|
|
49
|
+
const tr = useTranslations('reviews');
|
|
50
|
+
const router = useRouter();
|
|
51
|
+
const { refreshCart } = useCart();
|
|
52
|
+
const fallbackCurrency = useCurrency();
|
|
53
|
+
// FX overlay (PRD §23): prefer the region-converted display values when the
|
|
54
|
+
// storefront passed regionId to getProducts. Otherwise fall back to the
|
|
55
|
+
// canonical store-currency basePrice / salePrice.
|
|
56
|
+
const display = pickDisplayPrice(product, fallbackCurrency);
|
|
57
|
+
const { price, originalPrice, isOnSale } = getProductPriceInfo(product);
|
|
58
|
+
const mainImage = product.images?.[0];
|
|
59
|
+
const hoverImage = product.images?.[1];
|
|
60
|
+
const imageUrl = mainImage?.url || null;
|
|
61
|
+
const slug = product.slug || product.id;
|
|
62
|
+
const isVariable = product.type === 'VARIABLE';
|
|
63
|
+
|
|
64
|
+
const [adding, setAdding] = useState(false);
|
|
65
|
+
const [added, setAdded] = useState(false);
|
|
66
|
+
|
|
67
|
+
// ⛔ A KIT carries NO `inventory` object — its stock is on `kitAvailable`
|
|
68
|
+
// (`null` = unlimited, `0` = not sellable). Reading `inventory` here left a
|
|
69
|
+
// SOLD-OUT kit with an enabled add-to-cart button, because
|
|
70
|
+
// `undefined?.canPurchase !== false` is `true`. `canPurchaseProduct` reads
|
|
71
|
+
// the right field per product type, and keeps the `!== false` rule so a store
|
|
72
|
+
// that tracks no inventory at all can still sell.
|
|
73
|
+
// A kit also falls through `isVariable` above and adds by `productId` alone,
|
|
74
|
+
// which is correct — kits take no variantId and no selections.
|
|
75
|
+
const canPurchase = canPurchaseProduct(product);
|
|
76
|
+
|
|
77
|
+
const imageWellRef = useRef<HTMLDivElement>(null);
|
|
78
|
+
|
|
79
|
+
async function handleAddToCart(e: React.MouseEvent) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
e.stopPropagation();
|
|
82
|
+
|
|
83
|
+
if (isVariable) {
|
|
84
|
+
router.push(`/products/${slug}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (adding || !canPurchase) return;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
flyToCart(imageWellRef.current);
|
|
92
|
+
setAdding(true);
|
|
93
|
+
const { getClient } = await import('@/core/lib/brainerce');
|
|
94
|
+
const client = getClient();
|
|
95
|
+
await client.smartAddToCart({ productId: product.id, quantity: 1 });
|
|
96
|
+
await refreshCart();
|
|
97
|
+
openCartDrawer();
|
|
98
|
+
// Quick-add from a grid card is a real add_to_cart — without this the
|
|
99
|
+
// ad platforms only ever see adds made from a product page. Reported in
|
|
100
|
+
// the DISPLAYED currency (region-converted when the storefront passed a
|
|
101
|
+
// regionId), because that is what the shopper is actually being charged.
|
|
102
|
+
trackAddToCart(product, null, 1, display.salePrice ?? display.price, display.currency);
|
|
103
|
+
setAdded(true);
|
|
104
|
+
setTimeout(() => setAdded(false), 2000);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error('Failed to add to cart:', err);
|
|
107
|
+
} finally {
|
|
108
|
+
setAdding(false);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<article
|
|
114
|
+
className={cn('card card-hover group relative flex flex-col overflow-hidden', className)}
|
|
115
|
+
>
|
|
116
|
+
<figure className="relative">
|
|
117
|
+
<Link href={`/products/${slug}`} className="block" tabIndex={-1} aria-hidden="true">
|
|
118
|
+
{/* `relative` + `aspect-square` are layout-critical for next/image fill */}
|
|
119
|
+
<div ref={imageWellRef} className="bg-secondary relative aspect-square overflow-hidden">
|
|
120
|
+
{imageUrl ? (
|
|
121
|
+
<>
|
|
122
|
+
<Image
|
|
123
|
+
src={imageUrl}
|
|
124
|
+
alt={mainImage?.alt || product.name}
|
|
125
|
+
fill
|
|
126
|
+
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 33vw, 25vw"
|
|
127
|
+
className={cn(
|
|
128
|
+
'img-zoom object-cover',
|
|
129
|
+
hoverImage && 'transition-opacity duration-500 group-hover:opacity-0'
|
|
130
|
+
)}
|
|
131
|
+
/>
|
|
132
|
+
{hoverImage && (
|
|
133
|
+
<Image
|
|
134
|
+
src={hoverImage.url}
|
|
135
|
+
alt={hoverImage.alt || product.name}
|
|
136
|
+
fill
|
|
137
|
+
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 33vw, 25vw"
|
|
138
|
+
className="object-cover opacity-0 transition-opacity duration-500 group-hover:opacity-100"
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
</>
|
|
142
|
+
) : (
|
|
143
|
+
<span className="sr-only">{product.name}</span>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
</Link>
|
|
147
|
+
<figcaption className="sr-only">{product.name}</figcaption>
|
|
148
|
+
|
|
149
|
+
{/* Badges overlay */}
|
|
150
|
+
<div className="absolute start-3 top-3 flex flex-wrap gap-1.5">
|
|
151
|
+
{isOnSale && <span className="badge-primary">{t('sale')}</span>}
|
|
152
|
+
<DiscountBadge discount={product.discount} />
|
|
153
|
+
{product.isDownloadable && (
|
|
154
|
+
<span className="badge-soft">
|
|
155
|
+
<IconDownload size={16} />
|
|
156
|
+
{tp('digitalProduct')}
|
|
157
|
+
</span>
|
|
158
|
+
)}
|
|
159
|
+
</div>
|
|
160
|
+
</figure>
|
|
161
|
+
|
|
162
|
+
<div className="flex flex-1 flex-col gap-1.5 p-4">
|
|
163
|
+
{/* Categories */}
|
|
164
|
+
{product.categories && product.categories.length > 0 && (
|
|
165
|
+
<ul className="text-muted-foreground flex flex-wrap gap-1 text-xs">
|
|
166
|
+
{product.categories.slice(0, 2).map((cat, idx) => (
|
|
167
|
+
<li key={cat.id}>
|
|
168
|
+
{idx > 0 && <span aria-hidden="true">· </span>}
|
|
169
|
+
{cat.name}
|
|
170
|
+
</li>
|
|
171
|
+
))}
|
|
172
|
+
</ul>
|
|
173
|
+
)}
|
|
174
|
+
|
|
175
|
+
{/* Name — the card-covering link */}
|
|
176
|
+
<h3 className="text-foreground font-sans text-[15px] font-semibold leading-snug">
|
|
177
|
+
<Link
|
|
178
|
+
href={`/products/${slug}`}
|
|
179
|
+
className="hover:text-primary after:absolute after:inset-0 after:content-['']"
|
|
180
|
+
>
|
|
181
|
+
{product.name}
|
|
182
|
+
</Link>
|
|
183
|
+
</h3>
|
|
184
|
+
|
|
185
|
+
{/* Star rating. `avgRating` / `reviewCount` are denormalized rollups
|
|
186
|
+
the API returns on every product fetch. Auto-hides on a store with
|
|
187
|
+
no reviews yet: `reviewCount` is 0 (or absent) and the whole block
|
|
188
|
+
is skipped, so nothing renders and the card keeps its layout. */}
|
|
189
|
+
{product.reviewCount ? (
|
|
190
|
+
<div className="flex items-center gap-1" aria-label={tr('starRating')}>
|
|
191
|
+
<span aria-hidden="true" className="text-primary">
|
|
192
|
+
<IconStar size={16} />
|
|
193
|
+
</span>
|
|
194
|
+
<span className="text-foreground text-xs font-semibold">
|
|
195
|
+
{(product.avgRating ?? 0).toFixed(1)}
|
|
196
|
+
</span>
|
|
197
|
+
<span className="text-muted-foreground text-xs">({product.reviewCount})</span>
|
|
198
|
+
</div>
|
|
199
|
+
) : null}
|
|
200
|
+
|
|
201
|
+
{/* Price */}
|
|
202
|
+
<div>
|
|
203
|
+
{isVariable ? (
|
|
204
|
+
<VariantPriceRange product={product} />
|
|
205
|
+
) : (
|
|
206
|
+
<PriceDisplay
|
|
207
|
+
price={display.price ?? originalPrice}
|
|
208
|
+
salePrice={display.salePrice ?? (isOnSale ? price : undefined)}
|
|
209
|
+
currency={display.currency}
|
|
210
|
+
size="md"
|
|
211
|
+
/>
|
|
212
|
+
)}
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<StockBadge
|
|
216
|
+
inventory={product.inventory}
|
|
217
|
+
// Only a KIT has kit stock. Gating on `type` here keeps the badge and
|
|
218
|
+
// `resolveStockInfo()` using ONE definition of 'this is a kit'.
|
|
219
|
+
kitAvailable={product.type === 'KIT' ? product.kitAvailable : undefined}
|
|
220
|
+
/>
|
|
221
|
+
|
|
222
|
+
{/* Add to cart (variable products route to the product page for option selection) */}
|
|
223
|
+
{(isVariable || canPurchase) && (
|
|
224
|
+
<button
|
|
225
|
+
type="button"
|
|
226
|
+
onClick={handleAddToCart}
|
|
227
|
+
disabled={adding}
|
|
228
|
+
className={cn(
|
|
229
|
+
'btn-outline btn-sm relative z-10 mt-2 w-full',
|
|
230
|
+
added && 'border-primary bg-primary text-primary-foreground hover:bg-primary'
|
|
231
|
+
)}
|
|
232
|
+
>
|
|
233
|
+
{added ? (
|
|
234
|
+
<>
|
|
235
|
+
<IconCheck size={16} />
|
|
236
|
+
{tp('addedToCart')}
|
|
237
|
+
</>
|
|
238
|
+
) : isVariable ? (
|
|
239
|
+
tProd('selectOptions')
|
|
240
|
+
) : (
|
|
241
|
+
<>
|
|
242
|
+
<IconBag size={16} />
|
|
243
|
+
{adding ? tp('addingToCart') : tp('addToCart')}
|
|
244
|
+
</>
|
|
245
|
+
)}
|
|
246
|
+
</button>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
</article>
|
|
250
|
+
);
|
|
251
|
+
}
|