@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.
- package/package.json +1 -1
- package/src/cli.mjs +3 -0
- package/templates/backend/.env.example +24 -1
- package/templates/backend/package.json +8 -7
- package/templates/backend/scripts/sync-env-example.mjs +55 -0
- package/templates/backend/scripts/verify-env-contract.mjs +6 -5
- package/templates/backend/src/scripts/verify-runtime-modules.ts +1 -0
- package/templates/storefront/.env.example +6 -0
- package/templates/storefront/.env.local +3 -0
- package/templates/storefront/package.json +2 -1
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +5 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +14 -5
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +10 -1
- package/templates/storefront/src/app/account/orders/[id]/page.tsx +17 -2
- package/templates/storefront/src/app/checkout/success/page.tsx +5 -0
- package/templates/storefront/src/app/documents/page.tsx +27 -0
- package/templates/storefront/src/app/layout.tsx +8 -1
- package/templates/storefront/src/components/add-to-cart.tsx +16 -14
- package/templates/storefront/src/components/arukereso-backlink.tsx +43 -0
- package/templates/storefront/src/components/arukereso-trusted-shop-widget.tsx +81 -0
- package/templates/storefront/src/components/arukereso-trusted-shop.tsx +71 -0
- package/templates/storefront/src/components/carrier-pickup-adapter.ts +93 -0
- package/templates/storefront/src/components/carrier-pickup-dialog.tsx +119 -0
- package/templates/storefront/src/components/carrier-pickup-map.tsx +200 -0
- package/templates/storefront/src/components/cart-view.tsx +4 -2
- package/templates/storefront/src/components/category-documents.tsx +18 -0
- package/templates/storefront/src/components/checkout-analytics.tsx +22 -0
- package/templates/storefront/src/components/checkout-flow.tsx +75 -115
- package/templates/storefront/src/components/document-list.tsx +47 -0
- package/templates/storefront/src/components/google-ads-cart-remarketing.tsx +71 -0
- package/templates/storefront/src/components/google-ads-purchase.tsx +37 -0
- package/templates/storefront/src/components/price-display.tsx +39 -0
- package/templates/storefront/src/components/product-card.tsx +7 -6
- package/templates/storefront/src/components/product-documents.tsx +18 -0
- package/templates/storefront/src/components/product-view-tracker.tsx +17 -2
- package/templates/storefront/src/components/reorder-button.tsx +74 -0
- package/templates/storefront/src/components/variant-price-display.tsx +7 -11
- package/templates/storefront/src/lib/core/catalog.ts +6 -2
- package/templates/storefront/src/lib/core/commerce.ts +51 -0
- package/templates/storefront/src/lib/core/documents.ts +37 -0
- package/templates/storefront/src/lib/core/google-ads.ts +154 -7
- package/templates/storefront/src/lib/core/reorder.ts +26 -0
- package/templates/storefront/src/lib/storefront-routes.ts +3 -0
- package/templates/storefront/src/proxy.ts +2 -0
- package/templates/storefront/tests/carrier-pickup-adapter.test.mjs +69 -0
|
@@ -4,6 +4,9 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
|
4
4
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
|
5
5
|
import { useCart } from "./cart-provider"
|
|
6
6
|
import { StripePayment } from "./stripe-payment"
|
|
7
|
+
import { carrierPointToShippingData, type CarrierPickupPoint } from "./carrier-pickup-map"
|
|
8
|
+
import { CarrierPickupDialog } from "./carrier-pickup-dialog"
|
|
9
|
+
import { normalizeCarrierPickupPoint } from "./carrier-pickup-adapter"
|
|
7
10
|
import { checkoutApi } from "@/lib/core/checkout"
|
|
8
11
|
import {
|
|
9
12
|
activePaymentSession,
|
|
@@ -73,11 +76,8 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
73
76
|
const [address, setAddress] = useState<AddressState>(() => emptyAddress(config.store.default_country))
|
|
74
77
|
const [shippingOptions, setShippingOptions] = useState<JsonRecord[]>([])
|
|
75
78
|
const [selectedShipping, setSelectedShipping] = useState<JsonRecord | null>(null)
|
|
76
|
-
const [
|
|
77
|
-
const [
|
|
78
|
-
const [pickupSearch, setPickupSearch] = useState("")
|
|
79
|
-
const [packetaPointId, setPacketaPointId] = useState("")
|
|
80
|
-
const [packetaPointName, setPacketaPointName] = useState("")
|
|
79
|
+
const [selectedPickupPoint, setSelectedPickupPoint] = useState<CarrierPickupPoint | null>(null)
|
|
80
|
+
const [pickupDialogOpen, setPickupDialogOpen] = useState(false)
|
|
81
81
|
const [providers, setProviders] = useState<JsonRecord[]>([])
|
|
82
82
|
const [selectedProvider, setSelectedProvider] = useState("")
|
|
83
83
|
const [preparedCart, setPreparedCart] = useState<JsonRecord | null>(null)
|
|
@@ -278,49 +278,41 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
const selectShippingOption =
|
|
281
|
+
const selectShippingOption = (option: JsonRecord) => {
|
|
282
282
|
setSelectedShipping(option)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
setPickupSearch("")
|
|
286
|
-
const kind = pickupKind(option)
|
|
287
|
-
if (!kind || kind === "packeta") return
|
|
288
|
-
setBusy("pickup")
|
|
283
|
+
setSelectedPickupPoint(null)
|
|
284
|
+
setPickupDialogOpen(false)
|
|
289
285
|
setError(null)
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
postCode: address.postal_code,
|
|
310
|
-
city: address.city,
|
|
311
|
-
})
|
|
312
|
-
).deliveryPlaces,
|
|
313
|
-
)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Reconcile vendor widget selection with Core's current catalog where available. */
|
|
289
|
+
const verifyCarrierPickupPoint = async (kind: PickupKind, picked: CarrierPickupPoint | null) => {
|
|
290
|
+
if (!kind || !picked || kind !== picked.provider) return picked
|
|
291
|
+
let candidates: JsonRecord[] | null = null
|
|
292
|
+
if (kind === "foxpost") candidates = (await api.foxpostLockers()).lockers
|
|
293
|
+
if (kind === "gls") candidates = (await api.glsDeliveryPoints()).deliveryPoints
|
|
294
|
+
if (kind === "mpl") {
|
|
295
|
+
candidates = (await api.mplDeliveryPlaces({ postCode: picked.postalCode })).deliveryPlaces
|
|
296
|
+
}
|
|
297
|
+
if (!candidates) return picked
|
|
298
|
+
const match = candidates.find((item) => {
|
|
299
|
+
const candidate = normalizeCarrierPickupPoint(kind, item)
|
|
300
|
+
if (!candidate) return false
|
|
301
|
+
if (candidate.id === picked.id) return true
|
|
302
|
+
if (kind === "foxpost") {
|
|
303
|
+
const identifiers = [stringValue(item.operatorId), stringValue(item.placeId)].filter(Boolean)
|
|
304
|
+
return identifiers.includes(picked.id) || identifiers.includes(stringValue(picked.raw.place_id))
|
|
314
305
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
} finally {
|
|
322
|
-
setBusy(null)
|
|
306
|
+
return false
|
|
307
|
+
})
|
|
308
|
+
if (!match) {
|
|
309
|
+
throw new Error(localized(locale,
|
|
310
|
+
"A kiválasztott átvételi pont már nem érhető el ennél a futárszolgálatnál. Válassz másikat.",
|
|
311
|
+
"This pickup point is no longer available for this carrier. Please choose another."))
|
|
323
312
|
}
|
|
313
|
+
const confirmed = normalizeCarrierPickupPoint(kind, match)
|
|
314
|
+
if (!confirmed) throw new Error(localized(locale, "Hiányos átvételipont-adatok.", "Invalid pickup point details."))
|
|
315
|
+
return confirmed
|
|
324
316
|
}
|
|
325
317
|
|
|
326
318
|
const saveShipping = async () => {
|
|
@@ -329,11 +321,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
329
321
|
}
|
|
330
322
|
const optionId = stringValue(selectedShipping.id)
|
|
331
323
|
const kind = pickupKind(selectedShipping)
|
|
332
|
-
const selectedPoint = pickupPoints.find((point) => pickupKey(point) === selectedPickupKey) || null
|
|
333
|
-
const data = shippingData(kind, selectedPoint, packetaPointId, packetaPointName, locale)
|
|
334
324
|
setBusy("shipping")
|
|
335
325
|
setError(null)
|
|
336
326
|
try {
|
|
327
|
+
const verifiedPoint = await verifyCarrierPickupPoint(kind, selectedPickupPoint)
|
|
328
|
+
const data = shippingData(kind, verifiedPoint, locale)
|
|
337
329
|
const result = await api.addShippingMethod(cartId, optionId, data)
|
|
338
330
|
await refresh(cartId)
|
|
339
331
|
await loadProviders(result.cart)
|
|
@@ -396,11 +388,6 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
396
388
|
}
|
|
397
389
|
|
|
398
390
|
const pickup = selectedShipping ? pickupKind(selectedShipping) : null
|
|
399
|
-
const filteredPoints = pickupSearch.trim()
|
|
400
|
-
? pickupPoints
|
|
401
|
-
.filter((point) => pointLabel(point).toLowerCase().includes(pickupSearch.trim().toLowerCase()))
|
|
402
|
-
.slice(0, 200)
|
|
403
|
-
: pickupPoints.slice(0, 200)
|
|
404
391
|
const effectiveCart = preparedCart || cart
|
|
405
392
|
const session = activePaymentSession(effectiveCart)
|
|
406
393
|
const activeProviderId = providerId(session) || selectedProvider
|
|
@@ -454,29 +441,43 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
454
441
|
</div>
|
|
455
442
|
)}
|
|
456
443
|
|
|
457
|
-
{pickup
|
|
444
|
+
{pickup ? (
|
|
458
445
|
<div className="stack-sm">
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
446
|
+
{selectedPickupPoint?.provider === pickup ? (
|
|
447
|
+
<p className="notice" role="status">
|
|
448
|
+
<strong>{locale === "en" ? "Selected pickup point" : "Kiválasztott csomagpont"}: {selectedPickupPoint.name}</strong>
|
|
449
|
+
{" – "}{[selectedPickupPoint.postalCode, selectedPickupPoint.city, selectedPickupPoint.address].filter(Boolean).join(" ")}
|
|
450
|
+
</p>
|
|
451
|
+
) : (
|
|
452
|
+
<p className="muted">
|
|
453
|
+
{locale === "en"
|
|
454
|
+
? "Choose a pickup point on the carrier's map to continue."
|
|
455
|
+
: "A folytatáshoz válassz csomagpontot a futárszolgálat térképén."}
|
|
456
|
+
</p>
|
|
457
|
+
)}
|
|
458
|
+
<button
|
|
459
|
+
className="button secondary"
|
|
460
|
+
type="button"
|
|
461
|
+
disabled={busy === "shipping" || mutating}
|
|
462
|
+
onClick={() => setPickupDialogOpen(true)}
|
|
463
|
+
>
|
|
464
|
+
{selectedPickupPoint?.provider === pickup
|
|
465
|
+
? (locale === "en" ? "Change pickup point on map" : "Csomagpont módosítása a térképen")
|
|
466
|
+
: (locale === "en" ? "Choose pickup point on map" : "Csomagpont kiválasztása a térképen")}
|
|
467
|
+
</button>
|
|
470
468
|
</div>
|
|
471
469
|
) : null}
|
|
472
470
|
|
|
473
|
-
{pickup
|
|
474
|
-
<
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
471
|
+
{pickup && pickupDialogOpen ? (
|
|
472
|
+
<CarrierPickupDialog
|
|
473
|
+
key={pickup}
|
|
474
|
+
carrier={pickup}
|
|
475
|
+
selected={selectedPickupPoint}
|
|
476
|
+
postalCode={address.postal_code}
|
|
477
|
+
locale={locale}
|
|
478
|
+
onSelect={setSelectedPickupPoint}
|
|
479
|
+
onClose={() => setPickupDialogOpen(false)}
|
|
480
|
+
/>
|
|
480
481
|
) : null}
|
|
481
482
|
|
|
482
483
|
{selectedShipping ? (
|
|
@@ -485,8 +486,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
485
486
|
type="button"
|
|
486
487
|
disabled={
|
|
487
488
|
busy === "shipping" ||
|
|
488
|
-
(Boolean(pickup) &&
|
|
489
|
-
(pickup === "packeta" && !packetaPointId.trim())
|
|
489
|
+
(Boolean(pickup) && selectedPickupPoint?.provider !== pickup)
|
|
490
490
|
}
|
|
491
491
|
onClick={() => void saveShipping()}
|
|
492
492
|
>
|
|
@@ -735,50 +735,10 @@ function pickupKind(option: JsonRecord): PickupKind {
|
|
|
735
735
|
return null
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
-
function
|
|
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
|
-
)
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
function pointLabel(point: JsonRecord) {
|
|
751
|
-
const name = stringValue(point.name || point.label || point.title || point.shop_name || point.type)
|
|
752
|
-
const postal = stringValue(point.postalCode || point.postal_code || point.zipCode || point.zip_code || point.zip)
|
|
753
|
-
const city = stringValue(point.city || point.town)
|
|
754
|
-
const address = stringValue(point.address || point.address_1 || point.street || point.fullAddress)
|
|
755
|
-
return [name, [postal, city].filter(Boolean).join(" "), address].filter(Boolean).join(" – ") || pickupKey(point)
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
function shippingData(
|
|
759
|
-
kind: PickupKind,
|
|
760
|
-
point: JsonRecord | null,
|
|
761
|
-
packetaId: string,
|
|
762
|
-
packetaName: string,
|
|
763
|
-
locale: StorefrontLocale,
|
|
764
|
-
): Record<string, unknown> | undefined {
|
|
738
|
+
function shippingData(kind: PickupKind, point: CarrierPickupPoint | null, locale: StorefrontLocale): Record<string, unknown> | undefined {
|
|
765
739
|
if (!kind) return undefined
|
|
766
|
-
if (kind
|
|
767
|
-
|
|
768
|
-
throw new Error(
|
|
769
|
-
localized(locale, "A Packeta pont azonosítója kötelező.", "The Packeta pickup point ID is required."),
|
|
770
|
-
)
|
|
771
|
-
}
|
|
772
|
-
return { packeta: { pickupPoint: { id: packetaId.trim(), name: packetaName.trim() || undefined } } }
|
|
773
|
-
}
|
|
774
|
-
if (!point) {
|
|
775
|
-
throw new Error(localized(locale, "Válassz átvételi pontot.", "Choose a pickup point."))
|
|
776
|
-
}
|
|
777
|
-
if (kind === "foxpost") return { foxpost: { locker: point, packageSize: "M" } }
|
|
778
|
-
if (kind === "gls") return { gls: { deliveryPoint: point } }
|
|
779
|
-
if (kind === "dpd") return { dpd: { pickupPoint: point } }
|
|
780
|
-
if (kind === "mpl") return { mpl: { pickupPoint: point } }
|
|
781
|
-
return undefined
|
|
740
|
+
if (!point || point.provider !== kind) throw new Error(localized(locale, "Válassz átvételi pontot a futár térképén.", "Choose a pickup point on the carrier map."))
|
|
741
|
+
return carrierPointToShippingData(point)
|
|
782
742
|
}
|
|
783
743
|
|
|
784
744
|
function localized(locale: StorefrontLocale, hu: string, en: string) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { StoreDocument } from "@/lib/core/documents"
|
|
2
|
+
|
|
3
|
+
export function DocumentList({
|
|
4
|
+
documents,
|
|
5
|
+
locale = "hu-HU",
|
|
6
|
+
emptyLabel,
|
|
7
|
+
}: {
|
|
8
|
+
documents: StoreDocument[]
|
|
9
|
+
locale?: string
|
|
10
|
+
emptyLabel?: string
|
|
11
|
+
}) {
|
|
12
|
+
const en = locale.toLowerCase().startsWith("en")
|
|
13
|
+
if (!documents.length) {
|
|
14
|
+
return <p className="muted">{emptyLabel || (en ? "No documents are available." : "Nincs elérhető dokumentum.")}</p>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className="stack">
|
|
19
|
+
{documents.map((document) => (
|
|
20
|
+
<article className="card stack" key={document.id}>
|
|
21
|
+
<div className="stack" style={{ gap: ".35rem" }}>
|
|
22
|
+
<div className="button-row" style={{ justifyContent: "space-between", alignItems: "baseline" }}>
|
|
23
|
+
<strong>{document.title}</strong>
|
|
24
|
+
<span className="muted">{document.document_type}</span>
|
|
25
|
+
</div>
|
|
26
|
+
{document.description ? <p className="muted">{document.description}</p> : null}
|
|
27
|
+
<div className="product-meta">
|
|
28
|
+
{document.version ? <span>{en ? "Version" : "Verzió"}: {document.version}</span> : null}
|
|
29
|
+
{document.locale ? <span>{document.locale}</span> : null}
|
|
30
|
+
{document.file_size ? <span>{formatBytes(document.file_size)}</span> : null}
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<a className="button secondary" href={document.file_url} target="_blank" rel="noreferrer">
|
|
34
|
+
{en ? "Open document" : "Dokumentum megnyitása"}
|
|
35
|
+
</a>
|
|
36
|
+
</article>
|
|
37
|
+
))}
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function formatBytes(value: number) {
|
|
43
|
+
if (!Number.isFinite(value) || value <= 0) return ""
|
|
44
|
+
if (value < 1024) return `${Math.round(value)} B`
|
|
45
|
+
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
|
|
46
|
+
return `${(value / (1024 * 1024)).toFixed(1)} MB`
|
|
47
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react"
|
|
4
|
+
import { useCart } from "./cart-provider"
|
|
5
|
+
import {
|
|
6
|
+
googleAdsRemarketingFromSource,
|
|
7
|
+
trackGoogleAdsRemarketing,
|
|
8
|
+
} from "@/lib/core/google-ads"
|
|
9
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
10
|
+
|
|
11
|
+
type Line = Record<string, unknown>
|
|
12
|
+
|
|
13
|
+
export function GoogleAdsCartRemarketing({
|
|
14
|
+
googleAds,
|
|
15
|
+
}: {
|
|
16
|
+
googleAds: CoreConfig["marketing"]["google_ads"]
|
|
17
|
+
}) {
|
|
18
|
+
const { cart, loading } = useCart()
|
|
19
|
+
const previous = useRef<Map<string, number> | null>(null)
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (loading || !cart) return
|
|
23
|
+
|
|
24
|
+
const lines = Array.isArray(cart.items)
|
|
25
|
+
? cart.items.filter(isRecord)
|
|
26
|
+
: []
|
|
27
|
+
const current = new Map<string, number>()
|
|
28
|
+
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
const variantId = text(line.variant_id)
|
|
31
|
+
if (!variantId) continue
|
|
32
|
+
current.set(variantId, quantity(line.quantity))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (previous.current) {
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
const variantId = text(line.variant_id)
|
|
38
|
+
if (!variantId) continue
|
|
39
|
+
const nextQuantity = quantity(line.quantity)
|
|
40
|
+
const previousQuantity = previous.current.get(variantId) || 0
|
|
41
|
+
const added = nextQuantity - previousQuantity
|
|
42
|
+
if (added <= 0) continue
|
|
43
|
+
|
|
44
|
+
const ecommerce = googleAdsRemarketingFromSource({
|
|
45
|
+
currency_code: cart.currency_code,
|
|
46
|
+
items: [{ ...line, quantity: added }],
|
|
47
|
+
})
|
|
48
|
+
trackGoogleAdsRemarketing(googleAds, "add_to_cart", ecommerce)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
previous.current = current
|
|
53
|
+
}, [cart, googleAds, loading])
|
|
54
|
+
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function quantity(value: unknown) {
|
|
59
|
+
const parsed = typeof value === "number" ? value : Number(value)
|
|
60
|
+
return Number.isFinite(parsed) ? Math.max(0, Math.trunc(parsed)) : 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function text(value: unknown) {
|
|
64
|
+
return typeof value === "string" || typeof value === "number"
|
|
65
|
+
? String(value).trim()
|
|
66
|
+
: ""
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isRecord(value: unknown): value is Line {
|
|
70
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value))
|
|
71
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react"
|
|
4
|
+
import { COOKIE_CONSENT_EVENT } from "@/lib/core/consent"
|
|
5
|
+
import {
|
|
6
|
+
googleAdsRemarketingFromSource,
|
|
7
|
+
trackGoogleAdsPurchase,
|
|
8
|
+
trackGoogleAdsRemarketing,
|
|
9
|
+
} from "@/lib/core/google-ads"
|
|
10
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
11
|
+
|
|
12
|
+
type GoogleAdsPurchaseProps = {
|
|
13
|
+
googleAds: CoreConfig["marketing"]["google_ads"]
|
|
14
|
+
order: Record<string, unknown>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function GoogleAdsPurchase({ googleAds, order }: GoogleAdsPurchaseProps) {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const transactionId = String(order.id || order.display_id || "").trim()
|
|
20
|
+
const send = () => {
|
|
21
|
+
trackGoogleAdsPurchase(googleAds, order)
|
|
22
|
+
if (!transactionId) return
|
|
23
|
+
trackGoogleAdsRemarketing(
|
|
24
|
+
googleAds,
|
|
25
|
+
"purchase",
|
|
26
|
+
googleAdsRemarketingFromSource(order),
|
|
27
|
+
{ dedupeKey: transactionId },
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
send()
|
|
32
|
+
window.addEventListener(COOKIE_CONSENT_EVENT, send)
|
|
33
|
+
return () => window.removeEventListener(COOKIE_CONSENT_EVENT, send)
|
|
34
|
+
}, [googleAds, order])
|
|
35
|
+
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { formatMoney, type PriceBreakdown } from "@/lib/core/commerce"
|
|
2
|
+
|
|
3
|
+
export function PriceDisplay({
|
|
4
|
+
price,
|
|
5
|
+
locale,
|
|
6
|
+
className = "product-price",
|
|
7
|
+
compact = false,
|
|
8
|
+
}: {
|
|
9
|
+
price: PriceBreakdown
|
|
10
|
+
locale: string
|
|
11
|
+
className?: string
|
|
12
|
+
compact?: boolean
|
|
13
|
+
}) {
|
|
14
|
+
if (!Number.isFinite(price.amount)) return null
|
|
15
|
+
|
|
16
|
+
const english = locale.toLowerCase().startsWith("en")
|
|
17
|
+
const rate = Number.isFinite(price.taxRate) ? Math.round(price.taxRate * 100) / 100 : Number.NaN
|
|
18
|
+
const showBreakdown = price.hasTaxBreakdown
|
|
19
|
+
&& Number.isFinite(price.netAmount)
|
|
20
|
+
&& Number.isFinite(price.grossAmount)
|
|
21
|
+
&& price.grossAmount >= price.netAmount
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div className={className}>
|
|
25
|
+
<strong>{formatMoney(price.grossAmount, price.currency, locale)}</strong>
|
|
26
|
+
{showBreakdown ? (
|
|
27
|
+
<span className="muted small">
|
|
28
|
+
{english ? "Net" : "Nettó"}: {formatMoney(price.netAmount, price.currency, locale)}
|
|
29
|
+
{Number.isFinite(rate) && rate > 0 ? ` + ${formatTaxRate(rate)} ${english ? "VAT" : "ÁFA"}` : ""}
|
|
30
|
+
{!compact ? ` · ${english ? "gross price" : "bruttó ár"}` : ""}
|
|
31
|
+
</span>
|
|
32
|
+
) : null}
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function formatTaxRate(rate: number) {
|
|
38
|
+
return `${Number.isInteger(rate) ? rate.toFixed(0) : rate.toFixed(2).replace(/0+$/, "").replace(/\.$/, "")}%`
|
|
39
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import Link from "next/link"
|
|
2
|
+
import { PriceDisplay } from "./price-display"
|
|
2
3
|
import {
|
|
3
4
|
asRecords,
|
|
4
|
-
formatMoney,
|
|
5
5
|
isRecord,
|
|
6
|
-
|
|
7
|
-
productVariantPrice,
|
|
6
|
+
productVariantPriceBreakdown,
|
|
8
7
|
stringValue,
|
|
9
8
|
} from "@/lib/core/commerce"
|
|
10
9
|
import type { CoreConfig } from "@/lib/core/types"
|
|
@@ -22,10 +21,10 @@ export function ProductCard({
|
|
|
22
21
|
}) {
|
|
23
22
|
const variants = asRecords(product.variants)
|
|
24
23
|
const variant = variants[0] || null
|
|
25
|
-
const price =
|
|
26
|
-
const currency = productVariantCurrency(variant, config.store.default_currency)
|
|
24
|
+
const price = productVariantPriceBreakdown(variant, config.store.default_currency)
|
|
27
25
|
const handle = stringValue(product.handle)
|
|
28
26
|
const activeLocale = locale || storefrontLocale(config.store.locale)
|
|
27
|
+
const formatLocale = activeLocale === "en" ? "en-US" : "hu-HU"
|
|
29
28
|
const copy = storefrontCopy(activeLocale)
|
|
30
29
|
const href = productPath(activeLocale, handle)
|
|
31
30
|
const thumbnail = stringValue(product.thumbnail)
|
|
@@ -40,7 +39,9 @@ export function ProductCard({
|
|
|
40
39
|
<div className="product-card-body">
|
|
41
40
|
{categories[0] && isRecord(categories[0]) ? <span className="eyebrow">{stringValue(categories[0].name)}</span> : null}
|
|
42
41
|
<h2>{title}</h2>
|
|
43
|
-
{Number.isFinite(price)
|
|
42
|
+
{Number.isFinite(price.amount)
|
|
43
|
+
? <PriceDisplay price={price} locale={formatLocale} compact />
|
|
44
|
+
: <span className="muted">{copy.priceOnProductPage}</span>}
|
|
44
45
|
</div>
|
|
45
46
|
</Link>
|
|
46
47
|
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DocumentList } from "@/components/document-list"
|
|
2
|
+
import { getDocuments } from "@/lib/core/documents"
|
|
3
|
+
|
|
4
|
+
export async function ProductDocuments({ productId, locale = "hu-HU" }: { productId: string; locale?: string }) {
|
|
5
|
+
const en = locale.toLowerCase().startsWith("en")
|
|
6
|
+
const payload = await getDocuments({ productId, locale }).catch(() => ({ documents: [], count: 0 }))
|
|
7
|
+
if (!payload.documents.length) return null
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<section className="stack" aria-labelledby="product-documents-title">
|
|
11
|
+
<div>
|
|
12
|
+
<p className="eyebrow">{en ? "Downloads" : "Letöltések"}</p>
|
|
13
|
+
<h2 id="product-documents-title">{en ? "Documents" : "Dokumentumok"}</h2>
|
|
14
|
+
</div>
|
|
15
|
+
<DocumentList documents={payload.documents} locale={locale} />
|
|
16
|
+
</section>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect } from "react"
|
|
4
4
|
import { COOKIE_CONSENT_EVENT } from "@/lib/core/consent"
|
|
5
|
+
import { trackGoogleAdsRemarketing } from "@/lib/core/google-ads"
|
|
5
6
|
import {
|
|
6
7
|
trackViewItem,
|
|
7
8
|
type EcommerceItem,
|
|
@@ -10,28 +11,42 @@ import type { CoreConfig } from "@/lib/core/types"
|
|
|
10
11
|
|
|
11
12
|
export function ProductViewTracker({
|
|
12
13
|
analytics,
|
|
14
|
+
googleAds,
|
|
13
15
|
item,
|
|
16
|
+
googleAdsItem,
|
|
14
17
|
currency,
|
|
15
18
|
value,
|
|
16
19
|
}: {
|
|
17
20
|
analytics: CoreConfig["analytics"]
|
|
21
|
+
googleAds: CoreConfig["marketing"]["google_ads"]
|
|
18
22
|
item: EcommerceItem
|
|
23
|
+
googleAdsItem: EcommerceItem
|
|
19
24
|
currency: string
|
|
20
25
|
value?: number
|
|
21
26
|
}) {
|
|
22
27
|
useEffect(() => {
|
|
23
|
-
const send = () =>
|
|
28
|
+
const send = () => {
|
|
24
29
|
trackViewItem(analytics, {
|
|
25
30
|
item,
|
|
26
31
|
currency,
|
|
27
32
|
value,
|
|
28
33
|
dedupeKey: `${item.item_id}:${window.location.pathname}`,
|
|
29
34
|
})
|
|
35
|
+
trackGoogleAdsRemarketing(
|
|
36
|
+
googleAds,
|
|
37
|
+
"view_item",
|
|
38
|
+
{ currency, value, items: [googleAdsItem] },
|
|
39
|
+
{
|
|
40
|
+
dedupeKey: `${googleAdsItem.item_id}:${window.location.pathname}`,
|
|
41
|
+
sessionDedupe: true,
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
}
|
|
30
45
|
|
|
31
46
|
send()
|
|
32
47
|
window.addEventListener(COOKIE_CONSENT_EVENT, send)
|
|
33
48
|
return () => window.removeEventListener(COOKIE_CONSENT_EVENT, send)
|
|
34
|
-
}, [analytics, currency, item, value])
|
|
49
|
+
}, [analytics, currency, googleAds, googleAdsItem, item, value])
|
|
35
50
|
|
|
36
51
|
return null
|
|
37
52
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { usePathname, useRouter } from "next/navigation"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
import { reorderOrder } from "@/lib/core/reorder"
|
|
6
|
+
import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
7
|
+
import { useCart } from "./cart-provider"
|
|
8
|
+
import { useToast } from "./toast-provider"
|
|
9
|
+
|
|
10
|
+
export function ReorderButton({ orderId }: { orderId: string }) {
|
|
11
|
+
const pathname = usePathname()
|
|
12
|
+
const router = useRouter()
|
|
13
|
+
const locale = localeFromPathname(pathname)
|
|
14
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
15
|
+
const { adoptCart } = useCart()
|
|
16
|
+
const { showToast } = useToast()
|
|
17
|
+
const [busy, setBusy] = useState(false)
|
|
18
|
+
|
|
19
|
+
const reorder = async () => {
|
|
20
|
+
setBusy(true)
|
|
21
|
+
try {
|
|
22
|
+
const result = await reorderOrder(orderId)
|
|
23
|
+
if (!result.added_count || !result.cart?.id) {
|
|
24
|
+
showToast({
|
|
25
|
+
tone: "error",
|
|
26
|
+
message: locale === "en"
|
|
27
|
+
? "None of the items from this order are currently available to reorder."
|
|
28
|
+
: "A rendelés egyik tétele sem rendelhető újra jelenleg.",
|
|
29
|
+
})
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await adoptCart(String(result.cart.id))
|
|
34
|
+
|
|
35
|
+
if (result.skipped_items.length) {
|
|
36
|
+
showToast({
|
|
37
|
+
tone: "info",
|
|
38
|
+
durationMs: 7000,
|
|
39
|
+
message: locale === "en"
|
|
40
|
+
? `${result.skipped_items.length} previous item(s) could not be added. The cart contains the available items at current prices.`
|
|
41
|
+
: `${result.skipped_items.length} korábbi tételt nem lehetett kosárba tenni. A kosár az elérhető tételeket tartalmazza, aktuális árakon.`,
|
|
42
|
+
})
|
|
43
|
+
} else {
|
|
44
|
+
showToast({
|
|
45
|
+
tone: "success",
|
|
46
|
+
message: locale === "en"
|
|
47
|
+
? "The order has been rebuilt in a new cart using current prices and availability."
|
|
48
|
+
: "A rendelés új kosárba került, aktuális árakkal és készlettel.",
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
router.push(routes.cart)
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
showToast({
|
|
55
|
+
tone: "error",
|
|
56
|
+
message: cause instanceof Error
|
|
57
|
+
? cause.message
|
|
58
|
+
: locale === "en"
|
|
59
|
+
? "The order could not be reordered."
|
|
60
|
+
: "Az újrarendelés nem sikerült.",
|
|
61
|
+
})
|
|
62
|
+
} finally {
|
|
63
|
+
setBusy(false)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<button className="button" type="button" disabled={busy} onClick={() => void reorder()}>
|
|
69
|
+
{busy
|
|
70
|
+
? locale === "en" ? "Preparing cart…" : "Kosár készítése…"
|
|
71
|
+
: locale === "en" ? "Reorder" : "Újrarendelés"}
|
|
72
|
+
</button>
|
|
73
|
+
)
|
|
74
|
+
}
|