@hszrdm/create-commerce 1.4.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 (48) hide show
  1. package/package.json +1 -1
  2. package/templates/backend/.env.example +13 -0
  3. package/templates/backend/README.md +4 -0
  4. package/templates/backend/package.json +3 -1
  5. package/templates/backend/scripts/core-backup.mjs +281 -0
  6. package/templates/backend/scripts/core-restore.mjs +179 -0
  7. package/templates/backend/scripts/lib/core-backup-common.mjs +237 -0
  8. package/templates/backend/scripts/production-assets/deploy.sh +2 -1
  9. package/templates/backend/scripts/production-assets/install.sh +2 -1
  10. package/templates/backend/scripts/production-assets/restore.sh +4 -1
  11. package/templates/backend/src/scripts/core-init.ts +3 -1
  12. package/templates/storefront/README.md +35 -12
  13. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +3 -2
  14. package/templates/storefront/src/app/blog/page.tsx +46 -8
  15. package/templates/storefront/src/app/cart/page.tsx +2 -0
  16. package/templates/storefront/src/app/cart/shared/[token]/page.tsx +25 -0
  17. package/templates/storefront/src/app/cart-recovery/page.tsx +35 -0
  18. package/templates/storefront/src/app/ertekeles/page.tsx +25 -0
  19. package/templates/storefront/src/app/fiok-aktivalas/page.tsx +35 -0
  20. package/templates/storefront/src/app/knowledge-base/page.tsx +46 -8
  21. package/templates/storefront/src/app/layout.tsx +5 -2
  22. package/templates/storefront/src/app/legal/page.tsx +18 -2
  23. package/templates/storefront/src/app/page.tsx +33 -4
  24. package/templates/storefront/src/app/pages/page.tsx +43 -0
  25. package/templates/storefront/src/components/abandoned-cart-recovery.tsx +139 -0
  26. package/templates/storefront/src/components/account-activation-form.tsx +333 -0
  27. package/templates/storefront/src/components/add-to-cart.tsx +132 -2
  28. package/templates/storefront/src/components/analytics.tsx +52 -19
  29. package/templates/storefront/src/components/cart-provider.tsx +40 -3
  30. package/templates/storefront/src/components/cart-share-button.tsx +93 -0
  31. package/templates/storefront/src/components/cms-taxonomy-filters.tsx +86 -0
  32. package/templates/storefront/src/components/customer-cart-resume-gate.tsx +112 -0
  33. package/templates/storefront/src/components/fogyasztobarat-embed.tsx +32 -0
  34. package/templates/storefront/src/components/review-request-form.tsx +419 -0
  35. package/templates/storefront/src/components/shared-cart-view.tsx +257 -0
  36. package/templates/storefront/src/lib/core/abandoned-cart.ts +47 -0
  37. package/templates/storefront/src/lib/core/account-activation.ts +75 -0
  38. package/templates/storefront/src/lib/core/back-in-stock.ts +25 -0
  39. package/templates/storefront/src/lib/core/catalog.ts +12 -0
  40. package/templates/storefront/src/lib/core/checkout.ts +86 -4
  41. package/templates/storefront/src/lib/core/customer-cart-resume.ts +51 -0
  42. package/templates/storefront/src/lib/core/google-ads.ts +58 -0
  43. package/templates/storefront/src/lib/core/legal.ts +14 -0
  44. package/templates/storefront/src/lib/core/reviews.ts +37 -5
  45. package/templates/storefront/src/lib/core/shared-cart.ts +37 -0
  46. package/templates/storefront/src/lib/core/types.ts +18 -0
  47. package/templates/storefront/src/lib/storefront-routes.ts +12 -0
  48. package/templates/storefront/src/proxy.ts +11 -0
@@ -1,12 +1,37 @@
1
1
  import { CmsEntryCard } from "@/components/cms-content"
2
- import { listKnowledgeBaseEntries } from "@/lib/core/cms"
2
+ import { CmsTaxonomyFilters } from "@/components/cms-taxonomy-filters"
3
+ import { cmsConfig, listCmsTaxonomy, listKnowledgeBaseEntries } from "@/lib/core/cms"
3
4
  import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
4
- import { knowledgeBasePath, medusaLocale } from "@/lib/storefront-routes"
5
+ import { knowledgeBasePath, medusaLocale, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
5
6
 
6
- export default async function KnowledgeBasePage() {
7
- const locale = await requestStorefrontLocale()
7
+ type PageProps = {
8
+ searchParams: Promise<Record<string, string | string[] | undefined>>
9
+ }
10
+
11
+ export default async function KnowledgeBasePage({ searchParams }: PageProps) {
12
+ const [locale, params] = await Promise.all([
13
+ requestStorefrontLocale(),
14
+ searchParams,
15
+ ])
8
16
  const english = locale === "en"
9
- const { entries } = await listKnowledgeBaseEntries({ locale: medusaLocale(locale), limit: 100 }).catch(() => ({ entries: [] }))
17
+ const apiLocale = medusaLocale(locale)
18
+ const category = firstParam(params.category)
19
+ const tag = firstParam(params.tag)
20
+
21
+ const [config, taxonomy, content] = await Promise.all([
22
+ cmsConfig().catch(() => null),
23
+ listCmsTaxonomy({ locale: apiLocale }).catch(() => ({ terms: [], count: 0 })),
24
+ listKnowledgeBaseEntries({
25
+ locale: apiLocale,
26
+ category: category || undefined,
27
+ tag: tag || undefined,
28
+ limit: 100,
29
+ }).catch(() => ({ entries: [], count: 0, limit: 100, offset: 0 })),
30
+ ])
31
+
32
+ const enabledTaxonomies = new Set(config?.taxonomies || [])
33
+ const terms = taxonomy.terms.filter((term) => enabledTaxonomies.has(term.taxonomy))
34
+ const basePath = STOREFRONT_ROUTES[locale].knowledgeBase
10
35
 
11
36
  return (
12
37
  <div className="stack page-section">
@@ -15,11 +40,24 @@ export default async function KnowledgeBasePage() {
15
40
  <h1>{english ? "Knowledge base" : "Tudástár"}</h1>
16
41
  <p className="muted">{english ? "Answers, guides and practical information." : "Válaszok, útmutatók és gyakorlati információk."}</p>
17
42
  </header>
18
- {entries.length ? (
43
+
44
+ <CmsTaxonomyFilters
45
+ basePath={basePath}
46
+ terms={terms}
47
+ locale={locale}
48
+ activeCategory={category || undefined}
49
+ activeTag={tag || undefined}
50
+ />
51
+
52
+ {content.entries.length ? (
19
53
  <div className="cms-grid">
20
- {entries.map((entry) => <CmsEntryCard key={entry.id} entry={entry} href={knowledgeBasePath(locale, entry.slug)} locale={locale} />)}
54
+ {content.entries.map((entry) => <CmsEntryCard key={entry.id} entry={entry} href={knowledgeBasePath(locale, entry.slug)} locale={locale} />)}
21
55
  </div>
22
- ) : <div className="empty-state">{english ? "No knowledge-base entries yet." : "Még nincs publikált tudástár-bejegyzés."}</div>}
56
+ ) : <div className="empty-state">{english ? "No knowledge-base entries match these filters." : "A kiválasztott szűrőkkel nincs tudástár-bejegyzés."}</div>}
23
57
  </div>
24
58
  )
25
59
  }
60
+
61
+ function firstParam(value: string | string[] | undefined) {
62
+ return (Array.isArray(value) ? value[0] : value || "").trim()
63
+ }
@@ -7,6 +7,7 @@ import { AccessibilityPreferencesControl, AccessibilityPreferencesProvider } fro
7
7
  import { AnalyticsGate } from "@/components/analytics"
8
8
  import { CartProvider } from "@/components/cart-provider"
9
9
  import { ConsentBanner } from "@/components/consent-banner"
10
+ import { CustomerCartResumeGate } from "@/components/customer-cart-resume-gate"
10
11
  import { NewsletterSignup } from "@/components/newsletter-signup"
11
12
  import { StorefrontHeader } from "@/components/storefront-header"
12
13
  import { ToastProvider } from "@/components/toast-provider"
@@ -61,6 +62,7 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
61
62
  {en ? "Skip to content" : "Ugrás a tartalomhoz"}
62
63
  </a>
63
64
  <StorefrontHeader config={config} />
65
+ <CustomerCartResumeGate config={config} />
64
66
  <main id="main-content" className="shell main" tabIndex={-1}>{children}</main>
65
67
  <footer className="footer">
66
68
  <div className="shell footer-newsletter-shell">
@@ -75,6 +77,7 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
75
77
  <Link href={routes.products}>{en ? "Products" : "Termékek"}</Link>
76
78
  <Link href={routes.blog}>{en ? "Blog" : "Blog"}</Link>
77
79
  <Link href={routes.knowledgeBase}>{en ? "Knowledge base" : "Tudástár"}</Link>
80
+ <Link href={routes.cmsPages}>{en ? "Pages" : "Oldalak"}</Link>
78
81
  <Link href={routes.quoteRequest}>{en ? "Request a quote" : "Ajánlatkérés"}</Link>
79
82
  <Link href={routes.contact}>{en ? "Contact" : "Kapcsolat"}</Link>
80
83
  <Link href={routes.account}>{en ? "Account" : "Fiókom"}</Link>
@@ -83,8 +86,8 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
83
86
  <AccessibilityPreferencesControl locale={locale} />
84
87
  </div>
85
88
  </footer>
86
- <AnalyticsGate analytics={config.analytics} />
87
- <ConsentBanner enabled={config.features.analytics} />
89
+ <AnalyticsGate analytics={config.analytics} googleAds={config.marketing.google_ads} />
90
+ <ConsentBanner enabled={config.features.analytics || config.features.google_ads} />
88
91
  </CartProvider>
89
92
  </ToastProvider>
90
93
  </AccessibilityPreferencesProvider>
@@ -1,5 +1,6 @@
1
+ import { FogyasztobaratEmbed } from "@/components/fogyasztobarat-embed"
1
2
  import { getCoreConfig } from "@/lib/core/client"
2
- import { listLegalDocuments } from "@/lib/core/legal"
3
+ import { getLegalEmbed, listLegalDocuments } from "@/lib/core/legal"
3
4
  import { storefrontCopy } from "@/lib/storefront-copy"
4
5
  import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
5
6
 
@@ -9,13 +10,28 @@ export default async function LegalPage() {
9
10
  requestStorefrontLocale(),
10
11
  ])
11
12
  const copy = storefrontCopy(locale)
12
- const { documents } = await listLegalDocuments(config)
13
+ const [{ documents }, embed] = await Promise.all([
14
+ listLegalDocuments(config),
15
+ getLegalEmbed().catch(() => ({ enabled: false })),
16
+ ])
17
+ const en = locale === "en"
13
18
 
14
19
  return (
15
20
  <div className="stack page-section">
16
21
  <div className="page-heading">
17
22
  <div><p className="eyebrow">{copy.legalEyebrow}</p><h1>{copy.legalTitle}</h1><p className="muted">{copy.legalDescription}</p></div>
18
23
  </div>
24
+
25
+ {embed.enabled ? (
26
+ <section className="panel stack-sm">
27
+ <div>
28
+ <p className="eyebrow">{en ? "Consumer information" : "Fogyasztói tájékoztatás"}</p>
29
+ <h2>{en ? "Fogyasztó Barát information" : "Fogyasztó Barát tájékoztató"}</h2>
30
+ </div>
31
+ <FogyasztobaratEmbed embed={embed} />
32
+ </section>
33
+ ) : null}
34
+
19
35
  {documents.length ? (
20
36
  <div className="product-grid">
21
37
  {documents.map((document) => (
@@ -2,7 +2,12 @@ import Link from "next/link"
2
2
  import { ProductCard } from "@/components/product-card"
3
3
  import { getCoreConfig } from "@/lib/core/client"
4
4
  import { checkoutApi } from "@/lib/core/checkout"
5
- import { listCategories, listProducts } from "@/lib/core/catalog"
5
+ import {
6
+ getProductById,
7
+ listCategories,
8
+ listFeaturedProducts,
9
+ listProducts,
10
+ } from "@/lib/core/catalog"
6
11
  import { stringValue } from "@/lib/core/commerce"
7
12
  import { storefrontCopy } from "@/lib/storefront-copy"
8
13
  import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
@@ -15,10 +20,28 @@ export default async function HomePage() {
15
20
  const apiLocale = medusaLocale(locale)
16
21
  const region = await checkoutApi(config).resolveDefaultRegion().catch(() => null)
17
22
  const regionId = region ? stringValue(region.id) : undefined
18
- const [{ products }, { product_categories: categories }] = await Promise.all([
19
- listProducts({ limit: 8, order: "-created_at", regionId, locale: apiLocale }).catch(() => ({ products: [] })),
23
+ const [featuredResult, { product_categories: categories }] = await Promise.all([
24
+ listFeaturedProducts(8, apiLocale).catch(() => ({ products: [], count: 0, limit: 8 })),
20
25
  listCategories(apiLocale).catch(() => ({ product_categories: [] })),
21
26
  ])
27
+
28
+ const featuredProducts = (
29
+ await Promise.all(
30
+ featuredResult.products.map((featured) =>
31
+ getProductById(featured.id, regionId, apiLocale)
32
+ .then((result) => result.product)
33
+ .catch(() => null),
34
+ ),
35
+ )
36
+ ).filter((product): product is Record<string, unknown> => Boolean(product))
37
+
38
+ const fallbackProducts = featuredProducts.length
39
+ ? []
40
+ : await listProducts({ limit: 8, order: "-created_at", regionId, locale: apiLocale })
41
+ .then((result) => result.products)
42
+ .catch(() => [])
43
+ const products = featuredProducts.length ? featuredProducts : fallbackProducts
44
+ const showingFeatured = featuredProducts.length > 0
22
45
  const routes = STOREFRONT_ROUTES[locale]
23
46
 
24
47
  return (
@@ -45,7 +68,13 @@ export default async function HomePage() {
45
68
  ) : null}
46
69
 
47
70
  <section className="stack-sm">
48
- <div className="section-heading"><div><p className="eyebrow">{copy.newProducts}</p><h2>{copy.latestProducts}</h2></div><Link className="text-link" href={routes.products}>{copy.fullCatalog}</Link></div>
71
+ <div className="section-heading">
72
+ <div>
73
+ <p className="eyebrow">{showingFeatured ? (locale === "en" ? "Featured" : "Kiemelt") : copy.newProducts}</p>
74
+ <h2>{showingFeatured ? (locale === "en" ? "Featured products" : "Kiemelt termékek") : copy.latestProducts}</h2>
75
+ </div>
76
+ <Link className="text-link" href={routes.products}>{copy.fullCatalog}</Link>
77
+ </div>
49
78
  {products.length ? <div className="product-grid">{products.map((product) => <ProductCard key={stringValue(product.id)} product={product} config={config} locale={locale} />)}</div> : <div className="empty-state">{copy.noPublishedProducts}</div>}
50
79
  </section>
51
80
  </div>
@@ -0,0 +1,43 @@
1
+ import { CmsEntryCard } from "@/components/cms-content"
2
+ import { listCmsPages } from "@/lib/core/cms"
3
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
4
+ import { cmsPagePath, medusaLocale } from "@/lib/storefront-routes"
5
+
6
+ export default async function CmsPagesIndex() {
7
+ const locale = await requestStorefrontLocale()
8
+ const english = locale === "en"
9
+ const { entries } = await listCmsPages({
10
+ locale: medusaLocale(locale),
11
+ limit: 100,
12
+ }).catch(() => ({ entries: [], count: 0, limit: 100, offset: 0 }))
13
+
14
+ return (
15
+ <div className="stack page-section">
16
+ <header className="stack-sm">
17
+ <p className="eyebrow">{english ? "Information" : "Információ"}</p>
18
+ <h1>{english ? "Pages" : "Oldalak"}</h1>
19
+ <p className="muted">
20
+ {english
21
+ ? "Published informational pages managed by the Core CMS."
22
+ : "A Core CMS-ben kezelt, publikált tájékoztató oldalak."}
23
+ </p>
24
+ </header>
25
+ {entries.length ? (
26
+ <div className="cms-grid">
27
+ {entries.map((entry) => (
28
+ <CmsEntryCard
29
+ key={entry.id}
30
+ entry={entry}
31
+ href={cmsPagePath(locale, entry.slug)}
32
+ locale={locale}
33
+ />
34
+ ))}
35
+ </div>
36
+ ) : (
37
+ <div className="empty-state">
38
+ {english ? "No published pages yet." : "Még nincs publikált oldal."}
39
+ </div>
40
+ )}
41
+ </div>
42
+ )
43
+ }
@@ -0,0 +1,139 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { usePathname, useRouter, useSearchParams } from "next/navigation"
5
+ import { useEffect, useMemo, useRef, useState } from "react"
6
+ import { useCart } from "@/components/cart-provider"
7
+ import { abandonedCartApi } from "@/lib/core/abandoned-cart"
8
+ import { checkoutApi } from "@/lib/core/checkout"
9
+ import type { CoreConfig } from "@/lib/core/types"
10
+ import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
11
+
12
+ type RecoveryState = "checking" | "invalid" | "error"
13
+
14
+ export function AbandonedCartRecovery({ config }: { config: CoreConfig }) {
15
+ const pathname = usePathname()
16
+ const search = useSearchParams()
17
+ const router = useRouter()
18
+ const locale = localeFromPathname(pathname)
19
+ const routes = STOREFRONT_ROUTES[locale]
20
+ const recovery = useMemo(() => abandonedCartApi(config), [config])
21
+ const checkout = useMemo(() => checkoutApi(config), [config])
22
+ const { adoptCart, refresh } = useCart()
23
+ const started = useRef(false)
24
+ const [state, setState] = useState<RecoveryState>("checking")
25
+ const [reason, setReason] = useState<string | null>(null)
26
+ const [error, setError] = useState<string | null>(null)
27
+
28
+ useEffect(() => {
29
+ if (started.current) return
30
+ started.current = true
31
+
32
+ const token = search.get("token")?.trim() || ""
33
+ if (!token) {
34
+ setReason("missing")
35
+ setState("invalid")
36
+ return
37
+ }
38
+
39
+ void recovery
40
+ .recover(token)
41
+ .then(async (result) => {
42
+ if (!result.valid || !result.cart_id) {
43
+ setReason(result.reason || "invalid")
44
+ setState("invalid")
45
+ return
46
+ }
47
+
48
+ const cartId = result.cart_id
49
+ const adopted = await adoptCart(cartId)
50
+ if (!adopted) throw new Error(copy(locale).cartUnavailable)
51
+
52
+ if (result.coupon_code) {
53
+ try {
54
+ await checkout.addPromotion(cartId, result.coupon_code)
55
+ await refresh(cartId)
56
+ } catch {
57
+ // The cart itself is still recoverable if a promotion was already
58
+ // used, disabled or otherwise no longer applicable.
59
+ }
60
+ }
61
+
62
+ router.replace(routes.cart)
63
+ })
64
+ .catch((cause) => {
65
+ setError(cause instanceof Error ? cause.message : copy(locale).failed)
66
+ setState("error")
67
+ })
68
+ }, [adoptCart, checkout, locale, recovery, refresh, router, routes.cart, search])
69
+
70
+ const text = copy(locale)
71
+
72
+ if (state === "checking") {
73
+ return <div className="empty-state">{text.checking}</div>
74
+ }
75
+
76
+ if (state === "invalid") {
77
+ return (
78
+ <section className="panel stack narrow-card">
79
+ <div>
80
+ <p className="eyebrow">{text.eyebrow}</p>
81
+ <h1>{text.invalidTitle}</h1>
82
+ </div>
83
+ <p className="muted">{invalidReason(reason, locale)}</p>
84
+ <Link className="button button-large" href={routes.products}>
85
+ {text.shop}
86
+ </Link>
87
+ </section>
88
+ )
89
+ }
90
+
91
+ return (
92
+ <section className="panel stack narrow-card">
93
+ <div>
94
+ <p className="eyebrow">{text.eyebrow}</p>
95
+ <h1>{text.errorTitle}</h1>
96
+ </div>
97
+ <p className="error">{error || text.failed}</p>
98
+ <Link className="button button-large" href={routes.products}>
99
+ {text.shop}
100
+ </Link>
101
+ </section>
102
+ )
103
+ }
104
+
105
+ function invalidReason(reason: string | null, locale: "hu" | "en") {
106
+ if (locale === "en") {
107
+ if (reason === "completed") return "This cart has already been checked out."
108
+ if (reason === "empty") return "This cart is empty and can no longer be restored."
109
+ if (reason === "missing") return "The recovery link is incomplete. Open the full link from the email."
110
+ return "This cart recovery link is invalid or has expired."
111
+ }
112
+
113
+ if (reason === "completed") return "Ebből a kosárból már rendelés készült."
114
+ if (reason === "empty") return "Ez a kosár már üres, ezért nem állítható vissza."
115
+ if (reason === "missing") return "A visszaállító link hiányos. Nyisd meg az e-mailben kapott teljes hivatkozást."
116
+ return "Ez a kosár-visszaállító link érvénytelen vagy lejárt."
117
+ }
118
+
119
+ function copy(locale: "hu" | "en") {
120
+ return locale === "en"
121
+ ? {
122
+ eyebrow: "Cart recovery",
123
+ checking: "Restoring your cart…",
124
+ invalidTitle: "This recovery link is no longer available",
125
+ errorTitle: "Your cart could not be restored",
126
+ failed: "Cart recovery failed.",
127
+ cartUnavailable: "The recovered cart is no longer available.",
128
+ shop: "Continue shopping",
129
+ }
130
+ : {
131
+ eyebrow: "Kosár visszaállítása",
132
+ checking: "A kosarad visszaállítása…",
133
+ invalidTitle: "Ez a visszaállító link már nem használható",
134
+ errorTitle: "A kosár visszaállítása nem sikerült",
135
+ failed: "A kosár visszaállítása nem sikerült.",
136
+ cartUnavailable: "A visszaállított kosár már nem érhető el.",
137
+ shop: "Vásárlás folytatása",
138
+ }
139
+ }