@shopbite-de/storefront 2.1.0 → 2.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 (38) hide show
  1. package/.env.example +3 -1
  2. package/.github/workflows/build.yaml +1 -1
  3. package/.github/workflows/ci.yaml +5 -5
  4. package/CLAUDE.md +6 -3
  5. package/api-types/storeApiSchema.json +5 -0
  6. package/api-types/storeApiTypes.d.ts +2 -0
  7. package/app/components/Category/Listing.vue +53 -0
  8. package/app/components/Menu/BonCard.vue +13 -0
  9. package/app/components/Menu/FoodLabelLegend.vue +28 -0
  10. package/app/components/Navigation/MobileTop.vue +98 -9
  11. package/app/components/Product/FoodLabels.vue +39 -0
  12. package/app/components/Product/QuickView.vue +1 -0
  13. package/app/components/Sb/Sheet.vue +36 -18
  14. package/app/composables/useHomeMenuCategories.ts +6 -4
  15. package/app/composables/useMenuRootId.ts +27 -0
  16. package/app/composables/useNavigation.ts +2 -5
  17. package/app/composables/useProductQuickView.ts +4 -1
  18. package/app/composables/useTopSellers.ts +4 -1
  19. package/app/utils/menuGroups.ts +57 -0
  20. package/app/utils/menuRoot.ts +15 -0
  21. package/app/utils/product.ts +132 -0
  22. package/nuxt.config.ts +3 -0
  23. package/package.json +1 -1
  24. package/server/api/__sitemap__/urls.get.ts +1 -4
  25. package/server/api/_cache/purge.post.ts +31 -0
  26. package/server/api/listing/[categoryId].get.ts +13 -1
  27. package/server/api/product/[productId].get.ts +10 -1
  28. package/server/api/search.get.ts +11 -1
  29. package/server/routes/llms.txt.ts +3 -3
  30. package/server/utils/cachePurge.ts +62 -0
  31. package/server/utils/menuRoot.ts +25 -0
  32. package/test/nuxt/NavigationMobileTop.test.ts +90 -0
  33. package/test/nuxt/SbSheetHeader.test.ts +44 -0
  34. package/test/unit/cachePurge.spec.ts +65 -0
  35. package/test/unit/menuGroups.spec.ts +56 -0
  36. package/test/unit/menuRoot.spec.ts +21 -0
  37. package/test/unit/product.spec.ts +78 -0
  38. package/.gitignore +0 -45
@@ -0,0 +1,56 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { Schemas } from "#shopware";
3
+ import { findCategory, groupBySubsections } from "../../app/utils/menuGroups";
4
+
5
+ const category = (
6
+ id: string,
7
+ name: string,
8
+ children: Schemas["Category"][] = [],
9
+ ) =>
10
+ ({
11
+ id,
12
+ name,
13
+ translated: { name },
14
+ children,
15
+ }) as unknown as Schemas["Category"];
16
+ const product = (id: string, categoryIds: string[]) =>
17
+ ({ id, categoryIds }) as unknown as Schemas["Product"];
18
+
19
+ const nudeln = category("nudeln", "Nudeln", [
20
+ category("spaghetti", "Spaghetti"),
21
+ category("penne", "Penne", [category("penne-al-forno", "Al forno")]),
22
+ category("leer", "Leer"),
23
+ ]);
24
+
25
+ describe("groupBySubsections (#487)", () => {
26
+ it("groups dishes by sub-section in navigation order, direct dishes first", () => {
27
+ const result = groupBySubsections(
28
+ [
29
+ product("p1", ["penne"]),
30
+ product("p2", ["spaghetti"]),
31
+ product("p3", ["nudeln"]),
32
+ product("p4", ["penne-al-forno"]),
33
+ ],
34
+ nudeln.children,
35
+ );
36
+ expect(result?.direct.map((p) => p.id)).toEqual(["p3"]);
37
+ expect(
38
+ result?.groups.map((g) => [g.name, g.products.map((p) => p.id)]),
39
+ ).toEqual([
40
+ ["Spaghetti", ["p2"]],
41
+ ["Penne", ["p1", "p4"]],
42
+ ]);
43
+ });
44
+
45
+ it("is null for a section without sub-sections", () => {
46
+ expect(groupBySubsections([product("p1", ["pizza"])], [])).toBeNull();
47
+ });
48
+
49
+ it("finds a category anywhere in the tree", () => {
50
+ expect(
51
+ findCategory([category("pizza", "Pizza"), nudeln], "penne-al-forno")
52
+ ?.name,
53
+ ).toBe("Al forno");
54
+ expect(findCategory([nudeln], "x")).toBeUndefined();
55
+ });
56
+ });
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { NAVIGATION_ROOT, pickMenuRoot } from "../../app/utils/menuRoot";
3
+
4
+ const ENV = "211cf9b2d1725130a517bbadf753a43c";
5
+ const PLUGIN = "018dadb399837af3aa669c8fff4f4d6c";
6
+
7
+ describe("pickMenuRoot", () => {
8
+ it("keeps the environment variable of existing installations", () => {
9
+ expect(pickMenuRoot(ENV, PLUGIN)).toBe(ENV);
10
+ });
11
+
12
+ it("takes the plugin configuration without the variable", () => {
13
+ expect(pickMenuRoot("", PLUGIN)).toBe(PLUGIN);
14
+ expect(pickMenuRoot(undefined, PLUGIN)).toBe(PLUGIN);
15
+ });
16
+
17
+ it("falls back to the navigation root (older plugin, no answer)", () => {
18
+ expect(pickMenuRoot("", undefined)).toBe(NAVIGATION_ROOT);
19
+ expect(pickMenuRoot(undefined, null)).toBe(NAVIGATION_ROOT);
20
+ });
21
+ });
@@ -1,7 +1,12 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import type { Schemas } from "#shopware";
3
3
  import {
4
+ allergensChecked,
5
+ foodLabelCodes,
6
+ foodLabelLegend,
7
+ foodLabelText,
4
8
  getDiets,
9
+ getFoodLabels,
5
10
  getMainIngredients,
6
11
  hasYesOption,
7
12
  lineItemHoldsProduct,
@@ -102,3 +107,76 @@ describe("getDiets", () => {
102
107
  expect(getDiets([group("Hauptzutaten", ["Salami"])])).toEqual([]);
103
108
  });
104
109
  });
110
+
111
+ const labelGroup = (name: string, options: [string, string][]) =>
112
+ ({
113
+ translated: { name },
114
+ options: options.map(([code, option], i) => ({
115
+ id: `${name}${i}`,
116
+ translated: { name: option, customFields: { shopbite_code: code } },
117
+ })),
118
+ }) as unknown as Schemas["PropertyGroup"];
119
+
120
+ const withLabels = () => [
121
+ group("Hauptzutaten", ["Tomaten"]),
122
+ labelGroup("Allergene", [
123
+ ["A", "Weizen"],
124
+ ["A", "Dinkel"],
125
+ ["G", "Milch (inkl. Laktose)"],
126
+ ]),
127
+ labelGroup("Zusatzstoffe", [["2", "mit Konservierungsstoff"]]),
128
+ ];
129
+
130
+ describe("food labels (#485)", () => {
131
+ it("reads allergens and additives with their codes", () => {
132
+ const labels = getFoodLabels(withLabels());
133
+ expect(labels.allergens.map((label) => label.code)).toEqual([
134
+ "A",
135
+ "A",
136
+ "G",
137
+ ]);
138
+ expect(labels.additives).toEqual([
139
+ { code: "2", name: "mit Konservierungsstoff" },
140
+ ]);
141
+ expect(getFoodLabels(undefined)).toEqual({ allergens: [], additives: [] });
142
+ });
143
+
144
+ it("lists every code once and writes plain text", () => {
145
+ const labels = getFoodLabels(withLabels());
146
+ expect(foodLabelCodes(labels)).toEqual(["A", "G", "2"]);
147
+ expect(foodLabelText(labels)).toBe(
148
+ "Enthält: Weizen, Dinkel, Milch (inkl. Laktose). Zusatzstoffe: mit Konservierungsstoff.",
149
+ );
150
+ expect(foodLabelText({ allergens: [], additives: [] })).toBe("");
151
+ });
152
+
153
+ it("knows whether the restaurant checked the lists", () => {
154
+ expect(
155
+ allergensChecked(
156
+ product({
157
+ translated: { customFields: { shopbite_allergens_checked: true } },
158
+ } as unknown as Partial<Schemas["Product"]>),
159
+ ),
160
+ ).toBe(true);
161
+ expect(allergensChecked(product())).toBe(false);
162
+ });
163
+
164
+ it("builds a legend of the used codes, allergens by allergen name", () => {
165
+ const legend = foodLabelLegend([
166
+ product({ sortedProperties: withLabels() } as unknown as Partial<
167
+ Schemas["Product"]
168
+ >),
169
+ product({
170
+ sortedProperties: [
171
+ labelGroup("Zusatzstoffe", [["11", "koffeinhaltig"]]),
172
+ ],
173
+ } as unknown as Partial<Schemas["Product"]>),
174
+ ]);
175
+ expect(legend).toEqual([
176
+ { code: "A", name: "Glutenhaltiges Getreide" },
177
+ { code: "G", name: "Milch" },
178
+ { code: "2", name: "mit Konservierungsstoff" },
179
+ { code: "11", name: "koffeinhaltig" },
180
+ ]);
181
+ });
182
+ });
package/.gitignore DELETED
@@ -1,45 +0,0 @@
1
- # Nuxt dev/build outputs
2
- .output
3
- .data
4
- .nuxt
5
- .nitro
6
- .cache
7
- dist
8
-
9
- # Node dependencies
10
- node_modules
11
-
12
- # Logs
13
- logs
14
- *.log
15
-
16
- # Misc
17
- .DS_Store
18
- .fleet
19
- .idea
20
-
21
- # Local env files
22
- .env
23
- .env.*
24
- !.env.example
25
- coverage
26
- test-results
27
- playwright-report
28
-
29
- # Playwright
30
- /playwright-report/
31
- /blob-report/
32
- /playwright/.cache/
33
- /playwright/.auth/
34
-
35
- # Performance tooling (scripts/perf)
36
- scripts/perf/out
37
- scripts/perf/exp
38
- scripts/perf/*.pem
39
- test/visual/__snapshots__
40
- test/visual/results
41
-
42
- # build output of the layer fixture (CI job layer-build)
43
- test/layer/.nuxt
44
- test/layer/.output
45
- test/layer/.data