@shopbite-de/storefront 1.30.0 → 1.31.1

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.
@@ -65,7 +65,7 @@ jobs:
65
65
  - name: Install pnpm
66
66
  uses: pnpm/action-setup@v6
67
67
  with:
68
- version: 12.5.1
68
+ version: 12.9.1
69
69
 
70
70
  - name: Install Node.js
71
71
  uses: actions/setup-node@v7
@@ -25,7 +25,7 @@ jobs:
25
25
 
26
26
  - uses: pnpm/action-setup@v6
27
27
  with:
28
- version: 12.5.1
28
+ version: 12.9.1
29
29
 
30
30
  - uses: actions/setup-node@v7
31
31
  with:
@@ -69,7 +69,7 @@ jobs:
69
69
 
70
70
  - uses: pnpm/action-setup@v6
71
71
  with:
72
- version: 12.5.1
72
+ version: 12.9.1
73
73
 
74
74
  - uses: actions/setup-node@v7
75
75
  with:
@@ -105,7 +105,7 @@ jobs:
105
105
 
106
106
  - uses: pnpm/action-setup@v6
107
107
  with:
108
- version: 12.5.1
108
+ version: 12.9.1
109
109
 
110
110
  - uses: actions/setup-node@v7
111
111
  with:
package/CLAUDE.md CHANGED
@@ -134,6 +134,7 @@ Pages without content throw `createNotFoundError()` (`app/utils/notFound.ts`): f
134
134
  - `server/plugins/site-url.ts` makes `storeUrl` the nuxt-site-config URL, so canonical, sitemap and robots.txt share one base. Build absolute URLs with `toAbsoluteUrl(useSiteConfig().url, path)` (`app/utils/seo.ts`).
135
135
  - `app.vue` sets the title template (`site.titleTemplate`), canonical from the route, `og:url`, fallback `og:image` (`site.ogImage`) and `twitter:card`. Page titles are plain (`"Warenkorb"`), never suffixed with the shop name. Indexable pages use `usePageSeo` (`standalone: true` skips the template, home page); categories use `useCategorySeo`, which overrides the canonical with the SEO URL.
136
136
  - Shopware category SEO URLs end in `/` and 404 without it, but the sitemap module strips trailing slashes from every URL. Sitemap entries that need the slash carry `_trailingSlash: true`; `server/plugins/sitemap-trailing-slash.ts` restores it in the XML. Never normalise trailing slashes of backend SEO URLs.
137
+ - There are no category page routes: the catch-all `pages/[...all].vue` serves Markdown content pages first and otherwise the category SEO URL of the path, whatever prefix the Shopware template gives it (`/c/Pizza/`, `/speisekarte/pizza/`); paths with a file extension 404 without a backend request. It resolves the path with `useSeoUrlRoute` (category SEO URLs only, product SEO URLs 404, #289), which redirects (301) aliases to the SEO URL: other casing, toggled trailing slash, and old SEO URLs that Shopware keeps after a template or name change (`isCanonical: null`). The Store API hides old SEO URLs unless the criteria filter on `isCanonical` explicitly, so `resolvePath` never finds them; `resolveOldPath` looks them up separately, only for unknown paths.
137
138
  - `@nuxtjs/sitemap` must stay before `@nuxt/content` in `modules`; content collections need the `sitemap` schema field to appear in the sitemap.
138
139
  - The home page FAQ (`faq` in `content/index.yml`, `Home/Faq.vue`, #404) uses native `<details>`, not `UAccordion`: Reka unmounts closed panels, and the answers must be in the SSR HTML. The same items feed the `FAQPage` JSON-LD and `/llms.txt`.
139
140
  - `server/plugins/ai-crawlers.ts` adds two named robots.txt groups via the `robots:config` hook (#403): AI search/assistant bots and AI training bots (lists with sources in `server/utils/aiCrawlers.ts`), toggled by `runtimeConfig.aiCrawlers.search`/`.training`. A crawler matching a named group ignores `*`, so allowed groups repeat the `robots.disallow` paths.
@@ -70,7 +70,7 @@ function onVariantSelected(variant: Schemas["Product"]) {
70
70
  color="neutral"
71
71
  variant="ghost"
72
72
  :aria-label="canShare ? 'Teilen' : 'Link kopieren'"
73
- @click="share({ title: label })"
73
+ @click="share({ title: label, productNumber })"
74
74
  />
75
75
  </template>
76
76
  <template v-if="description" #description>
@@ -1,14 +1,18 @@
1
1
  import type { Schemas } from "#shopware";
2
2
  import { resolveSeoPath } from "~/utils/seoPath";
3
3
 
4
+ const CATEGORY_ROUTE = "frontend.navigation.page";
5
+
4
6
  /**
5
- * Resolves the current route against the backend SEO URLs. Throws a 404 if
6
- * nothing matches and redirects (301) to the SEO URL if the visited path is
7
- * only an alias of it: missing or extra trailing slash (#291) or different
8
- * casing (#244).
7
+ * Resolves the current route against the backend category SEO URLs. Throws a
8
+ * 404 if nothing matches and redirects (301) to the SEO URL if the visited
9
+ * path is only an alias of it: missing or extra trailing slash (#291),
10
+ * different casing (#244) or an old SEO URL of the same category. Product SEO
11
+ * URLs have no page (#289) and count as no match.
9
12
  */
10
13
  export async function useSeoUrlRoute() {
11
14
  const { resolvePath } = useNavigationSearch();
15
+ const { apiClient } = useShopwareContext();
12
16
  const route = useRoute();
13
17
  const routePath = route.path;
14
18
 
@@ -27,7 +31,8 @@ export async function useSeoUrlRoute() {
27
31
 
28
32
  const { match, redirectPath } = await resolveSeoPath(
29
33
  routePath,
30
- resolvePath,
34
+ resolveCategoryPath,
35
+ resolveOldPath,
31
36
  );
32
37
 
33
38
  if (!match?.foreignKey) {
@@ -52,6 +57,46 @@ export async function useSeoUrlRoute() {
52
57
  );
53
58
  }
54
59
 
60
+ async function resolveCategoryPath(
61
+ path: string,
62
+ ): Promise<Schemas["SeoUrl"] | null> {
63
+ const match = await resolvePath(path);
64
+ return match?.routeName === CATEGORY_ROUTE ? match : null;
65
+ }
66
+
67
+ /**
68
+ * The current SEO URL of the category an old SEO URL belonged to. Shopware
69
+ * keeps old SEO URLs with `isCanonical: null`; the Store API only returns
70
+ * them when the criteria filter on `isCanonical` themselves.
71
+ */
72
+ async function resolveOldPath(
73
+ path: string,
74
+ ): Promise<Schemas["SeoUrl"] | null> {
75
+ const old = await findSeoUrl([
76
+ { type: "equals", field: "seoPathInfo", value: path.substring(1) },
77
+ { type: "equals", field: "routeName", value: CATEGORY_ROUTE },
78
+ { type: "equals", field: "isCanonical", value: null },
79
+ ]);
80
+ if (!old) return null;
81
+
82
+ return findSeoUrl([
83
+ { type: "equals", field: "foreignKey", value: old.foreignKey },
84
+ { type: "equals", field: "routeName", value: CATEGORY_ROUTE },
85
+ { type: "equals", field: "languageId", value: old.languageId },
86
+ { type: "equals", field: "isCanonical", value: true },
87
+ ]);
88
+ }
89
+
90
+ async function findSeoUrl(
91
+ filter: { type: "equals"; field: string; value: string | boolean | null }[],
92
+ ): Promise<Schemas["SeoUrl"] | null> {
93
+ const { data } = await apiClient.invoke("readSeoUrl post /seo-url", {
94
+ body: { limit: 1, filter },
95
+ });
96
+
97
+ return data.elements?.[0] ?? null;
98
+ }
99
+
55
100
  return {
56
101
  seoUrl: computed(() => data.value?.seoUrl),
57
102
  };
@@ -3,21 +3,34 @@
3
3
  * has one (phones: WhatsApp, messages …), otherwise the link is copied and
4
4
  * a toast confirms it. `canShare` is false during SSR and the first render,
5
5
  * so the button's icon does not cause a hydration mismatch.
6
+ *
7
+ * With a `productNumber`, a completed share or copy is tracked in Matomo
8
+ * together with the shared path (`useTrackEvent().trackShare`).
6
9
  */
7
10
  export function useShareLink() {
8
11
  const toast = useToast();
12
+ const { trackShare } = useTrackEvent();
9
13
  const canShare = ref(false);
10
14
 
11
15
  onMounted(() => {
12
16
  canShare.value = typeof navigator.share === "function";
13
17
  });
14
18
 
15
- async function share({ title }: { title?: string } = {}) {
19
+ async function share({
20
+ title,
21
+ productNumber,
22
+ }: { title?: string; productNumber?: string } = {}) {
16
23
  const url = window.location.href;
24
+ const { pathname, search, hash } = window.location;
25
+ const track = (method: "share" | "copy") => {
26
+ if (productNumber)
27
+ trackShare(method, productNumber, pathname + search + hash);
28
+ };
17
29
 
18
30
  if (canShare.value) {
19
31
  try {
20
32
  await navigator.share({ title, url });
33
+ track("share");
21
34
  return;
22
35
  } catch (error) {
23
36
  // Closing the share sheet is no error.
@@ -29,6 +42,7 @@ export function useShareLink() {
29
42
 
30
43
  try {
31
44
  await navigator.clipboard.writeText(url);
45
+ track("copy");
32
46
  toast.add({
33
47
  title: "Link kopiert",
34
48
  icon: "i-lucide-check",
@@ -64,6 +64,24 @@ export function useTrackEvent() {
64
64
  push(["trackEvent", "Cart", "UpsellAdd", product.productNumber, quantity]);
65
65
  }
66
66
 
67
+ // A shared product link: `Share` for the native share sheet, `CopyLink`
68
+ // for the clipboard. The shared path carries the quick view configuration
69
+ // (`ohne`, `extras`, #411) and becomes the event's page URL; router.replace
70
+ // does not trigger a page view, so the last tracked URL would lack it.
71
+ function trackShare(
72
+ method: "share" | "copy",
73
+ productNumber: string,
74
+ path: string,
75
+ ) {
76
+ push(["setCustomUrl", path]);
77
+ push([
78
+ "trackEvent",
79
+ "Product",
80
+ method === "share" ? "Share" : "CopyLink",
81
+ productNumber,
82
+ ]);
83
+ }
84
+
67
85
  function trackSearch(term: string, productNumbers: string[]) {
68
86
  push(["trackSiteSearch", term, false, productNumbers.length]);
69
87
  }
@@ -75,6 +93,7 @@ export function useTrackEvent() {
75
93
  trackAddToWishlist,
76
94
  trackAddToCart,
77
95
  trackUpsellAdd,
96
+ trackShare,
78
97
  trackSearch,
79
98
  };
80
99
  }
@@ -1,14 +1,20 @@
1
- <script setup>
1
+ <script setup lang="ts">
2
+ import type { Schemas } from "#shopware";
3
+
4
+ // Every path without a file-based page: Markdown content pages first, then
5
+ // the category SEO URLs of the backend, whatever their prefix (`/c/Pizza/`,
6
+ // `/speisekarte/pizza/`).
2
7
  const route = useRoute();
3
8
  // Server route instead of queryCollection(): keeps the SQLite WASM client
4
9
  // out of client-side navigations (#314).
5
10
  const { data: page, error } = await useAsyncData(
6
11
  `landingpages-${route.path}`,
7
- () => $fetch("/api/content/page", { query: { path: route.path } }),
12
+ async () =>
13
+ (await $fetch("/api/content/page", { query: { path: route.path } })).page,
8
14
  );
9
15
 
10
16
  // A failing content server is a real error and stays fatal (logged); 4xx
11
- // means there is no such page (the route rejects over-long paths with 400).
17
+ // means there is no content page (the route rejects over-long paths with 400).
12
18
  if ((error.value?.statusCode ?? 0) >= 500) {
13
19
  throw createError({
14
20
  statusCode: 500,
@@ -17,18 +23,41 @@ if ((error.value?.statusCode ?? 0) >= 500) {
17
23
  });
18
24
  }
19
25
 
20
- if (!page.value) {
21
- throw createNotFoundError(`Page ${route.path} not found!`);
22
- }
26
+ let categoryId: Ref<string> | undefined;
27
+
28
+ if (page.value) {
29
+ usePageSeo({
30
+ title: page.value.title,
31
+ description: page.value.description,
32
+ });
33
+ } else {
34
+ // Scanner requests (`/wp-login.php`, `/.env`) are no SEO URLs; answer
35
+ // them without asking the backend.
36
+ if (/\.[a-z0-9]+$/i.test(route.path)) {
37
+ throw createNotFoundError(`Page ${route.path} not found!`);
38
+ }
23
39
 
24
- usePageSeo({
25
- title: page.value?.title,
26
- description: page.value?.description,
27
- });
40
+ const { seoUrl } = await useSeoUrlRoute();
41
+ categoryId = useNavigationContext(
42
+ seoUrl as Ref<Schemas["SeoUrl"]>,
43
+ ).foreignKey;
44
+
45
+ const { clearBreadcrumbs } = useBreadcrumbs();
46
+ onBeforeRouteLeave(() => {
47
+ clearBreadcrumbs();
48
+ });
49
+ }
28
50
  </script>
29
51
 
30
52
  <template>
31
- <UContainer>
32
- <ContentRenderer v-if="page" :value="page" class="content my-8" />
53
+ <UContainer v-if="page">
54
+ <ContentRenderer :value="page" class="content my-8" />
33
55
  </UContainer>
56
+ <div v-else-if="categoryId">
57
+ <!-- the listing layout's category bar, without switching layouts -->
58
+ <div class="sticky top-16 left-0 z-20 w-full backdrop-blur-md rounded-md">
59
+ <NavigationMobileTop />
60
+ </div>
61
+ <CategoryListing :id="categoryId" :key="categoryId" />
62
+ </div>
34
63
  </template>
@@ -13,6 +13,11 @@ type SeoPathResolution<T> = { match: T | null; redirectPath?: string };
13
13
  * - The lookup is exact on the trailing slash: `/c/Pizza/` exists, `/c/Pizza`
14
14
  * does not (#291). A miss is retried once with the slash toggled.
15
15
  * - The lookup is case-insensitive, so `/c/pizza/` resolves too (#244).
16
+ * - `resolve` only finds current (canonical) SEO URLs. Shopware keeps the
17
+ * old SEO URL of an entity when the URL template or its name changes;
18
+ * `resolveOld` maps such a path to the current SEO URL, so old links
19
+ * redirect instead of returning 404. It is asked last, with and without
20
+ * the trailing slash, only for paths `resolve` does not know.
16
21
  *
17
22
  * Whenever the match carries a SEO path that differs from the visited path,
18
23
  * `redirectPath` names it, so the visited URL always ends up canonical.
@@ -20,6 +25,7 @@ type SeoPathResolution<T> = { match: T | null; redirectPath?: string };
20
25
  export async function resolveSeoPath<T extends SeoPathMatch>(
21
26
  path: string,
22
27
  resolve: (path: string) => Promise<T | null>,
28
+ resolveOld?: (path: string) => Promise<T | null>,
23
29
  ): Promise<SeoPathResolution<T>> {
24
30
  if (path === "/") return { match: await resolve(path) };
25
31
 
@@ -30,9 +36,14 @@ export async function resolveSeoPath<T extends SeoPathMatch>(
30
36
  ? withoutTrailingSlash(path)
31
37
  : withTrailingSlash(path);
32
38
  const toggledMatch = await resolve(toggledPath);
33
- if (!toggledMatch?.seoPathInfo) return { match: null };
39
+ if (toggledMatch?.seoPathInfo) return withRedirect(path, toggledMatch);
34
40
 
35
- return withRedirect(path, toggledMatch);
41
+ if (!resolveOld) return { match: null };
42
+
43
+ const current = (await resolveOld(path)) ?? (await resolveOld(toggledPath));
44
+ if (!current?.seoPathInfo) return { match: null };
45
+
46
+ return withRedirect(path, current);
36
47
  }
37
48
 
38
49
  function withRedirect<T extends SeoPathMatch>(
package/container CHANGED
File without changes
@@ -0,0 +1,30 @@
1
+ # Old category SEO URLs redirect to the current ones
2
+
3
+ As of 2026-10-06, branch `feature/redirect-non-canonical-seo-urls`. Prompted by La Fattoria moving its category URLs from `/c/Pizza/` to `/speisekarte/pizza/` via the Shopware SEO URL template.
4
+
5
+ ## Findings (La Fattoria Store API)
6
+
7
+ - Shopware keeps the old SEO URL of an entity when the template or the entity name changes: same `foreignKey`, `isCanonical: null`. La Fattoria has 262 of them for products already (e.g. `Schnitzel-Wiener-Art/103V` next to the canonical `Schnitzel-Wiener-Art/103`).
8
+ - The Store API `/seo-url` route adds `isCanonical = true` to the criteria unless they contain an `equals` filter on `isCanonical` at top level (a nested `multi` filter does not count). A lookup by `seoPathInfo` alone therefore never finds an old URL: before this change, every old category URL returned 404 after a template change.
9
+
10
+ ## Change
11
+
12
+ - `resolveSeoPath` takes an optional `resolveOld`. It is asked only after the canonical lookup missed with and without the trailing slash, again for both variants, so known paths cost no extra request.
13
+ - `useSeoUrlRoute` implements it as two Store API calls: the old record (`seoPathInfo` + `isCanonical: null`), then the canonical record of the same `foreignKey`, `routeName` and `languageId`. A match redirects with 301 (query kept); an old URL without a current one (deleted category) stays 404.
14
+ - Up to four lookups for unknown paths below `/c/` and `/speisekarte/` (previously two). Other unknown paths go to the content catch-all and are unaffected.
15
+
16
+ ## One catch-all instead of `/c/` and `/speisekarte/`
17
+
18
+ The category pages `pages/c/[...all].vue` and `pages/speisekarte/[...all].vue` were identical and only existed for the two URL prefixes in use. `pages/[...all].vue` now serves both kinds of pages, so the prefix is up to the Shopware SEO URL template:
19
+
20
+ 1. Markdown content page for the path (local, cheap), as before.
21
+ 2. Otherwise `useSeoUrlRoute`, restricted to `frontend.navigation.page`: product SEO URLs have no page (#289) and stay 404, also as old URLs. Technical `/navigation/<id>` paths now redirect to their SEO URL (planned in #244).
22
+ 3. Paths with a file extension (`/wp-login.php`, `/.env`) 404 before step 2, so scanner traffic causes no Store API requests.
23
+
24
+ The category bar of the `listing` layout is rendered by the page itself (same markup) instead of switching layouts per result, which would need `setPageLayout` during SSR (hydration warning in Nuxt). A category page now costs one extra request to `/api/content/page`.
25
+
26
+ Checked against the La Fattoria backend (dev server): `/c/Pizza/` 200 with 29 products, `/c/pizza` and `/navigation/<pizza id>` 301 to `/c/Pizza/`, `/agb` 200, `/c/Unbekannt/`, `/Schnitzel-Wiener-Art/103`, `/wp-login.php`, `/.env` 404. Client-side navigation content → category → category → alias → content → back renders the right page each time. The hydration warnings on a category page (`NavigationDesktopLeft`, `CategoryListing`) are the same with the old pages.
27
+
28
+ ## Verification
29
+
30
+ Unit tests (`seoPath.spec.ts`, `useSeoUrlRoute.test.ts`), typecheck, ESLint, Prettier. Both queries checked against the La Fattoria Store API with existing old product URLs: the `seoPathInfo` lookup without an `isCanonical` filter returns nothing, with `isCanonical: null` it returns the old record, and the canonical lookup returns `Schnitzel-Wiener-Art/103`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "1.30.0",
3
+ "version": "1.31.1",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -24,7 +24,7 @@
24
24
  "@iconify-json/simple-icons": "^1.2.97",
25
25
  "@nuxt/content": "3.16.1",
26
26
  "@nuxt/image": "^2.1.0",
27
- "@nuxt/scripts": "1.3.9",
27
+ "@nuxt/scripts": "1.3.12",
28
28
  "@nuxt/ui": "^4.11.2",
29
29
  "@nuxtjs/robots": "^6.2.3",
30
30
  "@nuxtjs/sitemap": "^8.5.1",
@@ -55,7 +55,7 @@
55
55
  "@typescript-eslint/eslint-plugin": "^8.70.1",
56
56
  "@typescript-eslint/parser": "^8.70.1",
57
57
  "@vitejs/plugin-vue": "^6.0.9",
58
- "@vitest/ui": "5.0.1",
58
+ "@vitest/ui": "5.0.3",
59
59
  "@vue/compiler-dom": "^3.5.43",
60
60
  "@vue/server-renderer": "^3.5.43",
61
61
  "@vue/test-utils": "^2.5.1",
@@ -69,7 +69,7 @@
69
69
  "tailwindcss": "^4.3.3",
70
70
  "typescript": "^6.0.3",
71
71
  "vitest": "^5.0.1",
72
- "vue-tsc": "3.3.11"
72
+ "vue-tsc": "3.3.12"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "nuxt build",
File without changes
@@ -1,7 +1,8 @@
1
1
  import { queryCollection } from "@nuxt/content/server";
2
2
 
3
- // Landing page (content/*.md) by route path; see home.get.ts for why the
4
- // pages do not query the collection in the browser (#314).
3
+ // Landing page (content/*.md) by route path, `page: null` if there is none;
4
+ // see home.get.ts for why the pages do not query the collection in the
5
+ // browser (#314).
5
6
  export default defineEventHandler(async (event) => {
6
7
  const { path } = getQuery(event);
7
8
 
@@ -9,14 +10,10 @@ export default defineEventHandler(async (event) => {
9
10
  throw createError({ statusCode: 400, statusMessage: "Invalid path" });
10
11
  }
11
12
 
13
+ // No content page is a regular answer, not an error: the catch-all asks
14
+ // here first for every category page, and a 404 would show up as a failed
15
+ // request in the browser console and the RUM data on each navigation.
12
16
  const page = await queryCollection(event, "landingpages").path(path).first();
13
17
 
14
- if (!page) {
15
- throw createError({
16
- statusCode: 404,
17
- statusMessage: `Page ${path} not found!`,
18
- });
19
- }
20
-
21
- return page;
18
+ return { page: page ?? null };
22
19
  });
@@ -3,16 +3,23 @@ import { mockNuxtImport } from "@nuxt/test-utils/runtime";
3
3
  import { ref } from "vue";
4
4
  import { useSeoUrlRoute } from "~/composables/useSeoUrlRoute";
5
5
 
6
- const { mockResolvePath, mockNavigateTo, routeState } = vi.hoisted(() => ({
7
- mockResolvePath: vi.fn(),
8
- mockNavigateTo: vi.fn(),
9
- routeState: { path: "/c/Pizza/", query: {} as Record<string, string> },
10
- }));
6
+ const { mockResolvePath, mockInvoke, mockNavigateTo, routeState } = vi.hoisted(
7
+ () => ({
8
+ mockResolvePath: vi.fn(),
9
+ mockInvoke: vi.fn(),
10
+ mockNavigateTo: vi.fn(),
11
+ routeState: { path: "/c/Pizza/", query: {} as Record<string, string> },
12
+ }),
13
+ );
11
14
 
12
15
  mockNuxtImport("useNavigationSearch", () => () => ({
13
16
  resolvePath: mockResolvePath,
14
17
  }));
15
18
 
19
+ mockNuxtImport("useShopwareContext", () => () => ({
20
+ apiClient: { invoke: mockInvoke },
21
+ }));
22
+
16
23
  mockNuxtImport("useRoute", () => () => routeState);
17
24
 
18
25
  mockNuxtImport("navigateTo", () => mockNavigateTo);
@@ -48,6 +55,8 @@ describe("useSeoUrlRoute", () => {
48
55
  mockResolvePath.mockImplementation(async (path: string) =>
49
56
  path.toLowerCase() === "/c/pizza/" ? pizza : null,
50
57
  );
58
+ // no old SEO URLs unless a test says so
59
+ mockInvoke.mockResolvedValue({ data: { elements: [] } });
51
60
  });
52
61
 
53
62
  it("resolves the route and does not redirect on the SEO URL", async () => {
@@ -71,6 +80,56 @@ describe("useSeoUrlRoute", () => {
71
80
  );
72
81
  });
73
82
 
83
+ it("redirects permanently from an old SEO URL to the current one", async () => {
84
+ routeState.path = "/c/Pizzen/";
85
+ const oldPizza = {
86
+ ...pizza,
87
+ seoPathInfo: "c/Pizzen/",
88
+ languageId: "lang-de",
89
+ isCanonical: null,
90
+ };
91
+ mockInvoke
92
+ .mockResolvedValueOnce({ data: { elements: [oldPizza] } })
93
+ .mockResolvedValueOnce({ data: { elements: [pizza] } });
94
+
95
+ const { seoUrl } = await useSeoUrlRoute();
96
+
97
+ expect(mockInvoke).toHaveBeenNthCalledWith(1, "readSeoUrl post /seo-url", {
98
+ body: {
99
+ limit: 1,
100
+ filter: [
101
+ { type: "equals", field: "seoPathInfo", value: "c/Pizzen/" },
102
+ {
103
+ type: "equals",
104
+ field: "routeName",
105
+ value: "frontend.navigation.page",
106
+ },
107
+ { type: "equals", field: "isCanonical", value: null },
108
+ ],
109
+ },
110
+ });
111
+ expect(mockInvoke).toHaveBeenNthCalledWith(2, "readSeoUrl post /seo-url", {
112
+ body: {
113
+ limit: 1,
114
+ filter: [
115
+ { type: "equals", field: "foreignKey", value: "cat-pizza" },
116
+ {
117
+ type: "equals",
118
+ field: "routeName",
119
+ value: "frontend.navigation.page",
120
+ },
121
+ { type: "equals", field: "languageId", value: "lang-de" },
122
+ { type: "equals", field: "isCanonical", value: true },
123
+ ],
124
+ },
125
+ });
126
+ expect(seoUrl.value).toEqual(pizza);
127
+ expect(mockNavigateTo).toHaveBeenCalledWith(
128
+ { path: "/c/Pizza/", query: {} },
129
+ { redirectCode: 301, replace: true },
130
+ );
131
+ });
132
+
74
133
  it("throws a 404 when the path cannot be resolved", async () => {
75
134
  routeState.path = "/c/Unbekannt/";
76
135
 
@@ -78,6 +137,30 @@ describe("useSeoUrlRoute", () => {
78
137
  expect(mockNavigateTo).not.toHaveBeenCalled();
79
138
  });
80
139
 
140
+ it("throws a 404 for a product SEO URL (no product pages)", async () => {
141
+ routeState.path = "/Pizza-Margherita/21";
142
+ mockResolvePath.mockResolvedValue({
143
+ seoPathInfo: "Pizza-Margherita/21",
144
+ foreignKey: "p21",
145
+ routeName: "frontend.detail.page",
146
+ });
147
+
148
+ await expect(useSeoUrlRoute()).rejects.toMatchObject({ statusCode: 404 });
149
+ expect(mockNavigateTo).not.toHaveBeenCalled();
150
+ });
151
+
152
+ it("throws a 404 when an old SEO URL has no current one", async () => {
153
+ routeState.path = "/c/Geloescht/";
154
+ mockInvoke
155
+ .mockResolvedValueOnce({
156
+ data: { elements: [{ ...pizza, seoPathInfo: "c/Geloescht/" }] },
157
+ })
158
+ .mockResolvedValue({ data: { elements: [] } });
159
+
160
+ await expect(useSeoUrlRoute()).rejects.toMatchObject({ statusCode: 404 });
161
+ expect(mockNavigateTo).not.toHaveBeenCalled();
162
+ });
163
+
81
164
  it("uses the history state from client-side navigation without a request", async () => {
82
165
  history.replaceState(
83
166
  { routeName: "frontend.navigation.page", foreignKey: "cat-from-link" },
@@ -2,8 +2,15 @@ import { afterEach, describe, expect, it, vi } from "vitest";
2
2
  import { mountSuspended, mockNuxtImport } from "@nuxt/test-utils/runtime";
3
3
  import { defineComponent, h } from "vue";
4
4
 
5
- const { add } = vi.hoisted(() => ({ add: vi.fn() }));
5
+ const { add, trackShare } = vi.hoisted(() => ({
6
+ add: vi.fn(),
7
+ trackShare: vi.fn(),
8
+ }));
6
9
  mockNuxtImport("useToast", () => () => ({ add }));
10
+ mockNuxtImport("useTrackEvent", () => () => ({ trackShare }));
11
+
12
+ const sharedPath = () =>
13
+ window.location.pathname + window.location.search + window.location.hash;
7
14
 
8
15
  async function mountShare() {
9
16
  let api!: ReturnType<typeof useShareLink>;
@@ -22,6 +29,7 @@ describe("useShareLink", () => {
22
29
  afterEach(() => {
23
30
  vi.unstubAllGlobals();
24
31
  add.mockReset();
32
+ trackShare.mockReset();
25
33
  });
26
34
 
27
35
  it("uses the native share sheet when available", async () => {
@@ -30,13 +38,14 @@ describe("useShareLink", () => {
30
38
 
31
39
  const api = await mountShare();
32
40
  expect(api.canShare.value).toBe(true);
33
- await api.share({ title: "Pizza" });
41
+ await api.share({ title: "Pizza", productNumber: "P1" });
34
42
 
35
43
  expect(share).toHaveBeenCalledWith({
36
44
  title: "Pizza",
37
45
  url: window.location.href,
38
46
  });
39
47
  expect(add).not.toHaveBeenCalled();
48
+ expect(trackShare).toHaveBeenCalledWith("share", "P1", sharedPath());
40
49
  });
41
50
 
42
51
  it("copies the link without share sheet", async () => {
@@ -48,12 +57,29 @@ describe("useShareLink", () => {
48
57
  });
49
58
 
50
59
  const api = await mountShare();
51
- await api.share();
60
+ await api.share({ productNumber: "P1" });
52
61
 
53
62
  expect(writeText).toHaveBeenCalledWith(window.location.href);
54
63
  expect(add).toHaveBeenCalledWith(
55
64
  expect.objectContaining({ title: "Link kopiert" }),
56
65
  );
66
+ expect(trackShare).toHaveBeenCalledWith("copy", "P1", sharedPath());
67
+ });
68
+
69
+ it("does not track without product number or when copying fails", async () => {
70
+ const writeText = vi.fn().mockResolvedValue(undefined);
71
+ vi.stubGlobal("navigator", {
72
+ ...navigator,
73
+ share: undefined,
74
+ clipboard: { writeText },
75
+ });
76
+
77
+ const api = await mountShare();
78
+ await api.share();
79
+ writeText.mockRejectedValue(new Error("denied"));
80
+ await api.share({ productNumber: "P1" });
81
+
82
+ expect(trackShare).not.toHaveBeenCalled();
57
83
  });
58
84
 
59
85
  it("does nothing when the share sheet is closed", async () => {
@@ -68,9 +94,10 @@ describe("useShareLink", () => {
68
94
  });
69
95
 
70
96
  const api = await mountShare();
71
- await api.share();
97
+ await api.share({ productNumber: "P1" });
72
98
 
73
99
  expect(writeText).not.toHaveBeenCalled();
74
100
  expect(add).not.toHaveBeenCalled();
101
+ expect(trackShare).not.toHaveBeenCalled();
75
102
  });
76
103
  });
@@ -111,6 +111,22 @@ describe("useTrackEvent", () => {
111
111
  ]);
112
112
  });
113
113
 
114
+ it("tracks a shared product with the shared path as page URL", () => {
115
+ setMatomoConfig("https://analytics.example.com/", 3);
116
+ const path = "/Speisekarte/Pizza/?produkt=P1&ohne=Zwiebeln&extras=E1";
117
+
118
+ const { trackShare } = useTrackEvent();
119
+ trackShare("share", "P1", path);
120
+ trackShare("copy", "P1", path);
121
+
122
+ expect(matomoWindow._paq).toEqual([
123
+ ["setCustomUrl", path],
124
+ ["trackEvent", "Product", "Share", "P1"],
125
+ ["setCustomUrl", path],
126
+ ["trackEvent", "Product", "CopyLink", "P1"],
127
+ ]);
128
+ });
129
+
114
130
  it("appends to an existing _paq queue", () => {
115
131
  setMatomoConfig("https://analytics.example.com/", 3);
116
132
  matomoWindow._paq = [["setSiteId", "3"]];
@@ -0,0 +1,74 @@
1
+ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ type Handler = (event: { query: Record<string, unknown> }) => Promise<unknown>;
4
+
5
+ const { mockFirst, mockPath, mockQueryCollection } = vi.hoisted(() => {
6
+ const mockFirst = vi.fn();
7
+ const mockPath = vi.fn(() => ({ first: mockFirst }));
8
+ const mockQueryCollection = vi.fn(() => ({ path: mockPath }));
9
+ return { mockFirst, mockPath, mockQueryCollection };
10
+ });
11
+
12
+ vi.mock("@nuxt/content/server", () => ({
13
+ queryCollection: mockQueryCollection,
14
+ }));
15
+
16
+ // Nitro auto-imports of the route, reduced to what it uses.
17
+ vi.stubGlobal("defineEventHandler", (handler: Handler) => handler);
18
+ vi.stubGlobal(
19
+ "getQuery",
20
+ (event: { query: Record<string, unknown> }) => event.query,
21
+ );
22
+ vi.stubGlobal(
23
+ "createError",
24
+ (input: { statusCode: number; statusMessage: string }) =>
25
+ Object.assign(new Error(input.statusMessage), input),
26
+ );
27
+
28
+ let handler: Handler;
29
+
30
+ beforeAll(async () => {
31
+ // With the stubs above the default export is the plain handler function.
32
+ handler = (await import("../../server/api/content/page.get"))
33
+ .default as unknown as Handler;
34
+ });
35
+
36
+ beforeEach(() => {
37
+ vi.clearAllMocks();
38
+ });
39
+
40
+ describe("GET /api/content/page", () => {
41
+ it("returns the content page of the path", async () => {
42
+ const page = { path: "/agb", title: "AGB" };
43
+ mockFirst.mockResolvedValue(page);
44
+
45
+ await expect(handler({ query: { path: "/agb" } })).resolves.toEqual({
46
+ page,
47
+ });
48
+ expect(mockQueryCollection).toHaveBeenCalledWith(
49
+ expect.anything(),
50
+ "landingpages",
51
+ );
52
+ expect(mockPath).toHaveBeenCalledWith("/agb");
53
+ });
54
+
55
+ it("answers page: null instead of a 404 when there is no content page", async () => {
56
+ mockFirst.mockResolvedValue(null);
57
+
58
+ await expect(
59
+ handler({ query: { path: "/speisekarte/pizza/" } }),
60
+ ).resolves.toEqual({ page: null });
61
+ });
62
+
63
+ it.each([
64
+ ["missing", undefined],
65
+ ["relative", "agb"],
66
+ ["too long", `/${"x".repeat(256)}`],
67
+ ["repeated", ["/agb", "/impressum"]],
68
+ ])("rejects a %s path with 400", async (_label, path) => {
69
+ await expect(handler({ query: { path } })).rejects.toMatchObject({
70
+ statusCode: 400,
71
+ });
72
+ expect(mockQueryCollection).not.toHaveBeenCalled();
73
+ });
74
+ });
@@ -105,6 +105,51 @@ describe("resolveSeoPath", () => {
105
105
  });
106
106
  });
107
107
 
108
+ describe("old SEO URLs", () => {
109
+ const newPizza = { seoPathInfo: "speisekarte/pizza/", foreignKey: "pizza" };
110
+ const resolve = resolverFor({ "/speisekarte/pizza/": newPizza });
111
+
112
+ it("redirects an old SEO URL to the current one", async () => {
113
+ const resolveOld = resolverFor({ "/c/Pizza/": newPizza });
114
+
115
+ await expect(
116
+ resolveSeoPath("/c/Pizza/", resolve, resolveOld),
117
+ ).resolves.toEqual({
118
+ match: newPizza,
119
+ redirectPath: "/speisekarte/pizza/",
120
+ });
121
+ expect(resolveOld).toHaveBeenCalledTimes(1);
122
+ });
123
+
124
+ it("redirects an old SEO URL without its trailing slash", async () => {
125
+ const resolveOld = resolverFor({ "/c/Pizza/": newPizza });
126
+
127
+ await expect(
128
+ resolveSeoPath("/c/pizza", resolve, resolveOld),
129
+ ).resolves.toEqual({
130
+ match: newPizza,
131
+ redirectPath: "/speisekarte/pizza/",
132
+ });
133
+ expect(resolveOld).toHaveBeenLastCalledWith("/c/pizza/");
134
+ });
135
+
136
+ it("asks for old SEO URLs only when the path is unknown", async () => {
137
+ const resolveOld = vi.fn();
138
+
139
+ await resolveSeoPath("/speisekarte/pizza", resolve, resolveOld);
140
+ expect(resolveOld).not.toHaveBeenCalled();
141
+ });
142
+
143
+ it("returns no match for paths that never were SEO URLs", async () => {
144
+ const resolveOld = resolverFor({});
145
+
146
+ await expect(
147
+ resolveSeoPath("/c/Unbekannt/", resolve, resolveOld),
148
+ ).resolves.toEqual({ match: null });
149
+ expect(resolveOld).toHaveBeenCalledTimes(2);
150
+ });
151
+ });
152
+
108
153
  it("does not toggle the root path", async () => {
109
154
  const resolve = resolverFor({});
110
155
 
@@ -1,20 +0,0 @@
1
- <script setup lang="ts">
2
- import type { Schemas } from "#shopware";
3
-
4
- definePageMeta({
5
- layout: "listing",
6
- });
7
-
8
- const { clearBreadcrumbs } = useBreadcrumbs();
9
- const { seoUrl } = await useSeoUrlRoute();
10
-
11
- const { foreignKey } = useNavigationContext(seoUrl as Ref<Schemas["SeoUrl"]>);
12
-
13
- onBeforeRouteLeave(() => {
14
- clearBreadcrumbs();
15
- });
16
- </script>
17
-
18
- <template>
19
- <CategoryListing v-if="foreignKey" :id="foreignKey" :key="foreignKey" />
20
- </template>
@@ -1,20 +0,0 @@
1
- <script setup lang="ts">
2
- import type { Schemas } from "#shopware";
3
-
4
- definePageMeta({
5
- layout: "listing",
6
- });
7
-
8
- const { clearBreadcrumbs } = useBreadcrumbs();
9
- const { seoUrl } = await useSeoUrlRoute();
10
-
11
- const { foreignKey } = useNavigationContext(seoUrl as Ref<Schemas["SeoUrl"]>);
12
-
13
- onBeforeRouteLeave(() => {
14
- clearBreadcrumbs();
15
- });
16
- </script>
17
-
18
- <template>
19
- <CategoryListing v-if="foreignKey" :id="foreignKey" :key="foreignKey" />
20
- </template>