@hszrdm/create-commerce 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/templates/backend/package.json +1 -1
  3. package/templates/storefront/README.md +35 -12
  4. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +3 -2
  5. package/templates/storefront/src/app/blog/page.tsx +46 -8
  6. package/templates/storefront/src/app/cart/page.tsx +2 -0
  7. package/templates/storefront/src/app/cart/shared/[token]/page.tsx +25 -0
  8. package/templates/storefront/src/app/knowledge-base/page.tsx +46 -8
  9. package/templates/storefront/src/app/layout.tsx +5 -2
  10. package/templates/storefront/src/app/legal/page.tsx +18 -2
  11. package/templates/storefront/src/app/page.tsx +33 -4
  12. package/templates/storefront/src/app/pages/page.tsx +43 -0
  13. package/templates/storefront/src/components/add-to-cart.tsx +76 -2
  14. package/templates/storefront/src/components/analytics.tsx +37 -17
  15. package/templates/storefront/src/components/cart-provider.tsx +40 -3
  16. package/templates/storefront/src/components/cart-share-button.tsx +93 -0
  17. package/templates/storefront/src/components/cms-taxonomy-filters.tsx +86 -0
  18. package/templates/storefront/src/components/customer-cart-resume-gate.tsx +112 -0
  19. package/templates/storefront/src/components/fogyasztobarat-embed.tsx +32 -0
  20. package/templates/storefront/src/components/shared-cart-view.tsx +257 -0
  21. package/templates/storefront/src/lib/core/catalog.ts +12 -0
  22. package/templates/storefront/src/lib/core/checkout.ts +86 -4
  23. package/templates/storefront/src/lib/core/customer-cart-resume.ts +51 -0
  24. package/templates/storefront/src/lib/core/google-ads.ts +58 -0
  25. package/templates/storefront/src/lib/core/legal.ts +14 -0
  26. package/templates/storefront/src/lib/core/shared-cart.ts +37 -0
  27. package/templates/storefront/src/lib/core/types.ts +18 -0
  28. package/templates/storefront/src/lib/storefront-routes.ts +9 -0
  29. package/templates/storefront/src/proxy.ts +7 -0
@@ -0,0 +1,257 @@
1
+ "use client"
2
+
3
+ import { useEffect, useMemo, useState } from "react"
4
+ import { usePathname, useRouter } from "next/navigation"
5
+ import { useCart } from "./cart-provider"
6
+ import { useToast } from "./toast-provider"
7
+ import { getProductById } from "@/lib/core/catalog"
8
+ import { checkoutApi } from "@/lib/core/checkout"
9
+ import {
10
+ asRecords,
11
+ cartItems,
12
+ formatMoney,
13
+ numberValue,
14
+ productVariantCurrency,
15
+ productVariantPrice,
16
+ stringValue,
17
+ type JsonRecord,
18
+ } from "@/lib/core/commerce"
19
+ import { getSharedCart, type SharedCartPayload } from "@/lib/core/shared-cart"
20
+ import type { CoreConfig } from "@/lib/core/types"
21
+ import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
22
+
23
+ type PreviewItem = {
24
+ productId: string | null
25
+ variantId: string
26
+ quantity: number
27
+ productTitle: string
28
+ variantTitle: string
29
+ thumbnail: string
30
+ sku: string
31
+ price: number
32
+ currency: string
33
+ available: boolean
34
+ availability: number | null
35
+ manageInventory: boolean
36
+ allowBackorder: boolean
37
+ }
38
+
39
+ export function SharedCartView({ token, config }: { token: string; config: CoreConfig }) {
40
+ const api = useMemo(() => checkoutApi(config), [config])
41
+ const { cart, cartId, adoptCart, refresh } = useCart()
42
+ const { showToast } = useToast()
43
+ const router = useRouter()
44
+ const pathname = usePathname()
45
+ const locale = localeFromPathname(pathname)
46
+ const routes = STOREFRONT_ROUTES[locale]
47
+ const [shared, setShared] = useState<SharedCartPayload | null>(null)
48
+ const [preview, setPreview] = useState<PreviewItem[]>([])
49
+ const [loading, setLoading] = useState(true)
50
+ const [applying, setApplying] = useState(false)
51
+ const [error, setError] = useState<string | null>(null)
52
+
53
+ useEffect(() => {
54
+ let cancelled = false
55
+ setLoading(true)
56
+ setError(null)
57
+
58
+ void getSharedCart(token)
59
+ .then(async ({ shared_cart }) => {
60
+ const productIds = [...new Set(
61
+ shared_cart.items
62
+ .map((item) => item.product_id)
63
+ .filter((id): id is string => Boolean(id)),
64
+ )]
65
+ const productResults = await Promise.all(
66
+ productIds.map(async (id) => {
67
+ try {
68
+ const result = await getProductById(id, shared_cart.region_id || undefined)
69
+ return [id, result.product] as const
70
+ } catch {
71
+ return [id, null] as const
72
+ }
73
+ }),
74
+ )
75
+ const products = new Map<string, JsonRecord | null>(productResults)
76
+ const rows = shared_cart.items.map((item) =>
77
+ buildPreviewItem(
78
+ item,
79
+ products.get(item.product_id || "") || null,
80
+ shared_cart.currency_code || config.store.default_currency,
81
+ ),
82
+ )
83
+ if (!cancelled) {
84
+ setShared(shared_cart)
85
+ setPreview(rows)
86
+ }
87
+ })
88
+ .catch((cause) => {
89
+ if (!cancelled) setError(cause instanceof Error ? cause.message : "A megosztott kosár nem tölthető be.")
90
+ })
91
+ .finally(() => {
92
+ if (!cancelled) setLoading(false)
93
+ })
94
+
95
+ return () => { cancelled = true }
96
+ }, [config.store.default_currency, token])
97
+
98
+ const existingItems = cartItems(cart)
99
+ const hasExistingCart = existingItems.length > 0
100
+ const availableItems = preview.filter((item) => item.available)
101
+
102
+ const apply = async (mode: "merge" | "replace") => {
103
+ if (!shared || !availableItems.length) return
104
+ setApplying(true)
105
+ try {
106
+ let targetCartId = mode === "merge" ? cartId : null
107
+ let currentLines = mode === "merge" ? cartItems(cart) : []
108
+
109
+ if (!targetCartId) {
110
+ const created = await api.createCart({
111
+ ...(shared.region_id ? { region_id: shared.region_id } : {}),
112
+ })
113
+ targetCartId = stringValue(created.cart.id)
114
+ currentLines = []
115
+ if (!targetCartId) throw new Error("Nem sikerült új kosarat létrehozni.")
116
+ }
117
+
118
+ const lineByVariant = new Map(
119
+ currentLines
120
+ .map((line) => [stringValue(line.variant_id), line] as const)
121
+ .filter(([variantId]) => Boolean(variantId)),
122
+ )
123
+
124
+ if (mode === "merge") {
125
+ for (const item of availableItems) {
126
+ const existing = lineByVariant.get(item.variantId)
127
+ const nextQuantity = numberValue(existing?.quantity, 0) + item.quantity
128
+ if (
129
+ item.manageInventory &&
130
+ !item.allowBackorder &&
131
+ item.availability != null &&
132
+ nextQuantity > item.availability
133
+ ) {
134
+ throw new Error(
135
+ `${item.productTitle}: az egyesített mennyiség (${nextQuantity}) meghaladja az aktuális készletet (${item.availability}).`,
136
+ )
137
+ }
138
+ }
139
+ }
140
+
141
+ for (const item of availableItems) {
142
+ const existing = lineByVariant.get(item.variantId)
143
+ if (mode === "merge" && existing) {
144
+ const lineId = stringValue(existing.id)
145
+ const nextQuantity = numberValue(existing.quantity, 0) + item.quantity
146
+ await api.updateLineItem(targetCartId, lineId, nextQuantity)
147
+ existing.quantity = nextQuantity
148
+ } else {
149
+ const result = await api.addLineItem(targetCartId, item.variantId, item.quantity)
150
+ const added = cartItems(result.cart).find((line) => stringValue(line.variant_id) === item.variantId)
151
+ if (added) lineByVariant.set(item.variantId, added)
152
+ }
153
+ }
154
+
155
+ if (mode === "replace" || targetCartId !== cartId) await adoptCart(targetCartId)
156
+ else await refresh(targetCartId)
157
+
158
+ const skipped = preview.length - availableItems.length
159
+ showToast({
160
+ message: skipped
161
+ ? `A kosár betöltve. ${skipped} jelenleg nem elérhető tételt kihagytunk.`
162
+ : "A megosztott kosár betöltve.",
163
+ tone: skipped ? "info" : "success",
164
+ })
165
+ router.push(routes.cart)
166
+ } catch (cause) {
167
+ showToast({
168
+ message: cause instanceof Error ? cause.message : "A kosár betöltése nem sikerült.",
169
+ tone: "error",
170
+ })
171
+ } finally {
172
+ setApplying(false)
173
+ }
174
+ }
175
+
176
+ if (loading) return <div className="empty-state" role="status">Megosztott kosár betöltése…</div>
177
+ if (error || !shared) return <div className="empty-state"><strong>{error || "A megosztott kosár nem található."}</strong></div>
178
+
179
+ return (
180
+ <div className="stack">
181
+ <div className="stack-sm">
182
+ <strong>Megosztott kosár</strong>
183
+ <span className="muted">Az árak és a készlet most, a megnyitás pillanatában kerültek lekérésre.</span>
184
+ <span className="muted">A link lejárata: {new Date(shared.expires_at).toLocaleString("hu-HU")}</span>
185
+ </div>
186
+
187
+ <div className="cart-lines">
188
+ {preview.map((item) => (
189
+ <div className="cart-line" key={item.variantId}>
190
+ <div className="cart-line-image">
191
+ {item.thumbnail ? <img src={item.thumbnail} alt={item.productTitle} loading="lazy" /> : <span className="media-placeholder" aria-hidden="true" />}
192
+ </div>
193
+ <div className="cart-line-copy">
194
+ <strong>{item.productTitle}</strong>
195
+ {item.variantTitle ? <span className="muted">{item.variantTitle}</span> : null}
196
+ {item.sku ? <span className="muted">SKU: {item.sku}</span> : null}
197
+ <span>{item.quantity} × {Number.isFinite(item.price) ? formatMoney(item.price, item.currency, "hu-HU") : "Aktuális ár nem érhető el"}</span>
198
+ <span className={item.available ? "muted" : "error"}>
199
+ {item.available ? "Elérhető" : "Jelenleg nem elérhető"}
200
+ {item.manageInventory && item.availability != null ? ` · készlet: ${item.availability}` : ""}
201
+ </span>
202
+ </div>
203
+ </div>
204
+ ))}
205
+ </div>
206
+
207
+ {!availableItems.length ? <p className="error">A megosztott kosár egyik tétele sem rendelhető jelenleg.</p> : null}
208
+
209
+ <div className="button-row">
210
+ {hasExistingCart ? (
211
+ <>
212
+ <button className="button" type="button" disabled={applying || !availableItems.length} onClick={() => void apply("merge")}>Kosarak egyesítése</button>
213
+ <button className="button secondary" type="button" disabled={applying || !availableItems.length} onClick={() => void apply("replace")}>Saját kosár lecserélése</button>
214
+ </>
215
+ ) : (
216
+ <button className="button" type="button" disabled={applying || !availableItems.length} onClick={() => void apply("replace")}>Kosár betöltése</button>
217
+ )}
218
+ <button className="button secondary" type="button" disabled={applying} onClick={() => router.push(routes.cart)}>Elvetés</button>
219
+ </div>
220
+ </div>
221
+ )
222
+ }
223
+
224
+ function buildPreviewItem(
225
+ item: SharedCartPayload["items"][number],
226
+ product: JsonRecord | null,
227
+ fallbackCurrency: string,
228
+ ): PreviewItem {
229
+ const variants = asRecords(product?.variants)
230
+ const variant = variants.find((candidate) => stringValue(candidate.id) === item.variant_id) || null
231
+ const manageInventory = variant?.manage_inventory === true
232
+ const allowBackorder = variant?.allow_backorder === true
233
+ const availability = typeof item.availability === "number" && Number.isFinite(item.availability)
234
+ ? item.availability
235
+ : null
236
+ const available = Boolean(
237
+ variant && (!manageInventory || allowBackorder || availability == null || availability >= item.quantity),
238
+ )
239
+ const images = asRecords(product?.images)
240
+ const thumbnail = stringValue(product?.thumbnail || images[0]?.url)
241
+
242
+ return {
243
+ productId: item.product_id,
244
+ variantId: item.variant_id,
245
+ quantity: item.quantity,
246
+ productTitle: stringValue(product?.title) || "Ismeretlen termék",
247
+ variantTitle: stringValue(variant?.title),
248
+ thumbnail,
249
+ sku: stringValue(variant?.sku),
250
+ price: productVariantPrice(variant),
251
+ currency: productVariantCurrency(variant, fallbackCurrency),
252
+ available,
253
+ availability,
254
+ manageInventory,
255
+ allowBackorder,
256
+ }
257
+ }
@@ -86,3 +86,15 @@ export function getProductByHandle(handle: string, regionId?: string, locale?: s
86
86
  { next: { revalidate: 60 } },
87
87
  )
88
88
  }
89
+
90
+ export function getProductById(productId: string, regionId?: string, locale?: string) {
91
+ const params = new URLSearchParams({
92
+ fields: "+variants.calculated_price,+categories,+images",
93
+ })
94
+ if (regionId) params.set("region_id", regionId)
95
+ if (locale?.trim()) params.set("locale", locale.trim())
96
+ return medusaFetch<{ product: Record<string, unknown> }>(
97
+ `/store/products/${encodeURIComponent(productId)}?${params.toString()}`,
98
+ { cache: "no-store" },
99
+ )
100
+ }
@@ -1,4 +1,5 @@
1
1
  import { endpoint, medusaFetch } from "./client"
2
+ import { trackGoogleAdsPurchase } from "./google-ads"
2
3
  import {
3
4
  trackCartEvent,
4
5
  trackCartLineChange,
@@ -86,6 +87,59 @@ export function checkoutApi(config: CoreConfig) {
86
87
  })
87
88
  }
88
89
 
90
+ const saveFoxpostSelection = (
91
+ cartId: string,
92
+ deliveryType: "LOCKER" | "HOME",
93
+ locker: Record<string, unknown> | null = null,
94
+ ) =>
95
+ medusaFetch<{ foxpost: Record<string, unknown> }>(
96
+ endpoint(paths.foxpost_selection, { id: cartId }),
97
+ {
98
+ method: "POST",
99
+ body: JSON.stringify({ deliveryType, locker }),
100
+ },
101
+ )
102
+
103
+ const saveGlsSelection = (
104
+ cartId: string,
105
+ deliveryType: "POINT" | "HOME",
106
+ deliveryPoint: Record<string, unknown> | null = null,
107
+ ) =>
108
+ medusaFetch<{ gls: Record<string, unknown> }>(
109
+ endpoint(paths.gls_selection, { id: cartId }),
110
+ {
111
+ method: "POST",
112
+ body: JSON.stringify({ deliveryType, deliveryPoint }),
113
+ },
114
+ )
115
+
116
+ const persistCarrierSelection = async (
117
+ cartId: string,
118
+ optionId: string,
119
+ data: Record<string, unknown> | undefined,
120
+ cart: Record<string, unknown>,
121
+ ) => {
122
+ const selected = selectedShippingMethod(cart, optionId)
123
+ const carrierText = shippingMethodDescriptor(selected, optionId)
124
+ const foxpostData = isRecord(data?.foxpost) ? data.foxpost : null
125
+ const glsData = isRecord(data?.gls) ? data.gls : null
126
+
127
+ if (foxpostData || carrierText.includes("foxpost")) {
128
+ const locker = foxpostData && isRecord(foxpostData.locker)
129
+ ? foxpostData.locker
130
+ : null
131
+ await saveFoxpostSelection(cartId, locker ? "LOCKER" : "HOME", locker)
132
+ return
133
+ }
134
+
135
+ if (glsData || carrierText.includes("gls")) {
136
+ const deliveryPoint = glsData && isRecord(glsData.deliveryPoint)
137
+ ? glsData.deliveryPoint
138
+ : null
139
+ await saveGlsSelection(cartId, deliveryPoint ? "POINT" : "HOME", deliveryPoint)
140
+ }
141
+ }
142
+
89
143
  return {
90
144
  regions,
91
145
  resolveDefaultRegion,
@@ -225,10 +279,14 @@ export function checkoutApi(config: CoreConfig) {
225
279
  body: JSON.stringify({ option_id: optionId, ...(data ? { data } : {}) }),
226
280
  },
227
281
  )
282
+ await persistCarrierSelection(cartId, optionId, data, result.cart)
228
283
  trackShippingInfo(config.analytics, result.cart, shippingTier(result.cart, optionId))
229
284
  return result
230
285
  },
231
286
 
287
+ saveFoxpostSelection,
288
+ saveGlsSelection,
289
+
232
290
  foxpostLockers: () =>
233
291
  medusaFetch<{ lockers: Array<Record<string, unknown>> }>(paths.foxpost_lockers, {
234
292
  cache: "no-store",
@@ -295,6 +353,7 @@ export function checkoutApi(config: CoreConfig) {
295
353
  )
296
354
  if (result.type === "order" && isRecord(result.order)) {
297
355
  trackPurchase(config.analytics, result.order)
356
+ trackGoogleAdsPurchase(config.marketing.google_ads, result.order)
298
357
  }
299
358
  return result
300
359
  },
@@ -309,11 +368,34 @@ function findLine(
309
368
  return cart.items.filter(isRecord).find(predicate) || null
310
369
  }
311
370
 
371
+ function selectedShippingMethod(cart: Record<string, unknown>, optionId: string) {
372
+ return asRecords(cart.shipping_methods).find(
373
+ (method) => stringValue(method.shipping_option_id) === optionId,
374
+ ) || null
375
+ }
376
+
377
+ function shippingMethodDescriptor(
378
+ method: Record<string, unknown> | null,
379
+ optionId: string,
380
+ ) {
381
+ const option = method && isRecord(method.shipping_option)
382
+ ? method.shipping_option
383
+ : {}
384
+ return [
385
+ optionId,
386
+ method?.name,
387
+ method?.provider_id,
388
+ option.id,
389
+ option.name,
390
+ option.provider_id,
391
+ ]
392
+ .map((value) => stringValue(value).toLowerCase())
393
+ .filter(Boolean)
394
+ .join(" ")
395
+ }
396
+
312
397
  function shippingTier(cart: Record<string, unknown>, optionId: string) {
313
- if (!Array.isArray(cart.shipping_methods)) return optionId
314
- const selected = cart.shipping_methods
315
- .filter(isRecord)
316
- .find((method) => method.shipping_option_id === optionId)
398
+ const selected = selectedShippingMethod(cart, optionId)
317
399
  const shippingOption = selected && isRecord(selected.shipping_option)
318
400
  ? selected.shipping_option
319
401
  : null
@@ -0,0 +1,51 @@
1
+ import { CoreApiError, medusaFetch } from "./client"
2
+
3
+ export type CustomerCartResumeAction =
4
+ | "none"
5
+ | "resume"
6
+ | "keep-current"
7
+ | "merge-required"
8
+
9
+ export type CustomerCartResumeSummary = {
10
+ id: string
11
+ customer_id?: string | null
12
+ item_count?: number
13
+ status?: string | null
14
+ }
15
+
16
+ export type CustomerCartResumeDecision = {
17
+ action: CustomerCartResumeAction
18
+ target_cart_id: string | null
19
+ merge_required: boolean
20
+ active_cart: CustomerCartResumeSummary | null
21
+ current_cart: CustomerCartResumeSummary | null
22
+ }
23
+
24
+ export const CUSTOMER_CART_RESUME_CONFLICT_EVENT =
25
+ "hszrdm:customer-cart-resume-conflict"
26
+
27
+ export function resolveCustomerCartResume(currentCartId?: string | null) {
28
+ const params = new URLSearchParams()
29
+ if (currentCartId?.trim()) params.set("current_cart_id", currentCartId.trim())
30
+ const suffix = params.size ? `?${params.toString()}` : ""
31
+ return medusaFetch<CustomerCartResumeDecision>(
32
+ `/store/core-carts/me/active${suffix}`,
33
+ { cache: "no-store" },
34
+ )
35
+ }
36
+
37
+ export function isUnauthenticatedCartResume(error: unknown) {
38
+ return error instanceof CoreApiError && error.status === 401
39
+ }
40
+
41
+ export function announceCustomerCartResumeConflict(
42
+ decision: CustomerCartResumeDecision,
43
+ ) {
44
+ if (typeof window === "undefined") return
45
+ window.dispatchEvent(
46
+ new CustomEvent<CustomerCartResumeDecision>(
47
+ CUSTOMER_CART_RESUME_CONFLICT_EVENT,
48
+ { detail: decision },
49
+ ),
50
+ )
51
+ }
@@ -0,0 +1,58 @@
1
+ import { readConsentPreferences } from "./consent"
2
+ import type { CoreConfig } from "./types"
3
+
4
+ export function trackGoogleAdsPurchase(
5
+ googleAds: CoreConfig["marketing"]["google_ads"],
6
+ order: Record<string, unknown>,
7
+ ) {
8
+ if (typeof window === "undefined") return false
9
+ if (!googleAds.enabled || !googleAds.purchase_send_to) return false
10
+ if (!readConsentPreferences()?.marketing) return false
11
+
12
+ const transactionId = text(order.id) || text(order.display_id)
13
+ if (!transactionId) return false
14
+
15
+ const dedupeKey = `core:google-ads:purchase:${transactionId}`
16
+ if (window.localStorage.getItem(dedupeKey) === "sent") return false
17
+
18
+ const payload = {
19
+ send_to: googleAds.purchase_send_to,
20
+ transaction_id: transactionId,
21
+ value: finite(order.total),
22
+ currency: text(order.currency_code).toUpperCase() || "HUF",
23
+ }
24
+
25
+ const target = window as typeof window & {
26
+ dataLayer?: Array<Record<string, unknown> | unknown[]>
27
+ gtag?: (...args: unknown[]) => void
28
+ }
29
+ target.dataLayer = target.dataLayer || []
30
+
31
+ if (googleAds.google_tag_manager_enabled) {
32
+ target.dataLayer.push({
33
+ event: "google_ads_purchase",
34
+ ...payload,
35
+ })
36
+ window.localStorage.setItem(dedupeKey, "sent")
37
+ return true
38
+ }
39
+
40
+ if (typeof target.gtag === "function") {
41
+ target.gtag("event", "conversion", payload)
42
+ window.localStorage.setItem(dedupeKey, "sent")
43
+ return true
44
+ }
45
+
46
+ return false
47
+ }
48
+
49
+ function text(value: unknown) {
50
+ return typeof value === "string" || typeof value === "number"
51
+ ? String(value).trim()
52
+ : ""
53
+ }
54
+
55
+ function finite(value: unknown) {
56
+ const result = typeof value === "number" ? value : Number(value)
57
+ return Number.isFinite(result) ? result : undefined
58
+ }
@@ -1,6 +1,14 @@
1
1
  import { absoluteBackendUrl, endpoint, medusaFetch } from "./client"
2
2
  import type { CoreConfig, LegalDocument } from "./types"
3
3
 
4
+ export type LegalEmbedConfig = {
5
+ enabled: boolean
6
+ provider?: string
7
+ scriptUrl?: string
8
+ dataId?: string
9
+ dataType?: string
10
+ }
11
+
4
12
  export async function listLegalDocuments(config: CoreConfig) {
5
13
  const result = await medusaFetch<{ documents: LegalDocument[] }>(
6
14
  config.legal.documents_endpoint,
@@ -17,6 +25,12 @@ export async function listLegalDocuments(config: CoreConfig) {
17
25
  }
18
26
  }
19
27
 
28
+ export function getLegalEmbed() {
29
+ return medusaFetch<LegalEmbedConfig>("/store/legal/embed", {
30
+ cache: "no-store",
31
+ })
32
+ }
33
+
20
34
  export function acceptLegalDocument(
21
35
  config: CoreConfig,
22
36
  key: string,
@@ -0,0 +1,37 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type SharedCartSnapshotItem = {
4
+ product_id: string | null
5
+ variant_id: string
6
+ quantity: number
7
+ availability?: number | null
8
+ }
9
+
10
+ export type SharedCartPayload = {
11
+ items: SharedCartSnapshotItem[]
12
+ region_id: string | null
13
+ currency_code: string | null
14
+ expires_at: string
15
+ use_count: number
16
+ }
17
+
18
+ export function createSharedCart(input: {
19
+ items: SharedCartSnapshotItem[]
20
+ region_id?: string | null
21
+ currency_code?: string | null
22
+ }) {
23
+ return medusaFetch<{ token: string; expires_at: string; use_count: number }>(
24
+ "/store/shared-carts",
25
+ {
26
+ method: "POST",
27
+ body: JSON.stringify(input),
28
+ },
29
+ )
30
+ }
31
+
32
+ export function getSharedCart(token: string) {
33
+ return medusaFetch<{ shared_cart: SharedCartPayload }>(
34
+ `/store/shared-carts/${encodeURIComponent(token)}`,
35
+ { cache: "no-store" },
36
+ )
37
+ }
@@ -19,9 +19,18 @@ export type CoreConfig = {
19
19
  seo: boolean
20
20
  analytics: boolean
21
21
  merchant_feed: boolean
22
+ google_ads: boolean
22
23
  }
23
24
  account: {
24
25
  enabled: boolean
26
+ profile: boolean
27
+ addresses: boolean
28
+ order_history: boolean
29
+ email_verification: boolean
30
+ email_change: boolean
31
+ password_reset: boolean
32
+ password_change: boolean
33
+ delete_account: boolean
25
34
  managed_by: Record<string, string>
26
35
  endpoints: EndpointMap
27
36
  }
@@ -81,6 +90,15 @@ export type CoreConfig = {
81
90
  }
82
91
  marketing: {
83
92
  google_merchant: { enabled: boolean; feed_endpoint: string }
93
+ google_ads: {
94
+ enabled: boolean
95
+ consent_required: true
96
+ conversion_id: string | null
97
+ purchase_conversion_label: string | null
98
+ purchase_send_to: string | null
99
+ remarketing_enabled: boolean
100
+ google_tag_manager_enabled: boolean
101
+ }
84
102
  }
85
103
  checkout: {
86
104
  payment_availability: "medusa_region"
@@ -5,6 +5,7 @@ export const STOREFRONT_ROUTES = {
5
5
  products: "/hu/termekek",
6
6
  categories: "/hu/kategoriak",
7
7
  cart: "/hu/kosar",
8
+ sharedCart: "/hu/kosar/megosztas",
8
9
  cartRecovery: "/hu/kosar-visszaallitas",
9
10
  checkout: "/hu/penztar",
10
11
  checkoutSuccess: "/hu/penztar/sikeres-rendeles",
@@ -25,6 +26,7 @@ export const STOREFRONT_ROUTES = {
25
26
  products: "/en/products",
26
27
  categories: "/en/categories",
27
28
  cart: "/en/cart",
29
+ sharedCart: "/en/cart/shared",
28
30
  cartRecovery: "/en/cart-recovery",
29
31
  checkout: "/en/checkout",
30
32
  checkoutSuccess: "/en/checkout/success",
@@ -71,6 +73,10 @@ export function orderPath(locale: StorefrontLocale, orderId: string) {
71
73
  return `${STOREFRONT_ROUTES[locale].orders}/${encodeURIComponent(orderId)}`
72
74
  }
73
75
 
76
+ export function sharedCartPath(locale: StorefrontLocale, token: string) {
77
+ return `${STOREFRONT_ROUTES[locale].sharedCart}/${encodeURIComponent(token)}`
78
+ }
79
+
74
80
  export function blogPostPath(locale: StorefrontLocale, slug: string) {
75
81
  return `${STOREFRONT_ROUTES[locale].blog}/${encodeURIComponent(slug)}`
76
82
  }
@@ -103,6 +109,9 @@ export function equivalentLocalePath(
103
109
  return `${target.categories}/${pathname.slice(source.categories.length + 1)}`
104
110
  }
105
111
  if (pathname === source.cart) return target.cart
112
+ if (pathname.startsWith(`${source.sharedCart}/`)) {
113
+ return `${target.sharedCart}/${pathname.slice(source.sharedCart.length + 1)}`
114
+ }
106
115
  if (pathname === source.cartRecovery) return target.cartRecovery
107
116
  if (pathname === source.checkout) return target.checkout
108
117
  if (pathname === source.checkoutSuccess) return target.checkoutSuccess
@@ -52,6 +52,9 @@ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
52
52
  if (pathname === "/") return STOREFRONT_ROUTES[locale].home
53
53
 
54
54
  if (pathname === "/cart") return STOREFRONT_ROUTES[locale].cart
55
+ if (pathname.startsWith("/cart/shared/")) {
56
+ return `${STOREFRONT_ROUTES[locale].sharedCart}/${pathname.slice("/cart/shared/".length)}`
57
+ }
55
58
  if (pathname === "/cart-recovery" || pathname === "/kosar-visszaallitas") return STOREFRONT_ROUTES[locale].cartRecovery
56
59
  if (pathname === "/checkout") return STOREFRONT_ROUTES[locale].checkout
57
60
  if (pathname === "/checkout/success") return STOREFRONT_ROUTES[locale].checkoutSuccess
@@ -73,6 +76,7 @@ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
73
76
  if (pathname === "/hu/categories") return STOREFRONT_ROUTES.hu.categories
74
77
  if (pathname.startsWith("/hu/categories/")) return `${STOREFRONT_ROUTES.hu.categories}/${pathname.slice("/hu/categories/".length)}`
75
78
  if (pathname === "/hu/cart") return STOREFRONT_ROUTES.hu.cart
79
+ if (pathname.startsWith("/hu/cart/shared/")) return `${STOREFRONT_ROUTES.hu.sharedCart}/${pathname.slice("/hu/cart/shared/".length)}`
76
80
  if (pathname === "/hu/cart-recovery") return STOREFRONT_ROUTES.hu.cartRecovery
77
81
  if (pathname === "/hu/checkout") return STOREFRONT_ROUTES.hu.checkout
78
82
  if (pathname === "/hu/checkout/success") return STOREFRONT_ROUTES.hu.checkoutSuccess
@@ -99,6 +103,9 @@ function internalRewrite(pathname: string, locale: StorefrontLocale) {
99
103
  }
100
104
 
101
105
  if (pathname === routes.cart) return "/cart"
106
+ if (pathname.startsWith(`${routes.sharedCart}/`)) {
107
+ return `/cart/shared/${pathname.slice(routes.sharedCart.length + 1)}`
108
+ }
102
109
  if (pathname === routes.cartRecovery) return "/cart-recovery"
103
110
  if (pathname === routes.checkout) return "/checkout"
104
111
  if (pathname === routes.checkoutSuccess) return "/checkout/success"