@hszrdm/create-commerce 1.4.0 → 1.6.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/package.json +1 -1
- package/templates/backend/.env.example +13 -0
- package/templates/backend/README.md +4 -0
- package/templates/backend/package.json +3 -1
- package/templates/backend/scripts/core-backup.mjs +281 -0
- package/templates/backend/scripts/core-restore.mjs +179 -0
- package/templates/backend/scripts/lib/core-backup-common.mjs +237 -0
- package/templates/backend/scripts/production-assets/deploy.sh +2 -1
- package/templates/backend/scripts/production-assets/install.sh +2 -1
- package/templates/backend/scripts/production-assets/restore.sh +4 -1
- package/templates/backend/src/scripts/core-init.ts +3 -1
- package/templates/storefront/README.md +35 -12
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +3 -2
- package/templates/storefront/src/app/blog/page.tsx +46 -8
- package/templates/storefront/src/app/cart/page.tsx +2 -0
- package/templates/storefront/src/app/cart/shared/[token]/page.tsx +25 -0
- package/templates/storefront/src/app/cart-recovery/page.tsx +35 -0
- package/templates/storefront/src/app/ertekeles/page.tsx +25 -0
- package/templates/storefront/src/app/fiok-aktivalas/page.tsx +35 -0
- package/templates/storefront/src/app/knowledge-base/page.tsx +46 -8
- package/templates/storefront/src/app/layout.tsx +5 -2
- package/templates/storefront/src/app/legal/page.tsx +18 -2
- package/templates/storefront/src/app/page.tsx +33 -4
- package/templates/storefront/src/app/pages/page.tsx +43 -0
- package/templates/storefront/src/components/abandoned-cart-recovery.tsx +139 -0
- package/templates/storefront/src/components/account-activation-form.tsx +333 -0
- package/templates/storefront/src/components/add-to-cart.tsx +132 -2
- package/templates/storefront/src/components/analytics.tsx +52 -19
- package/templates/storefront/src/components/cart-provider.tsx +40 -3
- package/templates/storefront/src/components/cart-share-button.tsx +93 -0
- package/templates/storefront/src/components/cms-taxonomy-filters.tsx +86 -0
- package/templates/storefront/src/components/customer-cart-resume-gate.tsx +112 -0
- package/templates/storefront/src/components/fogyasztobarat-embed.tsx +32 -0
- package/templates/storefront/src/components/review-request-form.tsx +419 -0
- package/templates/storefront/src/components/shared-cart-view.tsx +257 -0
- package/templates/storefront/src/lib/core/abandoned-cart.ts +47 -0
- package/templates/storefront/src/lib/core/account-activation.ts +75 -0
- package/templates/storefront/src/lib/core/back-in-stock.ts +25 -0
- package/templates/storefront/src/lib/core/catalog.ts +12 -0
- package/templates/storefront/src/lib/core/checkout.ts +86 -4
- package/templates/storefront/src/lib/core/customer-cart-resume.ts +51 -0
- package/templates/storefront/src/lib/core/google-ads.ts +58 -0
- package/templates/storefront/src/lib/core/legal.ts +14 -0
- package/templates/storefront/src/lib/core/reviews.ts +37 -5
- package/templates/storefront/src/lib/core/shared-cart.ts +37 -0
- package/templates/storefront/src/lib/core/types.ts +18 -0
- package/templates/storefront/src/lib/storefront-routes.ts +12 -0
- package/templates/storefront/src/proxy.ts +11 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname, useSearchParams } from "next/navigation"
|
|
5
|
+
import { useEffect, useMemo, useState, type FormEvent } from "react"
|
|
6
|
+
import {
|
|
7
|
+
customerActivationApi,
|
|
8
|
+
type CustomerActivationResult,
|
|
9
|
+
type CustomerActivationReward,
|
|
10
|
+
type CustomerActivationValidation,
|
|
11
|
+
} from "@/lib/core/account-activation"
|
|
12
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
13
|
+
import {
|
|
14
|
+
localeFromPathname,
|
|
15
|
+
STOREFRONT_ROUTES,
|
|
16
|
+
type StorefrontLocale,
|
|
17
|
+
} from "@/lib/storefront-routes"
|
|
18
|
+
|
|
19
|
+
type ActivationState = "checking" | "ready" | "invalid" | "success" | "error"
|
|
20
|
+
|
|
21
|
+
export function AccountActivationForm({ config }: { config: CoreConfig }) {
|
|
22
|
+
const pathname = usePathname()
|
|
23
|
+
const search = useSearchParams()
|
|
24
|
+
const locale = localeFromPathname(pathname)
|
|
25
|
+
const copy = activationCopy(locale)
|
|
26
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
27
|
+
const api = useMemo(() => customerActivationApi(config), [config])
|
|
28
|
+
const [credentials] = useState(() => ({
|
|
29
|
+
customerId: search.get("customer")?.trim() || "",
|
|
30
|
+
token: search.get("token")?.trim() || "",
|
|
31
|
+
}))
|
|
32
|
+
const [state, setState] = useState<ActivationState>("checking")
|
|
33
|
+
const [validation, setValidation] = useState<CustomerActivationValidation | null>(null)
|
|
34
|
+
const [result, setResult] = useState<CustomerActivationResult | null>(null)
|
|
35
|
+
const [reason, setReason] = useState<string | null>(null)
|
|
36
|
+
const [password, setPassword] = useState("")
|
|
37
|
+
const [confirmPassword, setConfirmPassword] = useState("")
|
|
38
|
+
const [busy, setBusy] = useState(false)
|
|
39
|
+
const [error, setError] = useState<string | null>(null)
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
let cancelled = false
|
|
43
|
+
|
|
44
|
+
if (!credentials.customerId || !credentials.token) {
|
|
45
|
+
setReason("missing")
|
|
46
|
+
setState("invalid")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setState("checking")
|
|
51
|
+
void api
|
|
52
|
+
.validate(credentials.customerId, credentials.token)
|
|
53
|
+
.then((payload) => {
|
|
54
|
+
if (cancelled) return
|
|
55
|
+
if (!payload.valid) {
|
|
56
|
+
setReason(payload.reason || "invalid")
|
|
57
|
+
setState("invalid")
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
setValidation(payload)
|
|
61
|
+
setState("ready")
|
|
62
|
+
})
|
|
63
|
+
.catch((cause) => {
|
|
64
|
+
if (cancelled) return
|
|
65
|
+
setError(cause instanceof Error ? cause.message : copy.validationFailed)
|
|
66
|
+
setState("error")
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true
|
|
71
|
+
}
|
|
72
|
+
}, [api, copy.validationFailed, credentials.customerId, credentials.token])
|
|
73
|
+
|
|
74
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
75
|
+
event.preventDefault()
|
|
76
|
+
setError(null)
|
|
77
|
+
|
|
78
|
+
if (password.length < 8) {
|
|
79
|
+
setError(copy.passwordTooShort)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
if (password !== confirmPassword) {
|
|
83
|
+
setError(copy.passwordMismatch)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setBusy(true)
|
|
88
|
+
try {
|
|
89
|
+
const activation = await api.complete(
|
|
90
|
+
credentials.customerId,
|
|
91
|
+
credentials.token,
|
|
92
|
+
password,
|
|
93
|
+
)
|
|
94
|
+
if (typeof window !== "undefined" && window.location.search) {
|
|
95
|
+
window.history.replaceState(window.history.state, "", pathname)
|
|
96
|
+
}
|
|
97
|
+
setResult(activation)
|
|
98
|
+
setPassword("")
|
|
99
|
+
setConfirmPassword("")
|
|
100
|
+
setState("success")
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
setError(cause instanceof Error ? cause.message : copy.activationFailed)
|
|
103
|
+
} finally {
|
|
104
|
+
setBusy(false)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (state === "checking") {
|
|
109
|
+
return <div className="empty-state">{copy.checking}</div>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (state === "invalid") {
|
|
113
|
+
return (
|
|
114
|
+
<section className="panel stack narrow-card">
|
|
115
|
+
<div>
|
|
116
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
117
|
+
<h1>{copy.invalidTitle}</h1>
|
|
118
|
+
</div>
|
|
119
|
+
<p className="muted">{invalidMessage(reason, locale)}</p>
|
|
120
|
+
<Link className="button button-large" href={routes.account}>
|
|
121
|
+
{copy.goToAccount}
|
|
122
|
+
</Link>
|
|
123
|
+
</section>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (state === "error") {
|
|
128
|
+
return (
|
|
129
|
+
<section className="panel stack narrow-card">
|
|
130
|
+
<div>
|
|
131
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
132
|
+
<h1>{copy.errorTitle}</h1>
|
|
133
|
+
</div>
|
|
134
|
+
<p className="error">{error || copy.validationFailed}</p>
|
|
135
|
+
<Link className="button secondary" href={routes.account}>
|
|
136
|
+
{copy.goToAccount}
|
|
137
|
+
</Link>
|
|
138
|
+
</section>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (state === "success" && result) {
|
|
143
|
+
const reward = rewardText(result.reward, locale, config.store.default_currency)
|
|
144
|
+
return (
|
|
145
|
+
<section className="panel stack narrow-card">
|
|
146
|
+
<div>
|
|
147
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
148
|
+
<h1>{copy.successTitle}</h1>
|
|
149
|
+
</div>
|
|
150
|
+
<p className="success">{copy.successText}</p>
|
|
151
|
+
{result.coupon_code ? (
|
|
152
|
+
<div className="empty-state stack-sm">
|
|
153
|
+
<strong>{copy.couponTitle}</strong>
|
|
154
|
+
<code>{result.coupon_code}</code>
|
|
155
|
+
{reward ? <span className="muted small">{reward}</span> : null}
|
|
156
|
+
</div>
|
|
157
|
+
) : null}
|
|
158
|
+
<Link className="button button-large" href={routes.account}>
|
|
159
|
+
{copy.loginNow}
|
|
160
|
+
</Link>
|
|
161
|
+
</section>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const greeting = validation?.first_name?.trim()
|
|
166
|
+
? `${copy.greeting} ${validation.first_name.trim()}!`
|
|
167
|
+
: copy.title
|
|
168
|
+
const expiresAt = formatDateTime(validation?.expires_at, locale)
|
|
169
|
+
const reward = rewardText(validation?.reward, locale, config.store.default_currency)
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<section className="panel stack narrow-card">
|
|
173
|
+
<div>
|
|
174
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
175
|
+
<h1>{greeting}</h1>
|
|
176
|
+
</div>
|
|
177
|
+
<p className="muted">{copy.description}</p>
|
|
178
|
+
|
|
179
|
+
<div className="stack-sm">
|
|
180
|
+
{validation?.masked_email ? (
|
|
181
|
+
<p>
|
|
182
|
+
<strong>{copy.emailLabel}:</strong> {validation.masked_email}
|
|
183
|
+
</p>
|
|
184
|
+
) : null}
|
|
185
|
+
{expiresAt ? (
|
|
186
|
+
<p className="muted small">
|
|
187
|
+
{copy.expiresLabel}: {expiresAt}
|
|
188
|
+
</p>
|
|
189
|
+
) : null}
|
|
190
|
+
{reward ? (
|
|
191
|
+
<p className="muted small">
|
|
192
|
+
{copy.rewardLabel}: {reward}
|
|
193
|
+
</p>
|
|
194
|
+
) : null}
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<form className="stack-sm" onSubmit={submit}>
|
|
198
|
+
<label>
|
|
199
|
+
{copy.newPassword}
|
|
200
|
+
<input
|
|
201
|
+
autoComplete="new-password"
|
|
202
|
+
minLength={8}
|
|
203
|
+
required
|
|
204
|
+
type="password"
|
|
205
|
+
value={password}
|
|
206
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
207
|
+
/>
|
|
208
|
+
</label>
|
|
209
|
+
<label>
|
|
210
|
+
{copy.repeatPassword}
|
|
211
|
+
<input
|
|
212
|
+
autoComplete="new-password"
|
|
213
|
+
minLength={8}
|
|
214
|
+
required
|
|
215
|
+
type="password"
|
|
216
|
+
value={confirmPassword}
|
|
217
|
+
onChange={(event) => setConfirmPassword(event.target.value)}
|
|
218
|
+
/>
|
|
219
|
+
</label>
|
|
220
|
+
<p className="muted small">{copy.passwordHint}</p>
|
|
221
|
+
{error ? <p className="error">{error}</p> : null}
|
|
222
|
+
<button className="button button-large" disabled={busy} type="submit">
|
|
223
|
+
{busy ? copy.activating : copy.activate}
|
|
224
|
+
</button>
|
|
225
|
+
</form>
|
|
226
|
+
</section>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function invalidMessage(reason: string | null, locale: StorefrontLocale) {
|
|
231
|
+
if (locale === "en") {
|
|
232
|
+
if (reason === "expired") return "This activation link has expired. Request a new activation email from the store."
|
|
233
|
+
if (reason === "used") return "This activation link has already been used. You can sign in with your existing account."
|
|
234
|
+
if (reason === "missing") return "The activation link is incomplete. Open the full link from the email you received."
|
|
235
|
+
return "This activation link is invalid. Request a new activation email from the store."
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (reason === "expired") return "Ez az aktiváló link lejárt. Kérj új aktiváló e-mailt a webáruháztól."
|
|
239
|
+
if (reason === "used") return "Ezt az aktiváló linket már felhasználták. A meglévő fiókoddal már be tudsz jelentkezni."
|
|
240
|
+
if (reason === "missing") return "Az aktiváló link hiányos. Nyisd meg újra az e-mailben kapott teljes hivatkozást."
|
|
241
|
+
return "Ez az aktiváló link érvénytelen. Kérj új aktiváló e-mailt a webáruháztól."
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function rewardText(
|
|
245
|
+
reward: CustomerActivationReward | null | undefined,
|
|
246
|
+
locale: StorefrontLocale,
|
|
247
|
+
defaultCurrency: string,
|
|
248
|
+
) {
|
|
249
|
+
if (!reward?.enabled || !reward.value) return null
|
|
250
|
+
if (reward.type !== "fixed") {
|
|
251
|
+
return locale === "en"
|
|
252
|
+
? `${reward.value}% welcome discount after activation`
|
|
253
|
+
: `${reward.value}% üdvözlő kedvezmény az aktiválás után`
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const currency = (reward.currency_code || defaultCurrency || "huf").toUpperCase()
|
|
257
|
+
const amount = new Intl.NumberFormat(locale === "en" ? "en-GB" : "hu-HU", {
|
|
258
|
+
style: "currency",
|
|
259
|
+
currency,
|
|
260
|
+
maximumFractionDigits: 0,
|
|
261
|
+
}).format(reward.value)
|
|
262
|
+
return locale === "en"
|
|
263
|
+
? `${amount} welcome discount after activation`
|
|
264
|
+
: `${amount} üdvözlő kedvezmény az aktiválás után`
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function formatDateTime(value: string | null | undefined, locale: StorefrontLocale) {
|
|
268
|
+
if (!value) return null
|
|
269
|
+
const date = new Date(value)
|
|
270
|
+
if (Number.isNaN(date.getTime())) return null
|
|
271
|
+
return new Intl.DateTimeFormat(locale === "en" ? "en-GB" : "hu-HU", {
|
|
272
|
+
dateStyle: "medium",
|
|
273
|
+
timeStyle: "short",
|
|
274
|
+
}).format(date)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function activationCopy(locale: StorefrontLocale) {
|
|
278
|
+
if (locale === "en") {
|
|
279
|
+
return {
|
|
280
|
+
eyebrow: "Account activation",
|
|
281
|
+
title: "Activate your account",
|
|
282
|
+
greeting: "Welcome",
|
|
283
|
+
description: "Set a new password to activate the customer account created during migration.",
|
|
284
|
+
checking: "Checking activation link…",
|
|
285
|
+
invalidTitle: "Activation link unavailable",
|
|
286
|
+
errorTitle: "Activation could not be checked",
|
|
287
|
+
validationFailed: "We could not verify the activation link.",
|
|
288
|
+
activationFailed: "Account activation failed.",
|
|
289
|
+
emailLabel: "Account",
|
|
290
|
+
expiresLabel: "Link expires",
|
|
291
|
+
rewardLabel: "Activation reward",
|
|
292
|
+
newPassword: "New password",
|
|
293
|
+
repeatPassword: "Repeat password",
|
|
294
|
+
passwordHint: "Use at least 8 characters.",
|
|
295
|
+
passwordTooShort: "The password must be at least 8 characters long.",
|
|
296
|
+
passwordMismatch: "The two passwords do not match.",
|
|
297
|
+
activating: "Activating…",
|
|
298
|
+
activate: "Activate account",
|
|
299
|
+
successTitle: "Your account is active",
|
|
300
|
+
successText: "Your new password has been saved. You can now sign in to your account.",
|
|
301
|
+
couponTitle: "Your welcome coupon",
|
|
302
|
+
loginNow: "Sign in",
|
|
303
|
+
goToAccount: "Go to account",
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
eyebrow: "Fiókaktiválás",
|
|
309
|
+
title: "Aktiváld a fiókodat",
|
|
310
|
+
greeting: "Üdv",
|
|
311
|
+
description: "Adj meg egy új jelszót az átköltöztetett vásárlói fiókod aktiválásához.",
|
|
312
|
+
checking: "Aktiváló link ellenőrzése…",
|
|
313
|
+
invalidTitle: "Az aktiváló link nem használható",
|
|
314
|
+
errorTitle: "Az aktiváló linket nem sikerült ellenőrizni",
|
|
315
|
+
validationFailed: "Az aktiváló link ellenőrzése nem sikerült.",
|
|
316
|
+
activationFailed: "A fiók aktiválása nem sikerült.",
|
|
317
|
+
emailLabel: "Fiók",
|
|
318
|
+
expiresLabel: "A link lejár",
|
|
319
|
+
rewardLabel: "Aktiválási kedvezmény",
|
|
320
|
+
newPassword: "Új jelszó",
|
|
321
|
+
repeatPassword: "Új jelszó ismét",
|
|
322
|
+
passwordHint: "Legalább 8 karakteres jelszót adj meg.",
|
|
323
|
+
passwordTooShort: "A jelszó legalább 8 karakter legyen.",
|
|
324
|
+
passwordMismatch: "A két jelszó nem egyezik.",
|
|
325
|
+
activating: "Aktiválás…",
|
|
326
|
+
activate: "Fiók aktiválása",
|
|
327
|
+
successTitle: "A fiókod aktív",
|
|
328
|
+
successText: "Az új jelszavad mentve lett. Most már bejelentkezhetsz a fiókodba.",
|
|
329
|
+
couponTitle: "Az üdvözlő kuponod",
|
|
330
|
+
loginNow: "Bejelentkezés",
|
|
331
|
+
goToAccount: "Tovább a fiókhoz",
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useMemo, useState } from "react"
|
|
3
|
+
import { useEffect, useMemo, useState } from "react"
|
|
4
4
|
import { usePathname } from "next/navigation"
|
|
5
5
|
import { QuantityStepper } from "./quantity-stepper"
|
|
6
|
+
import { TierProgressHint } from "./tier-progress-hint"
|
|
6
7
|
import { useToast } from "./toast-provider"
|
|
7
8
|
import { useCart } from "./cart-provider"
|
|
9
|
+
import { subscribeBackInStock } from "@/lib/core/back-in-stock"
|
|
8
10
|
import {
|
|
9
11
|
asRecords,
|
|
10
12
|
formatMoney,
|
|
@@ -14,11 +16,26 @@ import {
|
|
|
14
16
|
stringValue,
|
|
15
17
|
} from "@/lib/core/commerce"
|
|
16
18
|
import { humanizeStorefrontError } from "@/lib/core/form-ux"
|
|
19
|
+
import {
|
|
20
|
+
findPricingTierForQuantity,
|
|
21
|
+
formatPricingAmount,
|
|
22
|
+
formatPricingTierRange,
|
|
23
|
+
getVariantPricingTiers,
|
|
24
|
+
type VariantPricingTiers,
|
|
25
|
+
} from "@/lib/core/pricing"
|
|
17
26
|
import { copyText } from "@/lib/core/share"
|
|
18
27
|
import type { CoreConfig } from "@/lib/core/types"
|
|
19
28
|
import { localeFromPathname } from "@/lib/storefront-routes"
|
|
20
29
|
|
|
21
|
-
export function AddToCart({
|
|
30
|
+
export function AddToCart({
|
|
31
|
+
product,
|
|
32
|
+
config,
|
|
33
|
+
regionId,
|
|
34
|
+
}: {
|
|
35
|
+
product: Record<string, unknown>
|
|
36
|
+
config: CoreConfig
|
|
37
|
+
regionId?: string
|
|
38
|
+
}) {
|
|
22
39
|
const pathname = usePathname()
|
|
23
40
|
const locale = localeFromPathname(pathname)
|
|
24
41
|
const en = locale === "en"
|
|
@@ -26,8 +43,13 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
26
43
|
const productMetadata = isRecord(product.metadata) ? product.metadata : {}
|
|
27
44
|
const [variantId, setVariantId] = useState(() => stringValue(variants[0]?.id))
|
|
28
45
|
const [quantity, setQuantity] = useState(() => variantMinimum(variants[0], productMetadata))
|
|
46
|
+
const [pricing, setPricing] = useState<VariantPricingTiers | null>(null)
|
|
29
47
|
const [message, setMessage] = useState<string | null>(null)
|
|
30
48
|
const [success, setSuccess] = useState(false)
|
|
49
|
+
const [alertEmail, setAlertEmail] = useState("")
|
|
50
|
+
const [alertBusy, setAlertBusy] = useState(false)
|
|
51
|
+
const [alertMessage, setAlertMessage] = useState<string | null>(null)
|
|
52
|
+
const [alertSuccess, setAlertSuccess] = useState(false)
|
|
31
53
|
const { addItem, mutating } = useCart()
|
|
32
54
|
const { showToast } = useToast()
|
|
33
55
|
const selected = variants.find((variant) => stringValue(variant.id) === variantId) || variants[0]
|
|
@@ -44,6 +66,31 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
44
66
|
? Math.max(1, Math.trunc(inventory))
|
|
45
67
|
: 999
|
|
46
68
|
const sku = stringValue(selected?.sku)
|
|
69
|
+
const currentTier = pricing?.has_tiered_pricing
|
|
70
|
+
? findPricingTierForQuantity(pricing.tiers, quantity)
|
|
71
|
+
: null
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
let active = true
|
|
75
|
+
if (!variantId) {
|
|
76
|
+
setPricing(null)
|
|
77
|
+
return () => { active = false }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setPricing(null)
|
|
81
|
+
void getVariantPricingTiers(variantId, {
|
|
82
|
+
regionId,
|
|
83
|
+
currencyCode: currency,
|
|
84
|
+
})
|
|
85
|
+
.then((result) => {
|
|
86
|
+
if (active) setPricing(result)
|
|
87
|
+
})
|
|
88
|
+
.catch(() => {
|
|
89
|
+
if (active) setPricing(null)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
return () => { active = false }
|
|
93
|
+
}, [currency, regionId, variantId])
|
|
47
94
|
|
|
48
95
|
if (!variants.length) {
|
|
49
96
|
return <div className="notice warning" role="status">{en ? "This product has no purchasable variant." : "Ehhez a termékhez nincs megvásárolható variáns."}</div>
|
|
@@ -64,6 +111,8 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
64
111
|
setVariantId(nextId)
|
|
65
112
|
setQuantity(variantMinimum(next, productMetadata))
|
|
66
113
|
setMessage(null)
|
|
114
|
+
setAlertMessage(null)
|
|
115
|
+
setAlertSuccess(false)
|
|
67
116
|
if (typeof window !== "undefined") {
|
|
68
117
|
window.dispatchEvent(new CustomEvent("hszrdm:product-variant-change", {
|
|
69
118
|
detail: {
|
|
@@ -109,6 +158,38 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
109
158
|
</div>
|
|
110
159
|
</div>
|
|
111
160
|
|
|
161
|
+
{pricing?.has_tiered_pricing && pricing.tiers.length ? (
|
|
162
|
+
<div className="notice stack-sm" aria-label={en ? "Quantity pricing" : "Mennyiségi ársávok"}>
|
|
163
|
+
<div>
|
|
164
|
+
<strong>{en ? "Quantity pricing" : "Mennyiségi ársávok"}</strong>
|
|
165
|
+
<p className="muted small">
|
|
166
|
+
{en
|
|
167
|
+
? "The Core returns the unit prices calculated by Medusa for your current customer context."
|
|
168
|
+
: "A Core a Medusa által, az aktuális vásárlói kontextusra kiszámolt egységárakat jeleníti meg."}
|
|
169
|
+
</p>
|
|
170
|
+
</div>
|
|
171
|
+
<div className="stack-sm">
|
|
172
|
+
{pricing.tiers.map((tier) => {
|
|
173
|
+
const active = currentTier === tier
|
|
174
|
+
return (
|
|
175
|
+
<div className="info-row" key={`${tier.min_quantity}:${tier.max_quantity ?? "max"}`}>
|
|
176
|
+
<span>{formatPricingTierRange(tier)} {en ? "pcs" : "db"}</span>
|
|
177
|
+
<strong>{formatPricingAmount(tier.unit_amount, tier.currency_code, formatLocale)}{active ? (en ? " · current" : " · aktuális") : ""}</strong>
|
|
178
|
+
</div>
|
|
179
|
+
)
|
|
180
|
+
})}
|
|
181
|
+
</div>
|
|
182
|
+
<TierProgressHint
|
|
183
|
+
quantity={quantity}
|
|
184
|
+
tiers={pricing.tiers.map((tier) => ({
|
|
185
|
+
minQuantity: tier.min_quantity,
|
|
186
|
+
unitPrice: tier.unit_amount,
|
|
187
|
+
}))}
|
|
188
|
+
locale={locale}
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
) : null}
|
|
192
|
+
|
|
112
193
|
<div className={`stock-status ${purchasable ? "is-available" : "is-unavailable"}`} role="status">
|
|
113
194
|
{purchasable
|
|
114
195
|
? hasKnownInventory && managesInventory
|
|
@@ -119,6 +200,55 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
119
200
|
: (en ? "Currently unavailable" : "Jelenleg nem vásárolható")}
|
|
120
201
|
</div>
|
|
121
202
|
|
|
203
|
+
{!purchasable ? (
|
|
204
|
+
<div className="notice stack-sm">
|
|
205
|
+
<strong>{en ? "Notify me when available" : "Értesíts, ha újra elérhető"}</strong>
|
|
206
|
+
<label>
|
|
207
|
+
<span className="field-label">{en ? "Email address" : "E-mail-cím"}</span>
|
|
208
|
+
<input
|
|
209
|
+
type="email"
|
|
210
|
+
autoComplete="email"
|
|
211
|
+
value={alertEmail}
|
|
212
|
+
onChange={(event) => setAlertEmail(event.target.value)}
|
|
213
|
+
placeholder="email@example.com"
|
|
214
|
+
disabled={alertBusy}
|
|
215
|
+
/>
|
|
216
|
+
</label>
|
|
217
|
+
<button
|
|
218
|
+
type="button"
|
|
219
|
+
className="button button-secondary"
|
|
220
|
+
disabled={alertBusy || !variantId || !alertEmail.trim()}
|
|
221
|
+
aria-busy={alertBusy}
|
|
222
|
+
onClick={() => {
|
|
223
|
+
setAlertBusy(true)
|
|
224
|
+
setAlertMessage(null)
|
|
225
|
+
setAlertSuccess(false)
|
|
226
|
+
void subscribeBackInStock({ email: alertEmail.trim(), variantId, locale: formatLocale })
|
|
227
|
+
.then((result) => {
|
|
228
|
+
const next = result.already_available
|
|
229
|
+
? (en ? "This variant is already available. Refresh the page to order it." : "Ez a változat már újra elérhető. Frissítsd az oldalt a rendeléshez.")
|
|
230
|
+
: result.already_subscribed
|
|
231
|
+
? (en ? "You are already on the notification list for this variant." : "Erre a változatra már fel vagy iratkozva az értesítésre.")
|
|
232
|
+
: (en ? "Done. We will email you when this variant is available again." : "Kész. E-mailt küldünk, amikor ez a változat újra elérhető.")
|
|
233
|
+
setAlertSuccess(true)
|
|
234
|
+
setAlertMessage(next)
|
|
235
|
+
showToast({ message: next, tone: "success" })
|
|
236
|
+
})
|
|
237
|
+
.catch((error) => {
|
|
238
|
+
const next = humanizeStorefrontError(error, locale)
|
|
239
|
+
setAlertSuccess(false)
|
|
240
|
+
setAlertMessage(next)
|
|
241
|
+
showToast({ message: next, tone: "error" })
|
|
242
|
+
})
|
|
243
|
+
.finally(() => setAlertBusy(false))
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
{alertBusy ? (en ? "Saving…" : "Mentés…") : (en ? "Notify me" : "Kérek értesítést")}
|
|
247
|
+
</button>
|
|
248
|
+
{alertMessage ? <p className={alertSuccess ? "success" : "error"} aria-live="polite">{alertMessage}</p> : null}
|
|
249
|
+
</div>
|
|
250
|
+
) : null}
|
|
251
|
+
|
|
122
252
|
{sku ? (
|
|
123
253
|
<div className="sku-row">
|
|
124
254
|
<span><span className="muted">SKU:</span> <code>{sku}</code></span>
|
|
@@ -12,6 +12,17 @@ import {
|
|
|
12
12
|
import { analyticsTrackingMode, trackWebshopPageView } from "@/lib/core/tracking"
|
|
13
13
|
import type { CoreConfig } from "@/lib/core/types"
|
|
14
14
|
|
|
15
|
+
const SENSITIVE_ANALYTICS_PATHS = new Set([
|
|
16
|
+
"/fiok-aktivalas",
|
|
17
|
+
"/ertekeles",
|
|
18
|
+
"/reset-password",
|
|
19
|
+
"/newsletter/confirm",
|
|
20
|
+
"/newsletter/unsubscribe",
|
|
21
|
+
"/cart-recovery",
|
|
22
|
+
"/hu/kosar-visszaallitas",
|
|
23
|
+
"/en/cart-recovery",
|
|
24
|
+
])
|
|
25
|
+
|
|
15
26
|
export const GOOGLE_CONSENT_DEFAULT_SCRIPT = `
|
|
16
27
|
window.dataLayer=window.dataLayer||[];
|
|
17
28
|
function gtag(){dataLayer.push(arguments);}
|
|
@@ -24,10 +35,17 @@ gtag('consent','default',{
|
|
|
24
35
|
});
|
|
25
36
|
`
|
|
26
37
|
|
|
27
|
-
export function AnalyticsGate({
|
|
38
|
+
export function AnalyticsGate({
|
|
39
|
+
analytics,
|
|
40
|
+
googleAds,
|
|
41
|
+
}: {
|
|
42
|
+
analytics: CoreConfig["analytics"]
|
|
43
|
+
googleAds: CoreConfig["marketing"]["google_ads"]
|
|
44
|
+
}) {
|
|
28
45
|
const pathname = usePathname()
|
|
29
46
|
const [preferences, setPreferences] = useState<ConsentPreferences | null>(null)
|
|
30
47
|
const [ready, setReady] = useState(false)
|
|
48
|
+
const sensitivePath = SENSITIVE_ANALYTICS_PATHS.has(pathname)
|
|
31
49
|
|
|
32
50
|
useEffect(() => {
|
|
33
51
|
const stored = readConsentPreferences()
|
|
@@ -47,37 +65,52 @@ export function AnalyticsGate({ analytics }: { analytics: CoreConfig["analytics"
|
|
|
47
65
|
}, [])
|
|
48
66
|
|
|
49
67
|
useEffect(() => {
|
|
68
|
+
if (sensitivePath) return
|
|
50
69
|
// HSZRDM Webshop Analytics is first-party and independent from GA4/GTM.
|
|
51
70
|
// The tracker stores only pseudonymous identifiers and commerce context.
|
|
52
71
|
trackWebshopPageView()
|
|
53
|
-
}, [pathname])
|
|
72
|
+
}, [pathname, sensitivePath])
|
|
54
73
|
|
|
55
|
-
if (!ready) return null
|
|
74
|
+
if (!ready || sensitivePath) return null
|
|
56
75
|
|
|
57
76
|
const mode = analyticsTrackingMode(analytics)
|
|
58
77
|
const analyticsGranted = Boolean(preferences?.analytics)
|
|
59
78
|
const marketingGranted = Boolean(preferences?.marketing)
|
|
60
79
|
|
|
61
|
-
// GTM
|
|
62
|
-
//
|
|
80
|
+
// GTM remains the single loader whenever a container is configured. Without
|
|
81
|
+
// GTM, GA4 and Google Ads share one gtag.js loader, while each public ID is
|
|
82
|
+
// configured only after its own consent category has been granted.
|
|
63
83
|
const loadGtm = mode === "gtm" && (analyticsGranted || marketingGranted)
|
|
64
|
-
const loadGa4 = mode === "ga4" && analyticsGranted
|
|
84
|
+
const loadGa4 = mode === "ga4" && analyticsGranted && Boolean(analytics.google_analytics.measurement_id)
|
|
85
|
+
const loadDirectAds = mode !== "gtm" && marketingGranted && googleAds.enabled && Boolean(googleAds.conversion_id)
|
|
86
|
+
const directGoogleTagId = loadGa4
|
|
87
|
+
? analytics.google_analytics.measurement_id
|
|
88
|
+
: loadDirectAds
|
|
89
|
+
? googleAds.conversion_id
|
|
90
|
+
: null
|
|
91
|
+
const configureGa4 = loadGa4
|
|
92
|
+
const configureAds = loadDirectAds
|
|
65
93
|
|
|
66
94
|
return (
|
|
67
95
|
<>
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
{directGoogleTagId ? (
|
|
97
|
+
<Script
|
|
98
|
+
id="core-google-tag-loader"
|
|
99
|
+
src={`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(directGoogleTagId)}`}
|
|
100
|
+
strategy="afterInteractive"
|
|
101
|
+
/>
|
|
102
|
+
) : null}
|
|
103
|
+
|
|
104
|
+
{configureGa4 ? (
|
|
105
|
+
<Script id="core-ga4-config" strategy="afterInteractive">
|
|
106
|
+
{`gtag('js',new Date());gtag('config','${analytics.google_analytics.measurement_id}');`}
|
|
107
|
+
</Script>
|
|
108
|
+
) : null}
|
|
109
|
+
|
|
110
|
+
{configureAds ? (
|
|
111
|
+
<Script id="core-google-ads-config" strategy="afterInteractive">
|
|
112
|
+
{`gtag('config','${googleAds.conversion_id}',{'allow_ad_personalization_signals':${googleAds.remarketing_enabled ? "true" : "false"}});`}
|
|
113
|
+
</Script>
|
|
81
114
|
) : null}
|
|
82
115
|
|
|
83
116
|
{loadGtm && analytics.google_tag_manager.container_id ? (
|