@hszrdm/create-commerce 1.7.0 → 1.9.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 (45) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +3 -0
  3. package/templates/backend/.env.example +24 -1
  4. package/templates/backend/package.json +8 -7
  5. package/templates/backend/scripts/sync-env-example.mjs +55 -0
  6. package/templates/backend/scripts/verify-env-contract.mjs +6 -5
  7. package/templates/backend/src/scripts/verify-runtime-modules.ts +1 -0
  8. package/templates/storefront/.env.example +6 -0
  9. package/templates/storefront/.env.local +3 -0
  10. package/templates/storefront/package.json +2 -1
  11. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +5 -1
  12. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +14 -5
  13. package/templates/storefront/src/app/[countryCode]/products/page.tsx +10 -1
  14. package/templates/storefront/src/app/account/orders/[id]/page.tsx +17 -2
  15. package/templates/storefront/src/app/checkout/success/page.tsx +5 -0
  16. package/templates/storefront/src/app/documents/page.tsx +27 -0
  17. package/templates/storefront/src/app/layout.tsx +8 -1
  18. package/templates/storefront/src/components/add-to-cart.tsx +16 -14
  19. package/templates/storefront/src/components/arukereso-backlink.tsx +43 -0
  20. package/templates/storefront/src/components/arukereso-trusted-shop-widget.tsx +81 -0
  21. package/templates/storefront/src/components/arukereso-trusted-shop.tsx +71 -0
  22. package/templates/storefront/src/components/carrier-pickup-adapter.ts +93 -0
  23. package/templates/storefront/src/components/carrier-pickup-dialog.tsx +119 -0
  24. package/templates/storefront/src/components/carrier-pickup-map.tsx +200 -0
  25. package/templates/storefront/src/components/cart-view.tsx +4 -2
  26. package/templates/storefront/src/components/category-documents.tsx +18 -0
  27. package/templates/storefront/src/components/checkout-analytics.tsx +22 -0
  28. package/templates/storefront/src/components/checkout-flow.tsx +75 -115
  29. package/templates/storefront/src/components/document-list.tsx +47 -0
  30. package/templates/storefront/src/components/google-ads-cart-remarketing.tsx +71 -0
  31. package/templates/storefront/src/components/google-ads-purchase.tsx +37 -0
  32. package/templates/storefront/src/components/price-display.tsx +39 -0
  33. package/templates/storefront/src/components/product-card.tsx +7 -6
  34. package/templates/storefront/src/components/product-documents.tsx +18 -0
  35. package/templates/storefront/src/components/product-view-tracker.tsx +17 -2
  36. package/templates/storefront/src/components/reorder-button.tsx +74 -0
  37. package/templates/storefront/src/components/variant-price-display.tsx +7 -11
  38. package/templates/storefront/src/lib/core/catalog.ts +6 -2
  39. package/templates/storefront/src/lib/core/commerce.ts +51 -0
  40. package/templates/storefront/src/lib/core/documents.ts +37 -0
  41. package/templates/storefront/src/lib/core/google-ads.ts +154 -7
  42. package/templates/storefront/src/lib/core/reorder.ts +26 -0
  43. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  44. package/templates/storefront/src/proxy.ts +2 -0
  45. package/templates/storefront/tests/carrier-pickup-adapter.test.mjs +69 -0
@@ -0,0 +1,81 @@
1
+ "use client"
2
+
3
+ import { useEffect, useRef } from "react"
4
+ import { medusaFetch } from "@/lib/core/client"
5
+
6
+ type WidgetResponse = {
7
+ enabled: boolean
8
+ code: string
9
+ }
10
+
11
+ export function ArukeresoTrustedShopWidget() {
12
+ const hostRef = useRef<HTMLDivElement>(null)
13
+
14
+ useEffect(() => {
15
+ let cancelled = false
16
+ const host = hostRef.current
17
+ if (!host) return
18
+
19
+ void (async () => {
20
+ try {
21
+ const data = await medusaFetch<WidgetResponse>("/store/arukereso/widget", {
22
+ cache: "no-store",
23
+ })
24
+ if (cancelled || !data.enabled || !data.code) return
25
+ mountOfficialWidget(host, data.code)
26
+ } catch {
27
+ // A badge/widget hibája nem zavarhatja a storefront működését.
28
+ }
29
+ })()
30
+
31
+ return () => {
32
+ cancelled = true
33
+ host.replaceChildren()
34
+ }
35
+ }, [])
36
+
37
+ return <div ref={hostRef} data-arukereso-trusted-shop-widget />
38
+ }
39
+
40
+ function mountOfficialWidget(host: HTMLDivElement, code: string) {
41
+ const template = document.createElement("template")
42
+ template.innerHTML = code
43
+
44
+ const scripts = Array.from(template.content.querySelectorAll("script"))
45
+ for (const script of scripts) script.remove()
46
+
47
+ host.replaceChildren(template.content.cloneNode(true))
48
+
49
+ for (const original of scripts) {
50
+ const src = original.getAttribute("src")
51
+ if (!src || !isAllowedUrl(src)) continue
52
+
53
+ const script = document.createElement("script")
54
+ script.src = new URL(src, "https://www.arukereso.hu").toString()
55
+ script.async = original.async !== false
56
+ script.defer = original.defer
57
+ for (const attr of Array.from(original.attributes)) {
58
+ if (["src", "async", "defer"].includes(attr.name.toLowerCase())) continue
59
+ if (attr.name.toLowerCase().startsWith("on")) continue
60
+ script.setAttribute(attr.name, attr.value)
61
+ }
62
+ host.appendChild(script)
63
+ }
64
+ }
65
+
66
+ function isAllowedUrl(value: string) {
67
+ try {
68
+ const url = new URL(value, "https://www.arukereso.hu")
69
+ return (
70
+ url.protocol === "https:" &&
71
+ [
72
+ "arukereso.hu",
73
+ "www.arukereso.hu",
74
+ "assets.arukereso.com",
75
+ "static.arukereso.hu",
76
+ ].includes(url.hostname.toLowerCase())
77
+ )
78
+ } catch {
79
+ return false
80
+ }
81
+ }
@@ -0,0 +1,71 @@
1
+ "use client"
2
+
3
+ import { useEffect } from "react"
4
+ import { medusaRawFetch } from "@/lib/core/client"
5
+
6
+ const STORAGE_PREFIX = "hszrdm:arukereso-trusted-shop:v2:"
7
+
8
+ type TrustedShopResponse = {
9
+ token: string
10
+ web_api_key: string
11
+ process_url: string
12
+ script_url: string
13
+ }
14
+
15
+ type AkuWindow = Window & {
16
+ aku_request_done?: (w: unknown, c: string) => void
17
+ }
18
+
19
+ export function ArukeresoTrustedShop({ orderId }: { orderId: string }) {
20
+ useEffect(() => {
21
+ if (!orderId || typeof window === "undefined") return
22
+
23
+ const storageKey = `${STORAGE_PREFIX}${orderId}`
24
+ if (window.localStorage.getItem(storageKey) === "sent") return
25
+
26
+ let cancelled = false
27
+ let script: HTMLScriptElement | null = null
28
+ const target = window as AkuWindow
29
+ const previousCallback = target.aku_request_done
30
+
31
+ void (async () => {
32
+ try {
33
+ const response = await medusaRawFetch(
34
+ `/store/arukereso/trusted-shop/${encodeURIComponent(orderId)}`,
35
+ { method: "POST", body: JSON.stringify({}) },
36
+ )
37
+ if (cancelled || response.status === 204 || !response.ok) return
38
+
39
+ const data = (await response.json()) as TrustedShopResponse
40
+ if (!data.token || !data.web_api_key || !data.process_url || !data.script_url) return
41
+
42
+ let processed = false
43
+ target.aku_request_done = (_w, c) => {
44
+ if (processed || cancelled) return
45
+ processed = true
46
+
47
+ const image = new Image()
48
+ image.onload = () => window.localStorage.setItem(storageKey, "sent")
49
+ image.src = `${data.process_url}?Token=${encodeURIComponent(data.token)}&WebApiKey=${encodeURIComponent(data.web_api_key)}&C=${encodeURIComponent(String(c || Date.now()))}`
50
+ }
51
+
52
+ script = document.createElement("script")
53
+ script.type = "text/javascript"
54
+ script.src = data.script_url
55
+ script.async = true
56
+ ;(document.head || document.body).appendChild(script)
57
+ } catch {
58
+ // A Trusted Shop mérés hibája nem akadályozhatja a sikeres rendelési oldalt.
59
+ }
60
+ })()
61
+
62
+ return () => {
63
+ cancelled = true
64
+ if (script?.parentNode) script.parentNode.removeChild(script)
65
+ if (target.aku_request_done === previousCallback) return
66
+ target.aku_request_done = previousCallback
67
+ }
68
+ }, [orderId])
69
+
70
+ return null
71
+ }
@@ -0,0 +1,93 @@
1
+ export type CarrierPickupKind = "foxpost" | "gls" | "packeta" | "dpd" | "mpl"
2
+
3
+ export type CarrierPickupPoint = {
4
+ id: string
5
+ name: string
6
+ postalCode: string
7
+ city: string
8
+ address: string
9
+ provider: CarrierPickupKind
10
+ type?: string
11
+ raw: Record<string, unknown>
12
+ }
13
+
14
+ function record(value: unknown): Record<string, unknown> {
15
+ return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {}
16
+ }
17
+
18
+ function str(...values: unknown[]) {
19
+ for (const value of values) {
20
+ if (typeof value === "string" && value.trim()) return value.trim()
21
+ if (typeof value === "number" && Number.isFinite(value)) return String(value)
22
+ }
23
+ return ""
24
+ }
25
+
26
+ function addressText(value: unknown) {
27
+ if (typeof value === "string") return value.trim()
28
+ const item = record(value)
29
+ return str(item.street, item.address, [item.streetName, item.houseNumber].filter(Boolean).join(" "))
30
+ }
31
+
32
+ /** Provider-specific widget results are adapted to the same checkout model. */
33
+ export function normalizeCarrierPickupPoint(provider: CarrierPickupKind, value: unknown): CarrierPickupPoint | null {
34
+ const raw = record(value)
35
+ const contact = record(raw.contact)
36
+ const location = record(raw.location)
37
+ const addr = record(raw.address)
38
+ const address = provider === "gls" ? str(contact.address, addressText(raw.address)) :
39
+ provider === "dpd" ? str(raw.street, raw.address, location.address, addr.street, addr.address, [raw.street, raw.houseNo].filter(Boolean).join(" ")) :
40
+ provider === "foxpost" ? str(raw.address, raw.street) :
41
+ str(raw.address, raw.street, location.address, addr.street)
42
+ const id = provider === "foxpost" ? str(raw.operator_id, raw.operatorId, raw.place_id, raw.placeId) :
43
+ provider === "dpd" ? str(raw.id, raw.pickupPointId, raw.pudoId, raw.pudo_id, raw.parcelShopId, location.id) :
44
+ str(raw.id, raw.addressId, raw.location_id, raw.code)
45
+ const name = str(raw.name, raw.label, raw.shop_name, raw.title, contact.name, location.name)
46
+ const postalCode = str(raw.zip, raw.postalCode, raw.postCode, raw.post_code, raw.zipCode, raw.postal_code, contact.postalCode, location.zip, addr.zip)
47
+ const city = str(raw.city, contact.city, raw.country, raw.town, location.city, addr.city)
48
+ if (!id || !name || !postalCode || !city || !address) return null
49
+ return { id, name, postalCode, city, address, provider, type: str(raw.variant, raw.type, raw.group), raw }
50
+ }
51
+
52
+ /** Map fields to the existing Medusa fulfillment providers; preserve native IDs. */
53
+ export function carrierPointToShippingData(point: CarrierPickupPoint): Record<string, unknown> {
54
+ const p = point.raw
55
+ switch (point.provider) {
56
+ case "foxpost":
57
+ return { foxpost: { locker: {
58
+ operatorId: str(p.operator_id, p.operatorId) || null,
59
+ placeId: str(p.place_id, p.placeId) || null,
60
+ name: point.name, postalCode: point.postalCode, city: point.city,
61
+ address: point.address, findMe: str(p.findme, p.findMe) || null,
62
+ }, packageSize: "M" } }
63
+ case "gls":
64
+ return { gls: { deliveryPoint: {
65
+ id: point.id, name: point.name, countryCode: str(record(p.contact).countryCode, p.countryCode, "HU"),
66
+ postalCode: point.postalCode, city: point.city, address: point.address,
67
+ type: point.type === "parcel-shop" || point.type === "parcel-locker" ? point.type : null,
68
+ } } }
69
+ case "packeta":
70
+ return { packeta: { pickupPoint: {
71
+ id: point.id, name: point.name,
72
+ ...(str(p.carrierId, p.carrier_id) ? { carrierId: str(p.carrierId, p.carrier_id) } : {}),
73
+ ...(str(p.carrierPickupPoint, p.carrier_pickup_point) ? { carrierPickupPoint: str(p.carrierPickupPoint, p.carrier_pickup_point) } : {}),
74
+ } } }
75
+ case "dpd":
76
+ return { dpd: { pickupPoint: {
77
+ id: point.id, name: point.name,
78
+ countryCode: str(p.countryCode, p.country_code, "HU"),
79
+ zipCode: point.postalCode, city: point.city,
80
+ street: str(p.street, point.address), houseNo: str(p.houseNo, p.house_no),
81
+ ...(Number.isInteger(Number(p.parcelShopId)) && Number(p.parcelShopId) > 0 ? { parcelShopId: Number(p.parcelShopId) } : {}),
82
+ } } }
83
+ case "mpl":
84
+ return { mpl: { pickupPoint: {
85
+ id: point.id, name: point.name,
86
+ postCode: point.postalCode, city: point.city, address: point.address,
87
+ deliveryMode: str(p.deliveryMode, p.delivery_mode) ||
88
+ (str(p.group).includes("csomagautomata") ? "CS" : "PM"),
89
+ servicePointType: str(p.group, p.servicePointType) || undefined,
90
+ } } }
91
+ }
92
+ }
93
+
@@ -0,0 +1,119 @@
1
+ "use client"
2
+
3
+ import { useEffect, useId, useRef, useState } from "react"
4
+ import { createPortal } from "react-dom"
5
+ import { CarrierPickupMap, type CarrierPickupKind, type CarrierPickupPoint } from "./carrier-pickup-map"
6
+
7
+ type Props = {
8
+ carrier: CarrierPickupKind
9
+ selected: CarrierPickupPoint | null
10
+ postalCode: string
11
+ locale: "hu" | "en"
12
+ onSelect: (point: CarrierPickupPoint) => void
13
+ onClose: () => void
14
+ }
15
+
16
+ const carrierLabels: Record<CarrierPickupKind, string> = {
17
+ foxpost: "FOXPOST",
18
+ gls: "GLS",
19
+ packeta: "Packeta",
20
+ dpd: "DPD",
21
+ mpl: "MPL / PostaPont",
22
+ }
23
+
24
+ export function CarrierPickupDialog({ carrier, selected, postalCode, locale, onSelect, onClose }: Props) {
25
+ const titleId = useId()
26
+ const closeRef = useRef<HTMLButtonElement>(null)
27
+ const previousFocus = useRef<HTMLElement | null>(null)
28
+ const [mounted, setMounted] = useState(false)
29
+
30
+ useEffect(() => {
31
+ previousFocus.current = document.activeElement instanceof HTMLElement
32
+ ? document.activeElement : null
33
+ const oldOverflow = document.body.style.overflow
34
+ document.body.style.overflow = "hidden"
35
+ setMounted(true)
36
+ return () => {
37
+ document.body.style.overflow = oldOverflow
38
+ previousFocus.current?.focus()
39
+ }
40
+ }, [])
41
+
42
+ useEffect(() => {
43
+ if (!mounted) return
44
+ closeRef.current?.focus()
45
+ const handleKeyDown = (event: KeyboardEvent) => {
46
+ if (event.key === "Escape") {
47
+ // The Packeta native picker may handle its own Escape key.
48
+ if (carrier !== "packeta") {
49
+ event.preventDefault()
50
+ onClose()
51
+ }
52
+ return
53
+ }
54
+ if (event.key !== "Tab" || carrier === "packeta") return
55
+ const dialog = document.getElementById(titleId)?.closest<HTMLElement>('[role="dialog"]')
56
+ if (!dialog) return
57
+ const focusable = Array.from(dialog.querySelectorAll<HTMLElement>(
58
+ 'button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), iframe, [tabindex]:not([tabindex="-1"])'
59
+ )).filter((element) => element.getClientRects().length > 0)
60
+ if (!focusable.length) return
61
+ const first = focusable[0]
62
+ const last = focusable[focusable.length - 1]
63
+ if (event.shiftKey && document.activeElement === first) {
64
+ event.preventDefault()
65
+ last.focus()
66
+ } else if (!event.shiftKey && document.activeElement === last) {
67
+ event.preventDefault()
68
+ first.focus()
69
+ }
70
+ }
71
+ document.addEventListener("keydown", handleKeyDown)
72
+ return () => document.removeEventListener("keydown", handleKeyDown)
73
+ }, [carrier, mounted, onClose, titleId])
74
+
75
+ const choose = (point: CarrierPickupPoint | null) => {
76
+ if (!point) return
77
+ onSelect(point)
78
+ onClose()
79
+ }
80
+
81
+ if (!mounted) return null
82
+
83
+ return createPortal(
84
+ <>
85
+ <style>{`
86
+ .hszrdm-pickup-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(9, 15, 27, .76); backdrop-filter: blur(4px); box-sizing: border-box; }
87
+ .hszrdm-pickup-window { box-sizing: border-box; position: relative; display: flex; flex-direction: column; width: min(960px, 100%); max-height: calc(100dvh - 32px); margin: auto; padding: 0; border: 1px solid rgba(128, 128, 128, .3); border-radius: 16px; background: var(--surface, #fff); color: var(--text, #20242b); box-shadow: 0 28px 90px rgba(0, 0, 0, .35); overflow: hidden; }
88
+ .hszrdm-pickup-header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid rgba(128, 128, 128, .25); }
89
+ .hszrdm-pickup-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 16px 20px 22px; }
90
+ .hszrdm-pickup-title { margin: 0; font-size: 1.15rem; font-weight: 700; }
91
+ .hszrdm-pickup-close { flex: none; cursor: pointer; border: 1px solid rgba(128, 128, 128, .45); border-radius: 9px; min-width: 40px; min-height: 40px; background: transparent; color: inherit; font-size: 24px; line-height: 1; }
92
+ @media (max-width: 640px) {
93
+ .hszrdm-pickup-overlay { padding: 0; }
94
+ .hszrdm-pickup-window { width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
95
+ .hszrdm-pickup-header { padding: 12px 16px; }
96
+ .hszrdm-pickup-body { padding: 12px; }
97
+ }
98
+ `}</style>
99
+ <div className="hszrdm-pickup-overlay"
100
+ onMouseDown={(event) => { if (event.target === event.currentTarget) onClose() }}>
101
+ <section className="hszrdm-pickup-window" role="dialog" aria-modal="true"
102
+ aria-labelledby={titleId}>
103
+ <div className="hszrdm-pickup-header">
104
+ <h2 id={titleId} className="hszrdm-pickup-title">
105
+ {carrierLabels[carrier]} – {locale === "en" ? "Choose a pickup point" : "Csomagpont kiválasztása"}
106
+ </h2>
107
+ <button ref={closeRef} type="button" className="hszrdm-pickup-close"
108
+ onClick={onClose} aria-label={locale === "en" ? "Close map" : "Térkép bezárása"}>×</button>
109
+ </div>
110
+ <div className="hszrdm-pickup-body">
111
+ <CarrierPickupMap carrier={carrier} locale={locale} postalCode={postalCode}
112
+ selected={selected} onSelect={choose} autoOpen />
113
+ </div>
114
+ </section>
115
+ </div>
116
+ </>,
117
+ document.body,
118
+ )
119
+ }
@@ -0,0 +1,200 @@
1
+ "use client"
2
+
3
+ import { useCallback, useEffect, useId, useRef, useState } from "react"
4
+
5
+ import { normalizeCarrierPickupPoint, type CarrierPickupKind, type CarrierPickupPoint } from "./carrier-pickup-adapter"
6
+ export { carrierPointToShippingData } from "./carrier-pickup-adapter"
7
+ export type { CarrierPickupKind, CarrierPickupPoint } from "./carrier-pickup-adapter"
8
+
9
+ type WidgetGlobals = Window & {
10
+ Packeta?: { Widget?: { pick: (key: string, callback: (point: unknown) => void, options: Record<string, unknown>) => void; close?: () => void } }
11
+ ppapi?: {
12
+ linkZipField: (id: string) => void
13
+ insertMap: (id: string) => void
14
+ onSelect?: (point: unknown) => void
15
+ showAllFilters?: boolean
16
+ }
17
+ jQuery?: unknown
18
+ }
19
+
20
+ const FOXPOST_ORIGIN = "https://cdn.foxpost.hu"
21
+ const DPD_ORIGIN = "https://api.dpd.cz"
22
+ const FOXPOST_WIDGET = "https://cdn.foxpost.hu/apt-finder/v1/app/"
23
+ const DPD_WIDGET = "https://api.dpd.cz/widget/latest/index.html?enabledCountries=HU&countries=HU&lang=hu&hideCloseButton=true"
24
+ const GLS_SCRIPT = "https://map.gls-hungary.com/widget/gls-dpm.js"
25
+ const PACKETA_SCRIPT = "https://widget.packeta.com/v6/www/js/library.js"
26
+ const POSTA_SCRIPT = "https://posta.hu/szolgaltatasok/postoffice/static/script/ppapi/postapont-api.js"
27
+ const POSTA_CSS = "https://posta.hu/szolgaltatasok/postoffice/static/css/ppapi/postapont-api.css"
28
+
29
+ function record(value: unknown): Record<string, unknown> {
30
+ return value !== null && typeof value === "object" && !Array.isArray(value)
31
+ ? (value as Record<string, unknown>)
32
+ : {}
33
+ }
34
+
35
+ function str(value: unknown): string {
36
+ return typeof value === "string" ? value.trim() : ""
37
+ }
38
+
39
+ function loadWidgetScript(url: string, module = false): Promise<void> {
40
+ if (typeof document === "undefined") return Promise.reject(new Error("Nincs böngészőkörnyezet."))
41
+ const existing = document.querySelector<HTMLScriptElement>(`script[data-hszrdm-widget="${url}"]`)
42
+ if (existing?.dataset.loaded === "true") return Promise.resolve()
43
+ return new Promise((resolve, reject) => {
44
+ const script = existing ?? document.createElement("script")
45
+ const timeout = window.setTimeout(() => reject(new Error("A térképes választó betöltése időtúllépés miatt megszakadt.")), 15000)
46
+ const success = () => { window.clearTimeout(timeout); script.dataset.loaded = "true"; resolve() }
47
+ const failure = () => { window.clearTimeout(timeout); script.remove(); reject(new Error("A futárszolgálat térképe nem tölthető be.")) }
48
+ script.addEventListener("load", success, { once: true })
49
+ script.addEventListener("error", failure, { once: true })
50
+ if (!existing) {
51
+ script.src = url
52
+ script.async = true
53
+ if (module) script.type = "module"
54
+ script.dataset.hszrdmWidget = url
55
+ document.head.appendChild(script)
56
+ }
57
+ })
58
+ }
59
+
60
+ export function CarrierPickupMap({
61
+ carrier, onSelect, selected, locale = "hu", postalCode = "", autoOpen = false,
62
+ }: {
63
+ carrier: CarrierPickupKind
64
+ onSelect: (point: CarrierPickupPoint | null) => void
65
+ selected: CarrierPickupPoint | null
66
+ locale?: "hu" | "en"
67
+ postalCode?: string
68
+ autoOpen?: boolean
69
+ }) {
70
+ const rawId = useId().replace(/[^a-zA-Z0-9_-]/g, "")
71
+ const containerId = `hszrdm-pickup-${rawId}`
72
+ const zipId = `hszrdm-postcode-${rawId}`
73
+ const frame = useRef<HTMLIFrameElement>(null)
74
+ const map = useRef<HTMLDivElement>(null)
75
+ const onSelectRef = useRef(onSelect)
76
+ const [error, setError] = useState("")
77
+ const [ready, setReady] = useState(false)
78
+ onSelectRef.current = onSelect
79
+
80
+ useEffect(() => {
81
+ let alive = true
82
+ const report = (err: unknown) => { if (alive) setError(err instanceof Error ? err.message : "A térkép nem elérhető.") }
83
+ const accept = (value: unknown) => {
84
+ if (!alive) return
85
+ const point = normalizeCarrierPickupPoint(carrier, value)
86
+ if (!point) { report(new Error("A kiválasztott pont azonosítója vagy neve hiányzik. Válassz másik pontot.")); return }
87
+ setError("")
88
+ onSelectRef.current(point)
89
+ }
90
+ const message = (event: MessageEvent) => {
91
+ if (event.source !== frame.current?.contentWindow) return
92
+ if (carrier === "foxpost" && event.origin === FOXPOST_ORIGIN) {
93
+ try { accept(typeof event.data === "string" ? JSON.parse(event.data) : event.data) } catch { report(new Error("Érvénytelen FOXPOST pontadat.")) }
94
+ }
95
+ if (carrier === "dpd" && event.origin === DPD_ORIGIN) {
96
+ const widget = record(record(event.data).dpdWidget)
97
+ if (str(widget.message) === "widgetClose") return
98
+ if (Object.keys(widget).length) {
99
+ const nested = record(widget.pickupPoint ?? widget.pickupPointData ?? widget.pickupPointResult)
100
+ accept(Object.keys(nested).length ? { ...widget, ...nested } : widget)
101
+ }
102
+ }
103
+ }
104
+ window.addEventListener("message", message)
105
+ const globals = window as WidgetGlobals
106
+ let glsElement: HTMLElement | null = null
107
+ let glsChange: EventListener | null = null
108
+ const initialize = async () => {
109
+ if (carrier === "foxpost" || carrier === "dpd") { setReady(true); return }
110
+ if (carrier === "gls") {
111
+ await loadWidgetScript(GLS_SCRIPT, true)
112
+ if (!alive || !map.current) return
113
+ glsElement = document.createElement("gls-dpm")
114
+ glsElement.setAttribute("country", "hu")
115
+ glsElement.setAttribute("language", locale)
116
+ glsElement.style.cssText = "display:block;width:100%;height:100%"
117
+ glsChange = ((event: Event) => accept((event as CustomEvent).detail)) as EventListener
118
+ glsElement.addEventListener("change", glsChange)
119
+ map.current.replaceChildren(glsElement)
120
+ setReady(true)
121
+ return
122
+ }
123
+ if (carrier === "packeta") {
124
+ if (!process.env.NEXT_PUBLIC_PACKETA_WIDGET_API_KEY?.trim()) {
125
+ throw new Error("Hiányzik a NEXT_PUBLIC_PACKETA_WIDGET_API_KEY. A Packeta térképhez nyilvános widget-kulcs szükséges.")
126
+ }
127
+ await loadWidgetScript(PACKETA_SCRIPT)
128
+ if (!alive) return
129
+ if (!globals.Packeta?.Widget?.pick) throw new Error("A Packeta widget nem indult el.")
130
+ setReady(true)
131
+ return
132
+ }
133
+ if (carrier === "mpl") {
134
+ const mapsKey = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY?.trim()
135
+ if (!mapsKey) throw new Error("A PostaPont térképhez NEXT_PUBLIC_GOOGLE_MAPS_API_KEY szükséges.")
136
+ await loadWidgetScript("https://code.jquery.com/jquery-3.7.1.min.js")
137
+ await loadWidgetScript(`https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(mapsKey)}&language=hu&region=HU`)
138
+ await loadWidgetScript(POSTA_SCRIPT)
139
+ if (!alive) return
140
+ if (!globals.ppapi) throw new Error("A PostaPont térkép szolgáltatás nem inicializálható.")
141
+ if (!document.querySelector(`link[data-hszrdm-posta-css]`)) {
142
+ const link = document.createElement("link")
143
+ link.rel = "stylesheet"; link.href = POSTA_CSS; link.dataset.hszrdmPostaCss = "true"
144
+ document.head.appendChild(link)
145
+ }
146
+ globals.ppapi.linkZipField(zipId)
147
+ globals.ppapi.onSelect = accept
148
+ globals.ppapi.insertMap(containerId)
149
+ setReady(true)
150
+ }
151
+ }
152
+ void initialize().catch(report)
153
+ return () => {
154
+ alive = false
155
+ window.removeEventListener("message", message)
156
+ if (glsElement && glsChange) glsElement.removeEventListener("change", glsChange)
157
+ if (carrier === "packeta") globals.Packeta?.Widget?.close?.()
158
+ if (carrier === "mpl" && globals.ppapi) globals.ppapi.onSelect = undefined
159
+ }
160
+ }, [carrier, containerId, locale, zipId])
161
+
162
+ const openPacketa = useCallback(() => {
163
+ const key = process.env.NEXT_PUBLIC_PACKETA_WIDGET_API_KEY?.trim()
164
+ if (!key) { setError("Nincs Packeta widget-kulcs."); return }
165
+ const widget = (window as WidgetGlobals).Packeta?.Widget
166
+ if (!widget?.pick) { setError("A Packeta térkép még nem töltődött be."); return }
167
+ widget.pick(key, (value) => { if (value) {
168
+ const point = normalizeCarrierPickupPoint("packeta", value)
169
+ if (point) { setError(""); onSelectRef.current(point) }
170
+ else setError("A Packeta nem adott vissza érvényes pontazonosítót.")
171
+ } }, { country: "hu", language: locale })
172
+ }, [locale])
173
+
174
+ useEffect(() => {
175
+ if (autoOpen && ready && carrier === "packeta") openPacketa()
176
+ }, [autoOpen, carrier, ready, openPacketa])
177
+
178
+ return <div className="stack-sm" aria-label="Hivatalos futárszolgálati csomagpontválasztó">
179
+ {error ? <p className="notice warning" role="alert">{error}</p> : null}
180
+ {carrier === "foxpost" ? <iframe ref={frame} title="FOXPOST hivatalos csomagponttérkép"
181
+ src={FOXPOST_WIDGET} loading="lazy" allow="geolocation"
182
+ onError={() => setError("A FOXPOST térkép nem tölthető be. Ellenőrizd a böngésző hálózati és tartalomvédelmi beállításait.")}
183
+ style={{ width: "100%", height: 530, border: 0 }} /> : null}
184
+ {carrier === "dpd" ? <iframe ref={frame} title="DPD hivatalos Pickup térkép"
185
+ src={DPD_WIDGET} loading="lazy" allow="geolocation"
186
+ onError={() => setError("A DPD térkép nem tölthető be. Ellenőrizd a böngésző hálózati és tartalomvédelmi beállításait.")}
187
+ style={{ width: "100%", height: 530, border: 0 }} /> : null}
188
+ {carrier === "gls" ? <div ref={map} style={{ height: 530, minHeight: 400 }} /> : null}
189
+ {carrier === "packeta" ? <button type="button" className="button secondary" disabled={!ready}
190
+ onClick={openPacketa}>{locale === "en" ? "Open Packeta pickup map" : "Packeta térkép megnyitása"}</button> : null}
191
+ {carrier === "mpl" ? <div>
192
+ <input id={zipId} type="hidden" value={postalCode} readOnly />
193
+ <div id={containerId} style={{ minHeight: 530, maxWidth: "100%" }} />
194
+ </div> : null}
195
+ {selected?.provider === carrier ? <p className="notice" role="status">
196
+ {locale === "en" ? "Selected point" : "Kiválasztott átvételi pont"}: <strong>{selected.name}</strong>
197
+ {" – "}{[selected.postalCode, selected.city, selected.address].filter(Boolean).join(" ")}
198
+ </p> : null}
199
+ </div>
200
+ }
@@ -3,6 +3,7 @@
3
3
  import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { useState } from "react"
6
+ import { PriceDisplay } from "./price-display"
6
7
  import { QuantityStepper } from "./quantity-stepper"
7
8
  import { useToast } from "./toast-provider"
8
9
  import { useCart } from "./cart-provider"
@@ -15,7 +16,7 @@ import {
15
16
  cartTaxTotal,
16
17
  cartTotal,
17
18
  formatMoney,
18
- lineTotal,
19
+ linePriceBreakdown,
19
20
  numberValue,
20
21
  stringValue,
21
22
  } from "@/lib/core/commerce"
@@ -78,6 +79,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
78
79
  const thumbnail = stringValue(item.thumbnail)
79
80
  const title = stringValue(item.product_title || item.title)
80
81
  const variantId = stringValue(item.variant_id)
82
+ const price = linePriceBreakdown(item, currency)
81
83
  return (
82
84
  <div className="cart-line" key={id}>
83
85
  <div className="cart-line-image">
@@ -86,7 +88,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
86
88
  <div className="cart-line-copy">
87
89
  <strong>{title}</strong>
88
90
  {item.variant_title ? <span className="muted">{stringValue(item.variant_title)}</span> : null}
89
- <span>{formatMoney(lineTotal(item), currency, formatLocale)}</span>
91
+ <PriceDisplay price={price} locale={formatLocale} compact />
90
92
  </div>
91
93
  <QuantityStepper
92
94
  value={quantity}
@@ -0,0 +1,18 @@
1
+ import { DocumentList } from "@/components/document-list"
2
+ import { getDocuments } from "@/lib/core/documents"
3
+
4
+ export async function CategoryDocuments({ categoryId, locale = "hu-HU" }: { categoryId: string; locale?: string }) {
5
+ const en = locale.toLowerCase().startsWith("en")
6
+ const payload = await getDocuments({ categoryId, locale }).catch(() => ({ documents: [], count: 0 }))
7
+ if (!payload.documents.length) return null
8
+
9
+ return (
10
+ <section className="stack" aria-labelledby="category-documents-title">
11
+ <div>
12
+ <p className="eyebrow">{en ? "Downloads" : "Letöltések"}</p>
13
+ <h2 id="category-documents-title">{en ? "Documents" : "Dokumentumok"}</h2>
14
+ </div>
15
+ <DocumentList documents={payload.documents} locale={locale} />
16
+ </section>
17
+ )
18
+ }
@@ -3,6 +3,11 @@
3
3
  import { useEffect, useMemo, useRef } from "react"
4
4
  import { useCart } from "./cart-provider"
5
5
  import { checkoutApi } from "@/lib/core/checkout"
6
+ import { COOKIE_CONSENT_EVENT } from "@/lib/core/consent"
7
+ import {
8
+ googleAdsRemarketingFromSource,
9
+ trackGoogleAdsRemarketing,
10
+ } from "@/lib/core/google-ads"
6
11
  import type { CoreConfig } from "@/lib/core/types"
7
12
 
8
13
  export function CheckoutAnalytics({ config }: { config: CoreConfig }) {
@@ -19,5 +24,22 @@ export function CheckoutAnalytics({ config }: { config: CoreConfig }) {
19
24
  })
20
25
  }, [api, cart, cartId])
21
26
 
27
+ useEffect(() => {
28
+ if (!cart || !cartId) return
29
+
30
+ const send = () => {
31
+ trackGoogleAdsRemarketing(
32
+ config.marketing.google_ads,
33
+ "begin_checkout",
34
+ googleAdsRemarketingFromSource(cart),
35
+ { dedupeKey: cartId, sessionDedupe: true },
36
+ )
37
+ }
38
+
39
+ send()
40
+ window.addEventListener(COOKIE_CONSENT_EVENT, send)
41
+ return () => window.removeEventListener(COOKIE_CONSENT_EVENT, send)
42
+ }, [cart, cartId, config.marketing.google_ads])
43
+
22
44
  return null
23
45
  }