@hszrdm/create-commerce 1.0.3 → 1.2.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 (69) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +5 -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 +46 -10
  11. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  12. package/templates/storefront/src/app/account/page.tsx +12 -1
  13. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  14. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  15. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  16. package/templates/storefront/src/app/core-ux.css +244 -0
  17. package/templates/storefront/src/app/layout.tsx +40 -14
  18. package/templates/storefront/src/app/legal/page.tsx +11 -5
  19. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  20. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  21. package/templates/storefront/src/app/page.tsx +18 -12
  22. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  23. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  24. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  25. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  26. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  27. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  28. package/templates/storefront/src/components/add-to-cart.tsx +127 -18
  29. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  30. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  31. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  32. package/templates/storefront/src/components/cart-view.tsx +96 -32
  33. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  34. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  35. package/templates/storefront/src/components/form-ux.tsx +47 -0
  36. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  37. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  38. package/templates/storefront/src/components/order-detail.tsx +84 -45
  39. package/templates/storefront/src/components/product-card.tsx +16 -8
  40. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  41. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  42. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  43. package/templates/storefront/src/components/share-button.tsx +63 -0
  44. package/templates/storefront/src/components/storefront-header.tsx +88 -20
  45. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  46. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  47. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  48. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  49. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  50. package/templates/storefront/src/lib/core/account.ts +3 -0
  51. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  52. package/templates/storefront/src/lib/core/client.ts +5 -0
  53. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  54. package/templates/storefront/src/lib/core/cms.ts +171 -0
  55. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  56. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  57. package/templates/storefront/src/lib/core/leads.ts +50 -0
  58. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  59. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  60. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  61. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  62. package/templates/storefront/src/lib/core/seo.ts +44 -6
  63. package/templates/storefront/src/lib/core/share.ts +57 -0
  64. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  65. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  66. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  67. package/templates/storefront/src/lib/storefront-routes.ts +94 -0
  68. package/templates/storefront/src/proxy.ts +145 -0
  69. package/templates/storefront/tsconfig.json +23 -5
@@ -0,0 +1,95 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { usePathname } from "next/navigation"
5
+ import { useCallback, useEffect, useState } from "react"
6
+ import { CoreApiError } from "@/lib/core/client"
7
+ import {
8
+ listWishlist,
9
+ removeWishlistProduct,
10
+ type WishlistItem,
11
+ } from "@/lib/core/wishlist"
12
+ import { localeFromPathname, productPath, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
13
+
14
+ export function AccountWishlist() {
15
+ const pathname = usePathname()
16
+ const locale = localeFromPathname(pathname)
17
+ const english = locale === "en"
18
+ const [items, setItems] = useState<WishlistItem[]>([])
19
+ const [loading, setLoading] = useState(true)
20
+ const [error, setError] = useState<string | null>(null)
21
+ const [busy, setBusy] = useState<string | null>(null)
22
+
23
+ const load = useCallback(async () => {
24
+ setLoading(true)
25
+ setError(null)
26
+ try {
27
+ const result = await listWishlist()
28
+ setItems(result.items)
29
+ } catch (cause) {
30
+ if (cause instanceof CoreApiError && cause.status === 401) {
31
+ setError(english ? "Sign in to view your wishlist." : "A kedvencek megtekintéséhez jelentkezz be.")
32
+ } else {
33
+ setError(cause instanceof Error ? cause.message : (english ? "Wishlist could not be loaded." : "A kedvencek nem tölthetők be."))
34
+ }
35
+ } finally {
36
+ setLoading(false)
37
+ }
38
+ }, [english])
39
+
40
+ useEffect(() => { void load() }, [load])
41
+
42
+ const remove = async (productId: string) => {
43
+ setBusy(productId)
44
+ try {
45
+ await removeWishlistProduct(productId)
46
+ setItems((current) => current.filter((item) => item.product_id !== productId))
47
+ } finally {
48
+ setBusy(null)
49
+ }
50
+ }
51
+
52
+ if (loading) return <section className="panel"><p>{english ? "Loading wishlist…" : "Kedvencek betöltése…"}</p></section>
53
+
54
+ return (
55
+ <section className="panel stack">
56
+ <div>
57
+ <p className="eyebrow">{english ? "Customer account" : "Ügyfélfiók"}</p>
58
+ <h1>{english ? "Wishlist" : "Kedvencek"}</h1>
59
+ </div>
60
+
61
+ {error ? (
62
+ <div className="empty-state stack-sm">
63
+ <p>{error}</p>
64
+ <Link className="button" href={STOREFRONT_ROUTES[locale].account}>{english ? "Go to account" : "Tovább a fiókhoz"}</Link>
65
+ </div>
66
+ ) : null}
67
+
68
+ {!error && !items.length ? <div className="empty-state">{english ? "Your wishlist is empty." : "Még nincs mentett kedvenced."}</div> : null}
69
+
70
+ {!error && items.length ? (
71
+ <div className="product-grid">
72
+ {items.map((item) => {
73
+ const product = item.product
74
+ const handle = product?.handle || ""
75
+ return (
76
+ <article className="panel stack-sm" key={item.id}>
77
+ {product?.thumbnail ? <img src={product.thumbnail} alt={product.title || ""} className="product-card-image" /> : null}
78
+ <div>
79
+ <strong>{product?.title || item.product_id}</strong>
80
+ <p className="muted small">{english ? "Saved product" : "Mentett termék"}</p>
81
+ </div>
82
+ <div className="button-row">
83
+ {handle ? <Link className="button secondary" href={productPath(locale, handle)}>{english ? "View" : "Megnézem"}</Link> : null}
84
+ <button className="button secondary" type="button" disabled={busy === item.product_id} onClick={() => void remove(item.product_id)}>
85
+ {busy === item.product_id ? (english ? "Removing…" : "Törlés…") : (english ? "Remove" : "Törlés")}
86
+ </button>
87
+ </div>
88
+ </article>
89
+ )
90
+ })}
91
+ </div>
92
+ ) : null}
93
+ </section>
94
+ )
95
+ }
@@ -1,71 +1,180 @@
1
1
  "use client"
2
2
 
3
3
  import { useMemo, useState } from "react"
4
+ import { usePathname } from "next/navigation"
5
+ import { QuantityStepper } from "./quantity-stepper"
6
+ import { useToast } from "./toast-provider"
4
7
  import { useCart } from "./cart-provider"
5
8
  import {
6
9
  asRecords,
7
10
  formatMoney,
11
+ numberValue,
8
12
  productVariantCurrency,
9
13
  productVariantPrice,
10
14
  stringValue,
11
15
  } from "@/lib/core/commerce"
16
+ import { humanizeStorefrontError } from "@/lib/core/form-ux"
17
+ import { copyText } from "@/lib/core/share"
12
18
  import type { CoreConfig } from "@/lib/core/types"
19
+ import { localeFromPathname } from "@/lib/storefront-routes"
13
20
 
14
21
  export function AddToCart({ product, config }: { product: Record<string, unknown>; config: CoreConfig }) {
22
+ const pathname = usePathname()
23
+ const locale = localeFromPathname(pathname)
24
+ const en = locale === "en"
15
25
  const variants = useMemo(() => asRecords(product.variants), [product])
26
+ const productMetadata = isRecord(product.metadata) ? product.metadata : {}
16
27
  const [variantId, setVariantId] = useState(() => stringValue(variants[0]?.id))
17
- const [quantity, setQuantity] = useState(1)
28
+ const [quantity, setQuantity] = useState(() => variantMinimum(variants[0], productMetadata))
18
29
  const [message, setMessage] = useState<string | null>(null)
30
+ const [success, setSuccess] = useState(false)
19
31
  const { addItem, mutating } = useCart()
32
+ const { showToast } = useToast()
20
33
  const selected = variants.find((variant) => stringValue(variant.id) === variantId) || variants[0]
21
34
  const price = productVariantPrice(selected)
22
35
  const currency = productVariantCurrency(selected, config.store.default_currency)
36
+ const formatLocale = en ? "en-US" : "hu-HU"
37
+ const minQuantity = variantMinimum(selected, productMetadata)
38
+ const inventory = Number(selected?.inventory_quantity)
39
+ const managesInventory = selected?.manage_inventory === true
40
+ const allowBackorder = selected?.allow_backorder === true
41
+ const hasKnownInventory = Number.isFinite(inventory)
42
+ const purchasable = !managesInventory || allowBackorder || !hasKnownInventory || inventory >= minQuantity
43
+ const maxQuantity = managesInventory && !allowBackorder && hasKnownInventory
44
+ ? Math.max(1, Math.trunc(inventory))
45
+ : 999
46
+ const sku = stringValue(selected?.sku)
23
47
 
24
48
  if (!variants.length) {
25
- return <div className="notice warning">Ehhez a termékhez nincs megvásárolható variáns.</div>
49
+ return <div className="notice warning" role="status">{en ? "This product has no purchasable variant." : "Ehhez a termékhez nincs megvásárolható variáns."}</div>
26
50
  }
27
51
 
28
52
  return (
29
53
  <div className="buy-box stack-sm">
30
54
  {variants.length > 1 ? (
31
55
  <label>
32
- Változat
33
- <select value={variantId} onChange={(event) => setVariantId(event.target.value)}>
56
+ {en ? "Variant" : "Változat"}
57
+ <select
58
+ value={variantId}
59
+ onChange={(event) => {
60
+ const nextId = event.target.value
61
+ const next = variants.find((variant) => stringValue(variant.id) === nextId)
62
+ const nextPrice = productVariantPrice(next)
63
+ const nextCurrency = productVariantCurrency(next, config.store.default_currency)
64
+ setVariantId(nextId)
65
+ setQuantity(variantMinimum(next, productMetadata))
66
+ setMessage(null)
67
+ if (typeof window !== "undefined") {
68
+ window.dispatchEvent(new CustomEvent("hszrdm:product-variant-change", {
69
+ detail: {
70
+ variantId: nextId,
71
+ imageUrl: variantImageUrl(next),
72
+ price: nextPrice,
73
+ currency: nextCurrency,
74
+ },
75
+ }))
76
+ }
77
+ }}
78
+ >
34
79
  {variants.map((variant) => (
35
80
  <option key={stringValue(variant.id)} value={stringValue(variant.id)}>
36
81
  {stringValue(variant.title || variant.sku || variant.id)}
37
82
  {Number.isFinite(productVariantPrice(variant))
38
- ? ` – ${formatMoney(productVariantPrice(variant), productVariantCurrency(variant, currency), config.store.locale)}`
83
+ ? ` – ${formatMoney(productVariantPrice(variant), productVariantCurrency(variant, currency), formatLocale)}`
39
84
  : ""}
40
85
  </option>
41
86
  ))}
42
87
  </select>
43
88
  </label>
44
89
  ) : null}
90
+
45
91
  <div className="buy-row">
46
- <label className="quantity-field">
47
- Mennyiség
48
- <input min={1} max={99} type="number" value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} />
49
- </label>
92
+ <div className="quantity-field">
93
+ <span className="field-label">{en ? "Quantity" : "Mennyiség"}</span>
94
+ <QuantityStepper
95
+ value={Math.max(minQuantity, quantity)}
96
+ min={minQuantity}
97
+ max={Math.max(minQuantity, maxQuantity)}
98
+ disabled={mutating || !purchasable}
99
+ label={en ? "Quantity" : "Mennyiség"}
100
+ decreaseLabel={en ? "Decrease quantity" : "Mennyiség csökkentése"}
101
+ increaseLabel={en ? "Increase quantity" : "Mennyiség növelése"}
102
+ onChange={setQuantity}
103
+ />
104
+ {minQuantity > 1 ? <span className="field-hint">{en ? `Minimum order: ${minQuantity}` : `Minimum rendelés: ${minQuantity} db`}</span> : null}
105
+ </div>
50
106
  <div className="buy-price">
51
- <span className="muted">Ár</span>
52
- <strong>{Number.isFinite(price) ? formatMoney(price, currency, config.store.locale) : "—"}</strong>
107
+ <span className="muted">{en ? "Selected price" : "Kiválasztott ár"}</span>
108
+ <strong>{Number.isFinite(price) ? formatMoney(price, currency, formatLocale) : "—"}</strong>
53
109
  </div>
54
110
  </div>
111
+
112
+ <div className={`stock-status ${purchasable ? "is-available" : "is-unavailable"}`} role="status">
113
+ {purchasable
114
+ ? hasKnownInventory && managesInventory
115
+ ? (en ? `${Math.max(0, Math.trunc(inventory))} in stock` : `${Math.max(0, Math.trunc(inventory))} db készleten`)
116
+ : (en ? "Available to order" : "Rendelhető")
117
+ : hasKnownInventory && managesInventory && inventory > 0
118
+ ? (en ? `Only ${Math.max(0, Math.trunc(inventory))} in stock; minimum order is ${minQuantity}.` : `Csak ${Math.max(0, Math.trunc(inventory))} db van készleten, a minimum rendelés ${minQuantity} db.`)
119
+ : (en ? "Currently unavailable" : "Jelenleg nem vásárolható")}
120
+ </div>
121
+
122
+ {sku ? (
123
+ <div className="sku-row">
124
+ <span><span className="muted">SKU:</span> <code>{sku}</code></span>
125
+ <button
126
+ type="button"
127
+ className="text-button"
128
+ onClick={() => void copyText(sku).then(() => showToast({ message: en ? "SKU copied" : "SKU másolva", tone: "success" }))}
129
+ >
130
+ {en ? "Copy SKU" : "SKU másolása"}
131
+ </button>
132
+ </div>
133
+ ) : null}
134
+
55
135
  <button
56
- className="button button-large"
136
+ className="button button-large sticky-mobile-cta"
57
137
  type="button"
58
- disabled={mutating || !variantId}
138
+ disabled={mutating || !variantId || !purchasable || quantity < minQuantity}
139
+ aria-busy={mutating}
59
140
  onClick={() => {
60
141
  setMessage(null)
61
- void addItem(variantId, quantity)
62
- .then(() => setMessage("A termék bekerült a kosárba."))
63
- .catch((error) => setMessage(error instanceof Error ? error.message : "Nem sikerült kosárba tenni."))
142
+ setSuccess(false)
143
+ void addItem(variantId, Math.max(minQuantity, quantity))
144
+ .then(() => {
145
+ const next = en ? "The product was added to your cart." : "A termék bekerült a kosárba."
146
+ setSuccess(true)
147
+ setMessage(next)
148
+ showToast({ message: next, tone: "success" })
149
+ })
150
+ .catch((error) => {
151
+ const next = humanizeStorefrontError(error, locale)
152
+ setSuccess(false)
153
+ setMessage(next)
154
+ showToast({ message: next, tone: "error" })
155
+ })
64
156
  }}
65
157
  >
66
- {mutating ? "Kosár frissítése…" : "Kosárba"}
158
+ {mutating ? (en ? "Updating cart…" : "Kosár frissítése…") : purchasable ? (en ? "Add to cart" : "Kosárba") : (en ? "Unavailable" : "Nem vásárolható")}
67
159
  </button>
68
- {message ? <p className={message.includes("bekerült") ? "success" : "error"}>{message}</p> : null}
160
+ {message ? <p className={success ? "success" : "error"} aria-live="polite">{message}</p> : null}
69
161
  </div>
70
162
  )
71
163
  }
164
+
165
+ function variantMinimum(variant: Record<string, unknown> | undefined, productMetadata: Record<string, unknown>) {
166
+ const metadata = isRecord(variant?.metadata) ? variant.metadata : {}
167
+ return Math.max(1, Math.trunc(numberValue(metadata.minimum_order_quantity ?? productMetadata.minimum_order_quantity, 1)))
168
+ }
169
+
170
+ function variantImageUrl(variant: Record<string, unknown> | undefined) {
171
+ if (!variant) return ""
172
+ const direct = stringValue(variant.thumbnail)
173
+ if (direct) return direct
174
+ const images = asRecords(variant.images)
175
+ return stringValue(images[0]?.url)
176
+ }
177
+
178
+ function isRecord(value: unknown): value is Record<string, unknown> {
179
+ return Boolean(value && typeof value === "object" && !Array.isArray(value))
180
+ }
@@ -0,0 +1,26 @@
1
+ "use client"
2
+
3
+ import { useEffect, useState } from "react"
4
+ import { prefersReducedMotion } from "@/lib/core/form-ux"
5
+
6
+ export function BackToTop({ label = "Vissza a tetejére" }: { label?: string }) {
7
+ const [visible, setVisible] = useState(false)
8
+
9
+ useEffect(() => {
10
+ const onScroll = () => setVisible(window.scrollY > 700)
11
+ onScroll()
12
+ window.addEventListener("scroll", onScroll, { passive: true })
13
+ return () => window.removeEventListener("scroll", onScroll)
14
+ }, [])
15
+
16
+ if (!visible) return null
17
+ return (
18
+ <button
19
+ type="button"
20
+ className="back-to-top"
21
+ onClick={() => window.scrollTo({ top: 0, behavior: prefersReducedMotion() ? "auto" : "smooth" })}
22
+ >
23
+ {label}
24
+ </button>
25
+ )
26
+ }
@@ -0,0 +1,26 @@
1
+ import Link from "next/link"
2
+
3
+ type BreadcrumbItem = {
4
+ label: string
5
+ href?: string
6
+ }
7
+
8
+ export function Breadcrumbs({ items, label = "Morzsanavigáció" }: { items: BreadcrumbItem[]; label?: string }) {
9
+ if (!items.length) return null
10
+ return (
11
+ <nav className="breadcrumbs" aria-label={label}>
12
+ <ol>
13
+ {items.map((item, index) => {
14
+ const current = index === items.length - 1
15
+ return (
16
+ <li key={`${item.label}:${index}`}>
17
+ {item.href && !current
18
+ ? <Link href={item.href}>{item.label}</Link>
19
+ : <span aria-current={current ? "page" : undefined}>{item.label}</span>}
20
+ </li>
21
+ )
22
+ })}
23
+ </ol>
24
+ </nav>
25
+ )
26
+ }
@@ -9,9 +9,11 @@ import {
9
9
  useState,
10
10
  type ReactNode,
11
11
  } from "react"
12
+ import { usePathname } from "next/navigation"
12
13
  import { checkoutApi } from "@/lib/core/checkout"
13
- import { cartItemCount, type JsonRecord } from "@/lib/core/commerce"
14
+ import { cartItemCount, stringValue, type JsonRecord } from "@/lib/core/commerce"
14
15
  import type { CoreConfig } from "@/lib/core/types"
16
+ import { localeFromPathname, medusaLocale } from "@/lib/storefront-routes"
15
17
 
16
18
  const CART_STORAGE_KEY = "hszrdm_core_cart_id"
17
19
 
@@ -46,6 +48,8 @@ export function CartProvider({
46
48
  children: ReactNode
47
49
  }) {
48
50
  const api = useMemo(() => checkoutApi(config), [config])
51
+ const pathname = usePathname()
52
+ const activeLocale = medusaLocale(localeFromPathname(pathname))
49
53
  const [cart, setCart] = useState<JsonRecord | null>(null)
50
54
  const [cartId, setCartId] = useState<string | null>(null)
51
55
  const [loading, setLoading] = useState(true)
@@ -60,6 +64,16 @@ export function CartProvider({
60
64
  else window.localStorage.removeItem(CART_STORAGE_KEY)
61
65
  }, [])
62
66
 
67
+ const syncLocale = useCallback(
68
+ async (id: string, current: JsonRecord) => {
69
+ if (stringValue(current.locale).toLowerCase() === activeLocale.toLowerCase()) {
70
+ return current
71
+ }
72
+ return (await api.updateCart(id, { locale: activeLocale })).cart
73
+ },
74
+ [activeLocale, api],
75
+ )
76
+
63
77
  const refresh = useCallback(
64
78
  async (id?: string) => {
65
79
  const target = id || cartId
@@ -69,10 +83,11 @@ export function CartProvider({
69
83
  }
70
84
  try {
71
85
  const result = await api.getCart(target)
72
- setCart(result.cart)
86
+ const localizedCart = await syncLocale(target, result.cart)
87
+ setCart(localizedCart)
73
88
  storeCartId(target)
74
89
  setError(null)
75
- return result.cart
90
+ return localizedCart
76
91
  } catch (cause) {
77
92
  if (!id || id === cartId) {
78
93
  setCart(null)
@@ -82,7 +97,7 @@ export function CartProvider({
82
97
  return null
83
98
  }
84
99
  },
85
- [api, cartId, storeCartId],
100
+ [api, cartId, storeCartId, syncLocale],
86
101
  )
87
102
 
88
103
  useEffect(() => {
@@ -94,8 +109,9 @@ export function CartProvider({
94
109
  setCartId(id)
95
110
  void api
96
111
  .getCart(id)
97
- .then((result) => {
98
- setCart(result.cart)
112
+ .then((result) => syncLocale(id, result.cart))
113
+ .then((localizedCart) => {
114
+ setCart(localizedCart)
99
115
  setError(null)
100
116
  })
101
117
  .catch(() => {
@@ -104,13 +120,13 @@ export function CartProvider({
104
120
  setCart(null)
105
121
  })
106
122
  .finally(() => setLoading(false))
107
- }, [api])
123
+ }, [api, syncLocale])
108
124
 
109
125
  const ensureCart = useCallback(async () => {
110
126
  if (cartId) return cartId
111
127
  setMutating(true)
112
128
  try {
113
- const result = await api.createCart()
129
+ const result = await api.createCart({ locale: activeLocale })
114
130
  const id = String(result.cart.id || "")
115
131
  if (!id) throw new Error("A Medusa nem adott vissza cart ID-t.")
116
132
  setCart(result.cart)
@@ -119,19 +135,20 @@ export function CartProvider({
119
135
  } finally {
120
136
  setMutating(false)
121
137
  }
122
- }, [api, cartId, storeCartId])
138
+ }, [activeLocale, api, cartId, storeCartId])
123
139
 
124
140
  const adoptCart = useCallback(
125
141
  async (id: string) => {
126
142
  const normalized = id.trim()
127
143
  if (!normalized) return null
128
144
  const result = await api.getCart(normalized)
129
- setCart(result.cart)
145
+ const localizedCart = await syncLocale(normalized, result.cart)
146
+ setCart(localizedCart)
130
147
  storeCartId(normalized)
131
148
  setError(null)
132
- return result.cart
149
+ return localizedCart
133
150
  },
134
- [api, storeCartId],
151
+ [api, storeCartId, syncLocale],
135
152
  )
136
153
 
137
154
  const mutate = useCallback(