@hszrdm/create-commerce 1.0.2 → 1.1.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.
Files changed (41) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +2 -2
  4. package/templates/backend/.env.example +66 -7
  5. package/templates/backend/medusa-config.ts +17 -1
  6. package/templates/backend/package.json +2 -1
  7. package/templates/backend/src/scripts/core-init.ts +13 -1
  8. package/templates/storefront/next-env.d.ts +4 -1
  9. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
  10. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +9 -5
  11. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  12. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  13. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  14. package/templates/storefront/src/app/layout.tsx +10 -3
  15. package/templates/storefront/src/app/legal/page.tsx +11 -5
  16. package/templates/storefront/src/app/page.tsx +18 -12
  17. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  18. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  19. package/templates/storefront/src/components/add-to-cart.tsx +24 -10
  20. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  21. package/templates/storefront/src/components/cart-view.tsx +28 -20
  22. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  23. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  24. package/templates/storefront/src/components/order-detail.tsx +84 -45
  25. package/templates/storefront/src/components/product-card.tsx +16 -8
  26. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  27. package/templates/storefront/src/components/storefront-header.tsx +25 -11
  28. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  29. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  30. package/templates/storefront/src/lib/core/client.ts +5 -0
  31. package/templates/storefront/src/lib/core/cms.ts +112 -0
  32. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  33. package/templates/storefront/src/lib/core/leads.ts +50 -0
  34. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  35. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  36. package/templates/storefront/src/lib/core/seo.ts +44 -6
  37. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  38. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  39. package/templates/storefront/src/lib/storefront-routes.ts +91 -0
  40. package/templates/storefront/src/proxy.ts +142 -0
  41. package/templates/storefront/tsconfig.json +23 -5
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react"
4
- import { useRouter, useSearchParams } from "next/navigation"
4
+ import { usePathname, useRouter, useSearchParams } from "next/navigation"
5
5
  import { useCart } from "./cart-provider"
6
6
  import { StripePayment } from "./stripe-payment"
7
7
  import { checkoutApi } from "@/lib/core/checkout"
@@ -24,6 +24,13 @@ import {
24
24
  } from "@/lib/core/commerce"
25
25
  import { acceptLegalDocument, listLegalDocuments } from "@/lib/core/legal"
26
26
  import type { CoreConfig, LegalDocument } from "@/lib/core/types"
27
+ import { storefrontCopy } from "@/lib/storefront-copy"
28
+ import {
29
+ localeFromPathname,
30
+ medusaLocale,
31
+ STOREFRONT_ROUTES,
32
+ type StorefrontLocale,
33
+ } from "@/lib/storefront-routes"
27
34
 
28
35
  type AddressState = {
29
36
  email: string
@@ -45,6 +52,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
45
52
  const api = useMemo(() => checkoutApi(config), [config])
46
53
  const router = useRouter()
47
54
  const search = useSearchParams()
55
+ const pathname = usePathname()
56
+ const locale = localeFromPathname(pathname)
57
+ const copy = storefrontCopy(locale)
58
+ const routes = STOREFRONT_ROUTES[locale]
59
+ const numberLocale = medusaLocale(locale)
48
60
  const {
49
61
  cart,
50
62
  cartId,
@@ -82,10 +94,14 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
82
94
  useEffect(() => {
83
95
  if (returnCartId && returnCartId !== cartId) {
84
96
  void adoptCart(returnCartId).catch((cause) =>
85
- setError(cause instanceof Error ? cause.message : "A visszatérő kosár nem tölthető be."),
97
+ setError(
98
+ cause instanceof Error
99
+ ? cause.message
100
+ : localized(locale, "A visszatérő kosár nem tölthető be.", "The returning cart could not be loaded."),
101
+ ),
86
102
  )
87
103
  }
88
- }, [adoptCart, cartId, returnCartId])
104
+ }, [adoptCart, cartId, locale, returnCartId])
89
105
 
90
106
  useEffect(() => {
91
107
  void listLegalDocuments(config)
@@ -145,46 +161,89 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
145
161
  const legalReady = requiredLegal.every((doc) => accepted[doc.key] === true)
146
162
 
147
163
  const acceptRequiredLegal = useCallback(async () => {
148
- if (!cartId) throw new Error("Nincs aktív kosár.")
164
+ if (!cartId) {
165
+ throw new Error(localized(locale, "Nincs aktív kosár.", "There is no active cart."))
166
+ }
149
167
  const missing = requiredLegal.filter((doc) => !accepted[doc.key])
150
- if (missing.length) throw new Error("A rendeléshez el kell fogadnod a kötelező jogi nyilatkozatokat.")
168
+ if (missing.length) {
169
+ throw new Error(
170
+ localized(
171
+ locale,
172
+ "A rendeléshez el kell fogadnod a kötelező jogi nyilatkozatokat.",
173
+ "You must accept the required legal documents before placing the order.",
174
+ ),
175
+ )
176
+ }
151
177
  await Promise.all(requiredLegal.map((doc) => acceptLegalDocument(config, doc.key, { cartId })))
152
- }, [accepted, cartId, config, requiredLegal])
178
+ }, [accepted, cartId, config, locale, requiredLegal])
153
179
 
154
180
  const completeOrder = useCallback(async () => {
155
- if (!cartId) throw new Error("Nincs aktív kosár.")
181
+ if (!cartId) {
182
+ throw new Error(localized(locale, "Nincs aktív kosár.", "There is no active cart."))
183
+ }
156
184
  setBusy("complete")
157
185
  setError(null)
158
186
  try {
159
187
  const result = await api.complete(cartId)
160
188
  if (result.type === "order" && isRecord(result.order)) {
161
189
  const orderId = stringValue(result.order.id)
162
- if (!orderId) throw new Error("A rendelés létrejött, de hiányzik az order ID.")
190
+ if (!orderId) {
191
+ throw new Error(
192
+ localized(
193
+ locale,
194
+ "A rendelés létrejött, de hiányzik az order ID.",
195
+ "The order was created, but its order ID is missing.",
196
+ ),
197
+ )
198
+ }
163
199
  clearCart()
164
- router.push(`/checkout/success?order_id=${encodeURIComponent(orderId)}`)
200
+ router.push(`${routes.checkoutSuccess}?order_id=${encodeURIComponent(orderId)}`)
165
201
  return
166
202
  }
167
203
  const detail = isRecord(result.cart) ? stringValue(result.cart.error || result.cart.message) : ""
168
- throw new Error(detail || "A rendelés még nem zárható le. Ellenőrizd a fizetés állapotát.")
204
+ throw new Error(
205
+ detail ||
206
+ localized(
207
+ locale,
208
+ "A rendelés még nem zárható le. Ellenőrizd a fizetés állapotát.",
209
+ "The order cannot be completed yet. Check the payment status.",
210
+ ),
211
+ )
169
212
  } finally {
170
213
  setBusy(null)
171
214
  }
172
- }, [api, cartId, clearCart, router])
215
+ }, [api, cartId, clearCart, locale, router, routes.checkoutSuccess])
173
216
 
174
217
  useEffect(() => {
175
218
  if (returnAttempted.current || !cartId || !cart || (!stripeReturn && !simplePayReturn)) return
176
219
  returnAttempted.current = true
177
- setMessage(simplePayReturn
178
- ? `SimplePay visszatérés: ${simplePayReturn}. A rendelés státuszának ellenőrzése folyamatban.`
179
- : "A bankkártyás fizetés után visszatértél. A rendelés lezárása folyamatban.")
220
+ setMessage(
221
+ simplePayReturn
222
+ ? localized(
223
+ locale,
224
+ `SimplePay visszatérés: ${simplePayReturn}. A rendelés státuszának ellenőrzése folyamatban.`,
225
+ `SimplePay return: ${simplePayReturn}. Checking the order status.`,
226
+ )
227
+ : localized(
228
+ locale,
229
+ "A bankkártyás fizetés után visszatértél. A rendelés lezárása folyamatban.",
230
+ "You returned after card payment. The order is being completed.",
231
+ ),
232
+ )
180
233
  void completeOrder().catch((cause) => {
181
- setError(cause instanceof Error ? cause.message : "A rendelés még nem zárható le.")
234
+ setError(
235
+ cause instanceof Error
236
+ ? cause.message
237
+ : localized(locale, "A rendelés még nem zárható le.", "The order cannot be completed yet."),
238
+ )
182
239
  })
183
- }, [cart, cartId, completeOrder, simplePayReturn, stripeReturn])
240
+ }, [cart, cartId, completeOrder, locale, simplePayReturn, stripeReturn])
184
241
 
185
242
  const saveAddress = async () => {
186
- if (!cartId) throw new Error("A kosár még nem áll készen.")
187
- validateAddress(address)
243
+ if (!cartId) {
244
+ throw new Error(localized(locale, "A kosár még nem áll készen.", "The cart is not ready yet."))
245
+ }
246
+ validateAddress(address, locale)
188
247
  setBusy("address")
189
248
  setError(null)
190
249
  try {
@@ -207,9 +266,13 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
207
266
  })
208
267
  await refresh(cartId)
209
268
  await loadShippingOptions()
210
- setMessage("Kapcsolati és szállítási adatok mentve.")
269
+ setMessage(copy.saveAddressSuccess)
211
270
  } catch (cause) {
212
- setError(cause instanceof Error ? cause.message : "A cím mentése nem sikerült.")
271
+ setError(
272
+ cause instanceof Error
273
+ ? cause.message
274
+ : localized(locale, "A cím mentése nem sikerült.", "The address could not be saved."),
275
+ )
213
276
  } finally {
214
277
  setBusy(null)
215
278
  }
@@ -228,48 +291,68 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
228
291
  if (kind === "foxpost") setPickupPoints((await api.foxpostLockers()).lockers)
229
292
  if (kind === "gls") setPickupPoints((await api.glsDeliveryPoints()).deliveryPoints)
230
293
  if (kind === "dpd") {
231
- setPickupPoints((await api.dpdPickupPoints({
232
- country: address.country_code,
233
- postalCode: address.postal_code,
234
- city: address.city,
235
- limit: "100",
236
- })).pickupPoints)
294
+ setPickupPoints(
295
+ (
296
+ await api.dpdPickupPoints({
297
+ country: address.country_code,
298
+ postalCode: address.postal_code,
299
+ city: address.city,
300
+ limit: "100",
301
+ })
302
+ ).pickupPoints,
303
+ )
237
304
  }
238
305
  if (kind === "mpl") {
239
- setPickupPoints((await api.mplDeliveryPlaces({
240
- postCode: address.postal_code,
241
- city: address.city,
242
- })).deliveryPlaces)
306
+ setPickupPoints(
307
+ (
308
+ await api.mplDeliveryPlaces({
309
+ postCode: address.postal_code,
310
+ city: address.city,
311
+ })
312
+ ).deliveryPlaces,
313
+ )
243
314
  }
244
315
  } catch (cause) {
245
- setError(cause instanceof Error ? cause.message : "A csomagpontok nem tölthetők be.")
316
+ setError(
317
+ cause instanceof Error
318
+ ? cause.message
319
+ : localized(locale, "A csomagpontok nem tölthetők be.", "Pickup points could not be loaded."),
320
+ )
246
321
  } finally {
247
322
  setBusy(null)
248
323
  }
249
324
  }
250
325
 
251
326
  const saveShipping = async () => {
252
- if (!cartId || !selectedShipping) throw new Error("Válassz szállítási módot.")
327
+ if (!cartId || !selectedShipping) {
328
+ throw new Error(localized(locale, "Válassz szállítási módot.", "Choose a shipping method."))
329
+ }
253
330
  const optionId = stringValue(selectedShipping.id)
254
331
  const kind = pickupKind(selectedShipping)
255
332
  const selectedPoint = pickupPoints.find((point) => pickupKey(point) === selectedPickupKey) || null
256
- const data = shippingData(kind, selectedPoint, packetaPointId, packetaPointName)
333
+ const data = shippingData(kind, selectedPoint, packetaPointId, packetaPointName, locale)
257
334
  setBusy("shipping")
258
335
  setError(null)
259
336
  try {
260
337
  const result = await api.addShippingMethod(cartId, optionId, data)
261
338
  await refresh(cartId)
262
339
  await loadProviders(result.cart)
263
- setMessage("Szállítási mód kiválasztva.")
340
+ setMessage(localized(locale, "Szállítási mód kiválasztva.", "Shipping method selected."))
264
341
  } catch (cause) {
265
- setError(cause instanceof Error ? cause.message : "A szállítási mód nem menthető.")
342
+ setError(
343
+ cause instanceof Error
344
+ ? cause.message
345
+ : localized(locale, "A szállítási mód nem menthető.", "The shipping method could not be saved."),
346
+ )
266
347
  } finally {
267
348
  setBusy(null)
268
349
  }
269
350
  }
270
351
 
271
352
  const preparePayment = async (id: string) => {
272
- if (!cartId) throw new Error("Nincs aktív kosár.")
353
+ if (!cartId) {
354
+ throw new Error(localized(locale, "Nincs aktív kosár.", "There is no active cart."))
355
+ }
273
356
  setBusy("payment")
274
357
  setError(null)
275
358
  setSelectedProvider(id)
@@ -280,29 +363,43 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
280
363
  if (!collectionId) {
281
364
  const created = await api.createPaymentCollection(cartId)
282
365
  collectionId = stringValue(created.payment_collection.id)
283
- if (!collectionId) throw new Error("A payment collection nem jött létre.")
366
+ if (!collectionId) {
367
+ throw new Error(
368
+ localized(
369
+ locale,
370
+ "A payment collection nem jött létre.",
371
+ "The payment collection could not be created.",
372
+ ),
373
+ )
374
+ }
284
375
  }
285
376
  const selected = await api.selectPayment(cartId, collectionId, id)
286
377
  current = selected.cart
287
378
  setPreparedCart(current)
288
379
  await refresh(cartId)
289
- setMessage("Fizetési mód előkészítve.")
380
+ setMessage(copy.paymentPrepared)
290
381
  } catch (cause) {
291
382
  setPreparedCart(null)
292
- setError(cause instanceof Error ? cause.message : "A fizetési mód nem készíthető elő.")
383
+ setError(
384
+ cause instanceof Error
385
+ ? cause.message
386
+ : localized(locale, "A fizetési mód nem készíthető elő.", "The payment method could not be prepared."),
387
+ )
293
388
  } finally {
294
389
  setBusy(null)
295
390
  }
296
391
  }
297
392
 
298
- if (loading) return <div className="empty-state">Pénztár betöltése…</div>
393
+ if (loading) return <div className="empty-state">{copy.checkoutLoading}</div>
299
394
  if (!cart || !cartId) {
300
- return <div className="empty-state">A pénztárhoz előbb tegyél terméket a kosárba.</div>
395
+ return <div className="empty-state">{copy.checkoutNeedsCart}</div>
301
396
  }
302
397
 
303
398
  const pickup = selectedShipping ? pickupKind(selectedShipping) : null
304
399
  const filteredPoints = pickupSearch.trim()
305
- ? pickupPoints.filter((point) => pointLabel(point).toLowerCase().includes(pickupSearch.trim().toLowerCase())).slice(0, 200)
400
+ ? pickupPoints
401
+ .filter((point) => pointLabel(point).toLowerCase().includes(pickupSearch.trim().toLowerCase()))
402
+ .slice(0, 200)
306
403
  : pickupPoints.slice(0, 200)
307
404
  const effectiveCart = preparedCart || cart
308
405
  const session = activePaymentSession(effectiveCart)
@@ -318,27 +415,29 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
318
415
  <div className="checkout-layout">
319
416
  <div className="stack">
320
417
  <section className="panel stack">
321
- <SectionTitle step="1" title="Kapcsolat és szállítási cím" />
418
+ <SectionTitle step="1" title={copy.contactAndAddress} />
322
419
  <div className="form-grid two-col">
323
- <Field label="E-mail" value={address.email} type="email" onChange={(value) => updateAddress(setAddress, "email", value)} />
324
- <Field label="Telefon" value={address.phone} onChange={(value) => updateAddress(setAddress, "phone", value)} />
325
- <Field label="Keresztnév" value={address.first_name} onChange={(value) => updateAddress(setAddress, "first_name", value)} />
326
- <Field label="Vezetéknév" value={address.last_name} onChange={(value) => updateAddress(setAddress, "last_name", value)} />
327
- <Field label="Cég (opcionális)" value={address.company} onChange={(value) => updateAddress(setAddress, "company", value)} />
328
- <Field label="Ország" value={address.country_code} onChange={(value) => updateAddress(setAddress, "country_code", value.toUpperCase())} />
329
- <Field label="Irányítószám" value={address.postal_code} onChange={(value) => updateAddress(setAddress, "postal_code", value)} />
330
- <Field label="Város" value={address.city} onChange={(value) => updateAddress(setAddress, "city", value)} />
331
- <Field label="Utca, házszám" value={address.address_1} onChange={(value) => updateAddress(setAddress, "address_1", value)} />
332
- <Field label="Cím kiegészítés" value={address.address_2} onChange={(value) => updateAddress(setAddress, "address_2", value)} />
420
+ <Field label={copy.email} value={address.email} type="email" onChange={(value) => updateAddress(setAddress, "email", value)} />
421
+ <Field label={copy.phone} value={address.phone} onChange={(value) => updateAddress(setAddress, "phone", value)} />
422
+ <Field label={copy.firstName} value={address.first_name} onChange={(value) => updateAddress(setAddress, "first_name", value)} />
423
+ <Field label={copy.lastName} value={address.last_name} onChange={(value) => updateAddress(setAddress, "last_name", value)} />
424
+ <Field label={copy.companyOptional} value={address.company} onChange={(value) => updateAddress(setAddress, "company", value)} />
425
+ <Field label={copy.country} value={address.country_code} onChange={(value) => updateAddress(setAddress, "country_code", value.toUpperCase())} />
426
+ <Field label={copy.postalCode} value={address.postal_code} onChange={(value) => updateAddress(setAddress, "postal_code", value)} />
427
+ <Field label={copy.city} value={address.city} onChange={(value) => updateAddress(setAddress, "city", value)} />
428
+ <Field label={copy.address1} value={address.address_1} onChange={(value) => updateAddress(setAddress, "address_1", value)} />
429
+ <Field label={copy.address2} value={address.address_2} onChange={(value) => updateAddress(setAddress, "address_2", value)} />
333
430
  </div>
334
431
  <button className="button secondary" type="button" disabled={busy === "address" || mutating} onClick={() => void saveAddress()}>
335
- {busy === "address" ? "Mentés…" : "Adatok mentése és szállítás betöltése"}
432
+ {busy === "address" ? copy.saving : copy.saveAddressAndLoadShipping}
336
433
  </button>
337
434
  </section>
338
435
 
339
436
  <section className="panel stack">
340
- <SectionTitle step="2" title="Szállítás" />
341
- {!shippingOptions.length ? <p className="muted">Mentsd el a címet az elérhető szállítási módok betöltéséhez.</p> : (
437
+ <SectionTitle step="2" title={copy.shipping} />
438
+ {!shippingOptions.length ? (
439
+ <p className="muted">{copy.chooseShippingFirst}</p>
440
+ ) : (
342
441
  <div className="choice-list">
343
442
  {shippingOptions.map((option) => {
344
443
  const id = stringValue(option.id)
@@ -347,7 +446,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
347
446
  <input type="radio" name="shipping" checked={stringValue(selectedShipping?.id) === id} onChange={() => void selectShippingOption(option)} />
348
447
  <span>
349
448
  <strong>{stringValue(option.name || option.id)}</strong>
350
- {typeof option.amount === "number" ? <small>{formatMoney(option.amount, currency, config.store.locale)}</small> : null}
449
+ {typeof option.amount === "number" ? <small>{formatMoney(option.amount, currency, numberLocale)}</small> : null}
351
450
  </span>
352
451
  </label>
353
452
  )
@@ -357,43 +456,62 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
357
456
 
358
457
  {pickup && pickup !== "packeta" ? (
359
458
  <div className="stack-sm">
360
- <Field label="Csomagpont keresése" value={pickupSearch} onChange={setPickupSearch} />
459
+ <Field label={copy.pickupSearch} value={pickupSearch} onChange={setPickupSearch} />
361
460
  <label>
362
- Átvételi pont
461
+ {copy.pickupPoint}
363
462
  <select value={selectedPickupKey} onChange={(event) => setSelectedPickupKey(event.target.value)} disabled={busy === "pickup"}>
364
- <option value="">Válassz átvételi pontot</option>
365
- {filteredPoints.map((point) => <option key={pickupKey(point)} value={pickupKey(point)}>{pointLabel(point)}</option>)}
463
+ <option value="">{copy.choosePickupPoint}</option>
464
+ {filteredPoints.map((point) => (
465
+ <option key={pickupKey(point)} value={pickupKey(point)}>{pointLabel(point)}</option>
466
+ ))}
366
467
  </select>
367
468
  </label>
368
- {pickupPoints.length > 200 ? <p className="muted small">Írj be várost vagy címet a lista szűkítéséhez.</p> : null}
469
+ {pickupPoints.length > 200 ? <p className="muted small">{copy.filterPickupHint}</p> : null}
369
470
  </div>
370
471
  ) : null}
371
472
 
372
473
  {pickup === "packeta" ? (
373
474
  <div className="notice warning stack-sm">
374
- <strong>Packeta pont</strong>
375
- <span>A Core nem tesz ki titkos Packeta credentialt a böngészőbe. Add meg az official Packeta widgetből kapott pont azonosítóját; ügyfél-designnál a widget ugyanebbe a mezőbe köthető.</span>
475
+ <strong>{copy.packetaPoint}</strong>
476
+ <span>{copy.packetaHint}</span>
376
477
  <Field label="Packeta point ID" value={packetaPointId} onChange={setPacketaPointId} />
377
- <Field label="Pont neve" value={packetaPointName} onChange={setPacketaPointName} />
478
+ <Field label={copy.pointName} value={packetaPointName} onChange={setPacketaPointName} />
378
479
  </div>
379
480
  ) : null}
380
481
 
381
482
  {selectedShipping ? (
382
- <button className="button secondary" type="button" disabled={busy === "shipping" || (Boolean(pickup) && pickup !== "packeta" && !selectedPickupKey) || (pickup === "packeta" && !packetaPointId.trim())} onClick={() => void saveShipping()}>
383
- {busy === "shipping" ? "Mentés…" : "Szállítás kiválasztása"}
483
+ <button
484
+ className="button secondary"
485
+ type="button"
486
+ disabled={
487
+ busy === "shipping" ||
488
+ (Boolean(pickup) && pickup !== "packeta" && !selectedPickupKey) ||
489
+ (pickup === "packeta" && !packetaPointId.trim())
490
+ }
491
+ onClick={() => void saveShipping()}
492
+ >
493
+ {busy === "shipping" ? copy.saving : copy.selectShipping}
384
494
  </button>
385
495
  ) : null}
386
496
  </section>
387
497
 
388
498
  <section className="panel stack">
389
- <SectionTitle step="3" title="Fizetés" />
390
- {!providers.length ? <p className="muted">Válassz és ments szállítási módot a fizetési lehetőségek betöltéséhez.</p> : (
499
+ <SectionTitle step="3" title={copy.payment} />
500
+ {!providers.length ? (
501
+ <p className="muted">{copy.chooseShippingForPayments}</p>
502
+ ) : (
391
503
  <div className="choice-list">
392
504
  {providers.map((provider) => {
393
505
  const id = stringValue(provider.id)
394
506
  const cod = shippingMethodIsCod(cart)
395
507
  return (
396
- <button className={`choice-card choice-button${selectedProvider === id ? " selected" : ""}`} type="button" key={id} disabled={busy === "payment"} onClick={() => void preparePayment(id)}>
508
+ <button
509
+ className={`choice-card choice-button${selectedProvider === id ? " selected" : ""}`}
510
+ type="button"
511
+ key={id}
512
+ disabled={busy === "payment"}
513
+ onClick={() => void preparePayment(id)}
514
+ >
397
515
  <strong>{providerLabel(id, cod)}</strong>
398
516
  <small>{id}</small>
399
517
  </button>
@@ -412,7 +530,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
412
530
  onConfirmed={completeOrder}
413
531
  />
414
532
  ) : stripeSelected ? (
415
- <div className="notice warning">A Stripe session még nem adott használható client secretet. Próbáld újra a fizetési mód kiválasztását.</div>
533
+ <div className="notice warning">{copy.stripeMissingSecret}</div>
416
534
  ) : null}
417
535
 
418
536
  {simplePaySelected ? (
@@ -420,52 +538,108 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
420
538
  className="button button-large"
421
539
  type="button"
422
540
  disabled={!simplePayRedirect || !legalReady}
423
- onClick={() => void acceptRequiredLegal().then(() => { if (simplePayRedirect) window.location.assign(simplePayRedirect) }).catch((cause) => setError(cause instanceof Error ? cause.message : "A jogi elfogadás nem rögzíthető."))}
541
+ onClick={() =>
542
+ void acceptRequiredLegal()
543
+ .then(() => {
544
+ if (simplePayRedirect) window.location.assign(simplePayRedirect)
545
+ })
546
+ .catch((cause) =>
547
+ setError(
548
+ cause instanceof Error
549
+ ? cause.message
550
+ : localized(locale, "A jogi elfogadás nem rögzíthető.", "The legal consent could not be recorded."),
551
+ ),
552
+ )
553
+ }
424
554
  >
425
- Tovább az OTP SimplePayhez
555
+ {copy.simplepayContinue}
426
556
  </button>
427
557
  ) : null}
428
558
 
429
559
  {systemSelected ? (
430
- <button className="button button-large" type="button" disabled={!legalReady || busy === "complete"} onClick={() => void acceptRequiredLegal().then(completeOrder).catch((cause) => setError(cause instanceof Error ? cause.message : "A rendelés nem zárható le."))}>
431
- {busy === "complete" ? "Rendelés leadása…" : shippingMethodIsCod(cart) ? "Megrendelés utánvéttel" : "Megrendelés leadása"}
560
+ <button
561
+ className="button button-large"
562
+ type="button"
563
+ disabled={!legalReady || busy === "complete"}
564
+ onClick={() =>
565
+ void acceptRequiredLegal()
566
+ .then(completeOrder)
567
+ .catch((cause) =>
568
+ setError(
569
+ cause instanceof Error
570
+ ? cause.message
571
+ : localized(locale, "A rendelés nem zárható le.", "The order could not be completed."),
572
+ ),
573
+ )
574
+ }
575
+ >
576
+ {busy === "complete"
577
+ ? copy.orderSubmitting
578
+ : shippingMethodIsCod(cart)
579
+ ? copy.orderSubmitCod
580
+ : copy.orderSubmit}
432
581
  </button>
433
582
  ) : null}
434
583
  </section>
435
584
 
436
585
  <section className="panel stack">
437
- <SectionTitle step="4" title="Jogi nyilatkozatok" />
438
- {requiredLegal.length ? requiredLegal.map((doc) => (
439
- <label className="legal-check" key={doc.key}>
440
- <input type="checkbox" checked={Boolean(accepted[doc.key])} onChange={(event) => setAccepted((current) => ({ ...current, [doc.key]: event.target.checked }))} />
441
- <span>
442
- Elfogadom: <strong>{doc.title || doc.key}</strong>
443
- {doc.pdfEndpoint ? <a href={doc.pdfEndpoint} target="_blank" rel="noreferrer"> Dokumentum megnyitása</a> : null}
444
- </span>
445
- </label>
446
- )) : <p className="muted">Nincs kötelező checkout dokumentum.</p>}
586
+ <SectionTitle step="4" title={copy.legalStatements} />
587
+ {requiredLegal.length ? (
588
+ requiredLegal.map((doc) => (
589
+ <label className="legal-check" key={doc.key}>
590
+ <input
591
+ type="checkbox"
592
+ checked={Boolean(accepted[doc.key])}
593
+ onChange={(event) =>
594
+ setAccepted((current) => ({ ...current, [doc.key]: event.target.checked }))
595
+ }
596
+ />
597
+ <span>
598
+ {copy.accept}: <strong>{doc.title || doc.key}</strong>
599
+ {doc.pdfEndpoint ? (
600
+ <a href={doc.pdfEndpoint} target="_blank" rel="noreferrer"> {copy.openDocument}</a>
601
+ ) : null}
602
+ </span>
603
+ </label>
604
+ ))
605
+ ) : (
606
+ <p className="muted">{copy.noRequiredLegal}</p>
607
+ )}
447
608
  </section>
448
609
 
449
610
  {message ? <div className="notice success-box">{message}</div> : null}
450
611
  {error || cartError ? <div className="notice error-box">{error || cartError}</div> : null}
451
612
  {(stripeReturn || simplePayReturn) && error ? (
452
- <button className="button secondary" type="button" disabled={busy === "complete"} onClick={() => void completeOrder().catch((cause) => setError(cause instanceof Error ? cause.message : "A rendelés még nem zárható le."))}>
453
- Fizetés állapotának újraellenőrzése
613
+ <button
614
+ className="button secondary"
615
+ type="button"
616
+ disabled={busy === "complete"}
617
+ onClick={() =>
618
+ void completeOrder().catch((cause) =>
619
+ setError(
620
+ cause instanceof Error
621
+ ? cause.message
622
+ : localized(locale, "A rendelés még nem zárható le.", "The order cannot be completed yet."),
623
+ ),
624
+ )
625
+ }
626
+ >
627
+ {copy.recheckPayment}
454
628
  </button>
455
629
  ) : null}
456
630
  </div>
457
631
 
458
632
  <aside className="checkout-summary panel stack-sm">
459
- <p className="eyebrow">Rendelés összesítő</p>
633
+ <p className="eyebrow">{copy.orderSummary}</p>
460
634
  {asRecords(cart.items).map((item) => (
461
635
  <div className="summary-line" key={stringValue(item.id)}>
462
636
  <span>{stringValue(item.product_title || item.title)} × {stringValue(item.quantity)}</span>
463
- <span>{typeof item.total === "number" ? formatMoney(item.total, currency, config.store.locale) : ""}</span>
637
+ <span>{typeof item.total === "number" ? formatMoney(item.total, currency, numberLocale) : ""}</span>
464
638
  </div>
465
639
  ))}
466
640
  <div className="summary-total">
467
- <span>Összesen</span>
468
- <strong>{formatMoney(cartTotal(cart), currency, config.store.locale)}</strong>
641
+ <span>{copy.total}</span>
642
+ <strong>{formatMoney(cartTotal(cart), currency, numberLocale)}</strong>
469
643
  </div>
470
644
  </aside>
471
645
  </div>
@@ -473,17 +647,61 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
473
647
  }
474
648
 
475
649
  function emptyAddress(country: string): AddressState {
476
- return { email: "", first_name: "", last_name: "", company: "", phone: "", country_code: country.toUpperCase(), postal_code: "", city: "", province: "", address_1: "", address_2: "" }
650
+ return {
651
+ email: "",
652
+ first_name: "",
653
+ last_name: "",
654
+ company: "",
655
+ phone: "",
656
+ country_code: country.toUpperCase(),
657
+ postal_code: "",
658
+ city: "",
659
+ province: "",
660
+ address_1: "",
661
+ address_2: "",
662
+ }
477
663
  }
478
664
 
479
- function updateAddress(setter: React.Dispatch<React.SetStateAction<AddressState>>, key: keyof AddressState, value: string) {
665
+ function updateAddress(
666
+ setter: React.Dispatch<React.SetStateAction<AddressState>>,
667
+ key: keyof AddressState,
668
+ value: string,
669
+ ) {
480
670
  setter((current) => ({ ...current, [key]: value }))
481
671
  }
482
672
 
483
- function validateAddress(address: AddressState) {
484
- if (!/^\S+@\S+\.\S+$/.test(address.email)) throw new Error("Érvényes e-mail-cím szükséges.")
485
- for (const [label, value] of [["keresztnév", address.first_name], ["vezetéknév", address.last_name], ["telefon", address.phone], ["ország", address.country_code], ["irányítószám", address.postal_code], ["város", address.city], ["cím", address.address_1]] as const) {
486
- if (!value.trim()) throw new Error(`A(z) ${label} megadása kötelező.`)
673
+ function validateAddress(address: AddressState, locale: StorefrontLocale) {
674
+ if (!/^\S+@\S+\.\S+$/.test(address.email)) {
675
+ throw new Error(localized(locale, "Érvényes e-mail-cím szükséges.", "Enter a valid email address."))
676
+ }
677
+ const fields = locale === "en"
678
+ ? [
679
+ ["first name", address.first_name],
680
+ ["last name", address.last_name],
681
+ ["phone", address.phone],
682
+ ["country", address.country_code],
683
+ ["postal code", address.postal_code],
684
+ ["city", address.city],
685
+ ["address", address.address_1],
686
+ ] as const
687
+ : [
688
+ ["keresztnév", address.first_name],
689
+ ["vezetéknév", address.last_name],
690
+ ["telefon", address.phone],
691
+ ["ország", address.country_code],
692
+ ["irányítószám", address.postal_code],
693
+ ["város", address.city],
694
+ ["cím", address.address_1],
695
+ ] as const
696
+
697
+ for (const [label, value] of fields) {
698
+ if (!value.trim()) {
699
+ throw new Error(
700
+ locale === "en"
701
+ ? `The ${label} field is required.`
702
+ : `A(z) ${label} megadása kötelező.`,
703
+ )
704
+ }
487
705
  }
488
706
  }
489
707
 
@@ -491,7 +709,17 @@ function SectionTitle({ step, title }: { step: string; title: string }) {
491
709
  return <div className="section-title"><span className="step-badge">{step}</span><h2>{title}</h2></div>
492
710
  }
493
711
 
494
- function Field({ label, value, onChange, type = "text" }: { label: string; value: string; onChange: (value: string) => void; type?: string }) {
712
+ function Field({
713
+ label,
714
+ value,
715
+ onChange,
716
+ type = "text",
717
+ }: {
718
+ label: string
719
+ value: string
720
+ onChange: (value: string) => void
721
+ type?: string
722
+ }) {
495
723
  return <label>{label}<input type={type} value={value} onChange={(event) => onChange(event.target.value)} /></label>
496
724
  }
497
725
 
@@ -508,7 +736,15 @@ function pickupKind(option: JsonRecord): PickupKind {
508
736
  }
509
737
 
510
738
  function pickupKey(point: JsonRecord) {
511
- return stringValue(point.id || point.operatorId || point.placeId || point.code || point.shop_id || point.location_id || point.name)
739
+ return stringValue(
740
+ point.id ||
741
+ point.operatorId ||
742
+ point.placeId ||
743
+ point.code ||
744
+ point.shop_id ||
745
+ point.location_id ||
746
+ point.name,
747
+ )
512
748
  }
513
749
 
514
750
  function pointLabel(point: JsonRecord) {
@@ -519,16 +755,32 @@ function pointLabel(point: JsonRecord) {
519
755
  return [name, [postal, city].filter(Boolean).join(" "), address].filter(Boolean).join(" – ") || pickupKey(point)
520
756
  }
521
757
 
522
- function shippingData(kind: PickupKind, point: JsonRecord | null, packetaId: string, packetaName: string): Record<string, unknown> | undefined {
758
+ function shippingData(
759
+ kind: PickupKind,
760
+ point: JsonRecord | null,
761
+ packetaId: string,
762
+ packetaName: string,
763
+ locale: StorefrontLocale,
764
+ ): Record<string, unknown> | undefined {
523
765
  if (!kind) return undefined
524
766
  if (kind === "packeta") {
525
- if (!packetaId.trim()) throw new Error("A Packeta pont azonosítója kötelező.")
767
+ if (!packetaId.trim()) {
768
+ throw new Error(
769
+ localized(locale, "A Packeta pont azonosítója kötelező.", "The Packeta pickup point ID is required."),
770
+ )
771
+ }
526
772
  return { packeta: { pickupPoint: { id: packetaId.trim(), name: packetaName.trim() || undefined } } }
527
773
  }
528
- if (!point) throw new Error("Válassz átvételi pontot.")
774
+ if (!point) {
775
+ throw new Error(localized(locale, "Válassz átvételi pontot.", "Choose a pickup point."))
776
+ }
529
777
  if (kind === "foxpost") return { foxpost: { locker: point, packageSize: "M" } }
530
778
  if (kind === "gls") return { gls: { deliveryPoint: point } }
531
779
  if (kind === "dpd") return { dpd: { pickupPoint: point } }
532
780
  if (kind === "mpl") return { mpl: { pickupPoint: point } }
533
781
  return undefined
534
782
  }
783
+
784
+ function localized(locale: StorefrontLocale, hu: string, en: string) {
785
+ return locale === "en" ? en : hu
786
+ }