@shopbite-de/storefront 2.2.0 → 2.2.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.
package/CLAUDE.md CHANGED
@@ -102,7 +102,7 @@ The storefront reads plain Shopware entities with fixed names; seed data must ma
102
102
  - **Property groups:** `Hauptzutaten` (ingredients on the card, deselectable on the detail page, removed ones are appended to the cart label with "-"), `Vegetarisch` and `Vegan` with the option `Ja` (diet badges), `Küche` (kitchen badge). Filterable groups appear as listing filters.
103
103
  - **Extras:** product cross-sellings of type `productList`; the cross-selling name is the label ("Extras", "Beilagen"), the assigned products need a price and sales-channel visibility but no category. In the quick view each cross-selling is a collapsible checkbox list that shows 6 entries of a long list and a search field above 15 entries (`Product/CrossSelling.vue`). Selected extras are sent as children of a `container` line item (`useAddToCart.ts`, handled by the ShopBite plugin). The bon card opens the quick view sheet (`Product/QuickView.vue`), whose state is the `produkt` query parameter (product number) via `useProductQuickView` (#325). That deep link is the product URL (#289, no product pages): `productDeepLink()` (`app/utils/productUrl.ts`) takes the product SEO URL when it carries `?produkt=` (the ShopBite plugin sets the template, shopware-plugin#28; the number must be `|url_encode|raw` in the template, the SEO escaper slugifies `ß`) and otherwise builds it from the category SEO URL. The card name is a stretched link to it (a plain click stays in place); a number not in the list (a variant) is loaded and opens with its options selected. The quick view keeps its configuration in the URL (#411): `ohne` (deselected ingredients by name) and `extras` (extras by product number), written live with `router.replace` by `useQuickViewConfiguration`; a variant switch updates `produkt` without swapping the sheet's product (numbers the sheet switched to itself are pinned). The share button (`useShareLink`) uses the Web Share API, else copies the link.
104
104
  - **Custom fields on products:** `shopbite_receipt_print_type` (`number` prints the menu number on the receipt, `label` prints the name) and `shopbite_delivery_time_factor` (int) and `shopbite_cart_upsell` (bool, suggests the product on the order confirmation step `/bestellung/bestaetigen` via `useCartUpsell`; variant parents are never suggested, a flag on a parent applies to its variants), all from the ShopBite plugin.
105
- - **Allergens and additives (#485):** property groups `Allergene` and `Zusatzstoffe` from the ShopBite plugin (shopware-plugin#36, maintained in the backoffice), code in the option custom field `shopbite_code` (A-R, 1-12), product custom field `shopbite_allergens_checked` = lists complete. `getFoodLabels()`/`foodLabelCodes()`/`foodLabelText()`/`foodLabelLegend()` in `app/utils/product.ts`. The bon card shows the codes (names for screen readers), `Menu/FoodLabelLegend.vue` explains the codes used in the list (native `<details>`), `Product/FoodLabels.vue` writes them out in the sheet; without `shopbite_allergens_checked` the sheet points to the restaurant's phone and never says "no allergens". **Includes filter `translated` too:** custom fields only come back when `customFields` is in the `product` and `property_group_option` includes (listing, search, product route, quick view, top sellers).
105
+ - **Allergens and additives (#485):** property groups `Allergene` and `Zusatzstoffe` from the ShopBite plugin (shopware-plugin#36, maintained in the backoffice), code in the option custom field `shopbite_code` (A-R, 1-12), product custom field `shopbite_allergens_checked` = lists complete. `getFoodLabels()`/`foodLabelText()`/`allergensChecked()` in `app/utils/product.ts`. Shown only on request (#500): the bon card and the list show nothing, `Product/FoodLabels.vue` is an info button in the sheet's toolbar that opens a Reka popover (not teleported, so the dialog's focus trap holds) with the names written out; without `shopbite_allergens_checked` the sheet points to the restaurant's phone and never says "no allergens". **Includes filter `translated` too:** custom fields only come back when `customFields` is in the `product` and `property_group_option` includes (listing, search, product route, quick view, top sellers).
106
106
  - **Variants:** standard configurator settings (`Product/Configurator.vue`); `server/api/product/variant.get.ts` resolves a variant by option ids.
107
107
 
108
108
  ### Server routes
@@ -275,7 +275,6 @@ async function openFilterDrawer() {
275
275
  @select="quickView.show"
276
276
  />
277
277
  </div>
278
- <MenuFoodLabelLegend v-if="!showSkeleton" :products="elements" />
279
278
  <LazyProductQuickView
280
279
  v-if="quickView.mounted.value"
281
280
  v-model:open="quickView.open.value"
@@ -35,11 +35,6 @@ const diets = computed(() =>
35
35
  diet === "vegan" ? "Vegan" : "Vegetarisch",
36
36
  ),
37
37
  );
38
- // Allergen and additive codes (#485); the legend below the list explains
39
- // them, screen readers get the names.
40
- const foodLabels = computed(() => getFoodLabels(sortedProperties.value));
41
- const foodCodes = computed(() => foodLabelCodes(foodLabels.value));
42
- const foodText = computed(() => foodLabelText(foodLabels.value));
43
38
  // Read before the name; the strip with the number is aria-hidden. Built in
44
39
  // script: a trailing space in the template would be condensed away.
45
40
  // The strip has a fixed width so the cards line up (#441); menu numbers
@@ -156,14 +151,6 @@ function onLinkClick(event: MouseEvent) {
156
151
  <p v-if="ingredients" class="text-sm leading-snug text-sb-ink-muted">
157
152
  {{ ingredients }}
158
153
  </p>
159
- <p
160
- v-if="foodCodes.length"
161
- class="text-xs tracking-wide text-sb-ink-muted tabular-nums"
162
- data-testid="food-codes"
163
- >
164
- <span aria-hidden="true">{{ foodCodes.join(", ") }}</span
165
- ><span class="sr-only">{{ foodText }}</span>
166
- </p>
167
154
  <div class="mt-auto flex items-center justify-between pt-1.5">
168
155
  <span class="text-base font-bold tabular-nums">{{ price }}</span>
169
156
  <span
@@ -1,10 +1,19 @@
1
1
  <script setup lang="ts">
2
2
  import type { Schemas } from "#shopware";
3
+ import {
4
+ PopoverContent,
5
+ PopoverPortal,
6
+ PopoverRoot,
7
+ PopoverTrigger,
8
+ } from "reka-ui";
3
9
 
4
10
  /**
5
- * Allergens and additives in the product sheet (#485). Without the
6
- * restaurant's confirmation an empty list is "not entered yet", so the
7
- * sheet never claims "free of allergens" then and points to the phone.
11
+ * Allergens and additives of a dish behind an info button in the sheet's
12
+ * toolbar (#500): reachable before ordering, shown only to guests who look
13
+ * for them. Without the restaurant's confirmation an empty list is "not
14
+ * entered yet", so it never claims "free of allergens" then and points to
15
+ * the phone (#485). The content stays inside the sheet (no teleport), so
16
+ * the dialog's focus trap keeps working.
8
17
  */
9
18
  const props = defineProps<{ product: Schemas["Product"] }>();
10
19
 
@@ -19,21 +28,39 @@ const text = computed(() => foodLabelText(labels.value));
19
28
  </script>
20
29
 
21
30
  <template>
22
- <p class="text-sm text-sb-ink-muted" data-testid="food-labels">
23
- <template v-if="text">{{ text }}</template>
24
- <template v-else-if="checked"
25
- >Ohne kennzeichnungspflichtige Allergene und Zusatzstoffe.</template
26
- >
27
- <template v-else>
28
- Angaben zu Allergenen und Zusatzstoffen erhalten Sie im
29
- Restaurant<template v-if="site.telephone"
30
- >:
31
- <a
32
- :href="toTelHref(site.telephone)"
33
- class="font-semibold text-sb-ink underline underline-offset-4"
34
- >{{ site.telephone }}</a
35
- ></template
36
- >.
37
- </template>
38
- </p>
31
+ <PopoverRoot>
32
+ <PopoverTrigger as-child>
33
+ <SbIconButton label="Allergene und Zusatzstoffe">
34
+ <SbIcon name="info" />
35
+ </SbIconButton>
36
+ </PopoverTrigger>
37
+ <PopoverPortal disabled>
38
+ <PopoverContent
39
+ side="bottom"
40
+ align="end"
41
+ :side-offset="6"
42
+ :collision-padding="16"
43
+ class="z-50 w-72 max-w-[calc(100vw-32px)] rounded-sb-card border border-sb-line bg-sb-surface p-4 text-sm text-sb-ink shadow-lg focus-visible:outline-none"
44
+ data-testid="food-labels"
45
+ >
46
+ <p class="mb-1 font-semibold">Allergene und Zusatzstoffe</p>
47
+ <p class="text-sb-ink-muted">
48
+ <template v-if="text">{{ text }}</template>
49
+ <template v-else-if="checked"
50
+ >Ohne kennzeichnungspflichtige Allergene und Zusatzstoffe.</template
51
+ >
52
+ <template v-else>
53
+ Angaben erhalten Sie im Restaurant<template v-if="site.telephone"
54
+ >:
55
+ <a
56
+ :href="toTelHref(site.telephone)"
57
+ class="font-semibold text-sb-ink underline underline-offset-4"
58
+ >{{ site.telephone }}</a
59
+ ></template
60
+ >.
61
+ </template>
62
+ </p>
63
+ </PopoverContent>
64
+ </PopoverPortal>
65
+ </PopoverRoot>
39
66
  </template>
@@ -89,11 +89,11 @@ function onVariantSelected(variant: Schemas["Product"]) {
89
89
  >{{ diets.join(" · ") }}{{ description ? " · " : "" }}</span
90
90
  >{{ description }}
91
91
  </DialogDescription>
92
- <ProductFoodLabels v-if="product" :product="product" />
93
92
  </div>
94
93
  </div>
95
94
  </template>
96
95
  <template #actions>
96
+ <ProductFoodLabels v-if="product" :product="product" />
97
97
  <WishlistSaveButton :selection="selection" :name="label" />
98
98
  <SbIconButton
99
99
  :label="canShare ? 'Teilen' : 'Link kopieren'"
@@ -16,7 +16,8 @@ type IconName =
16
16
  | "phone"
17
17
  | "heart"
18
18
  | "bag"
19
- | "chevron-up";
19
+ | "chevron-up"
20
+ | "info";
20
21
 
21
22
  withDefaults(
22
23
  defineProps<{ name: IconName; size?: number; filled?: boolean }>(),
@@ -38,6 +39,7 @@ const PATHS: Record<IconName, string[]> = {
38
39
  "M16 10a4 4 0 0 1-8 0",
39
40
  ],
40
41
  "chevron-up": ["m18 15-6-6-6 6"],
42
+ info: ["M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z", "M12 16v-4", "M12 8h.01"],
41
43
  heart: [
42
44
  "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",
43
45
  ],
@@ -72,27 +72,6 @@ export function getDiets(
72
72
  const ALLERGEN_GROUP = "Allergene";
73
73
  const ADDITIVE_GROUP = "Zusatzstoffe";
74
74
 
75
- /**
76
- * Names of the allergen codes for the legend. The options name the cereal
77
- * or nut (LMIV Annex II), the legend names the allergen.
78
- */
79
- export const ALLERGEN_CODE_NAMES: Record<string, string> = {
80
- A: "Glutenhaltiges Getreide",
81
- B: "Krebstiere",
82
- C: "Eier",
83
- D: "Fisch",
84
- E: "Erdnüsse",
85
- F: "Soja",
86
- G: "Milch",
87
- H: "Schalenfrüchte",
88
- L: "Sellerie",
89
- M: "Senf",
90
- N: "Sesam",
91
- O: "Schwefeldioxid und Sulfite",
92
- P: "Lupinen",
93
- R: "Weichtiere",
94
- };
95
-
96
75
  export interface FoodLabel {
97
76
  code: string;
98
77
  name: string;
@@ -143,18 +122,7 @@ export function allergensChecked(product: Schemas["Product"]): boolean {
143
122
  return customFieldsOf(product).shopbite_allergens_checked === true;
144
123
  }
145
124
 
146
- /** "A, G, 2": every code once, allergens first. */
147
- export function foodLabelCodes(labels: FoodLabels): string[] {
148
- return [
149
- ...new Set(
150
- [...labels.allergens, ...labels.additives]
151
- .map((label) => label.code)
152
- .filter(Boolean),
153
- ),
154
- ];
155
- }
156
-
157
- /** Plain text for the product sheet and screen readers. */
125
+ /** Plain text for the info popover of the product sheet (#500). */
158
126
  export function foodLabelText(labels: FoodLabels): string {
159
127
  const parts: string[] = [];
160
128
  if (labels.allergens.length) {
@@ -169,32 +137,3 @@ export function foodLabelText(labels: FoodLabels): string {
169
137
  }
170
138
  return parts.join(" ");
171
139
  }
172
-
173
- /**
174
- * Legend of the codes used in a list of products: allergens by their
175
- * allergen name, additives by their option name, sorted like a menu.
176
- */
177
- export function foodLabelLegend(products: Schemas["Product"][]): FoodLabel[] {
178
- const legend = new Map<string, string>();
179
- for (const product of products) {
180
- const labels = getFoodLabels(
181
- product.sortedProperties as Schemas["PropertyGroup"][] | undefined,
182
- );
183
- for (const label of labels.allergens) {
184
- if (label.code)
185
- legend.set(label.code, ALLERGEN_CODE_NAMES[label.code] ?? label.name);
186
- }
187
- for (const label of labels.additives) {
188
- if (label.code) legend.set(label.code, label.name);
189
- }
190
- }
191
- return [...legend]
192
- .map(([code, name]) => ({ code, name }))
193
- .sort((a, b) => {
194
- const numeric = Number(a.code) - Number(b.code);
195
- if (!Number.isNaN(numeric)) return numeric;
196
- if (Number.isNaN(Number(a.code)) !== Number.isNaN(Number(b.code)))
197
- return Number.isNaN(Number(a.code)) ? -1 : 1;
198
- return a.code.localeCompare(b.code);
199
- });
200
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopbite-de/storefront",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "main": "nuxt.config.ts",
5
5
  "description": "Shopware storefront for food delivery shops",
6
6
  "keywords": [
@@ -44,7 +44,7 @@
44
44
  "@axe-core/playwright": "^4.13.0",
45
45
  "@nuxt/devtools-kit": "^3.4.2",
46
46
  "@nuxt/eslint": "^1.17.0",
47
- "@nuxt/hints": "1.1.4",
47
+ "@nuxt/hints": "1.1.5",
48
48
  "@nuxt/test-utils": "^4.3.2",
49
49
  "@playwright/test": "^1.63.0",
50
50
  "@types/js-cookie": "^3.0.6",
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { mountSuspended } from "@nuxt/test-utils/runtime";
3
+ import { flushPromises } from "@vue/test-utils";
4
+ import type { Schemas } from "#shopware";
5
+ import ProductFoodLabels from "~/components/Product/FoodLabels.vue";
6
+
7
+ const option = (code: string, name: string) => ({
8
+ name,
9
+ translated: { name, customFields: { shopbite_code: code } },
10
+ });
11
+
12
+ const dish = (
13
+ allergens: [string, string][],
14
+ checked = false,
15
+ ): Schemas["Product"] =>
16
+ ({
17
+ translated: {
18
+ customFields: checked ? { shopbite_allergens_checked: true } : {},
19
+ },
20
+ sortedProperties: allergens.length
21
+ ? [
22
+ {
23
+ translated: { name: "Allergene" },
24
+ options: allergens.map(([code, name]) => option(code, name)),
25
+ },
26
+ ]
27
+ : [],
28
+ }) as unknown as Schemas["Product"];
29
+
30
+ async function openPopover(product: Schemas["Product"]) {
31
+ const wrapper = await mountSuspended(ProductFoodLabels, {
32
+ props: { product },
33
+ attachTo: document.body,
34
+ });
35
+ const button = wrapper.get("button");
36
+ expect(button.attributes("aria-label")).toBe("Allergene und Zusatzstoffe");
37
+ expect(wrapper.find('[data-testid="food-labels"]').exists()).toBe(false);
38
+ await button.trigger("click");
39
+ await flushPromises();
40
+ return wrapper;
41
+ }
42
+
43
+ describe("food labels behind the info button (#500)", () => {
44
+ it("shows the allergens only after a click", async () => {
45
+ const wrapper = await openPopover(
46
+ dish([
47
+ ["A", "Weizen"],
48
+ ["G", "Milch (inkl. Laktose)"],
49
+ ]),
50
+ );
51
+ expect(wrapper.get('[data-testid="food-labels"]').text()).toContain(
52
+ "Enthält: Weizen, Milch (inkl. Laktose).",
53
+ );
54
+ wrapper.unmount();
55
+ });
56
+
57
+ it("says 'without' only when the restaurant checked the lists", async () => {
58
+ const checked = await openPopover(dish([], true));
59
+ expect(checked.get('[data-testid="food-labels"]').text()).toContain(
60
+ "Ohne kennzeichnungspflichtige Allergene und Zusatzstoffe.",
61
+ );
62
+ checked.unmount();
63
+
64
+ const unchecked = await openPopover(dish([]));
65
+ const text = unchecked.get('[data-testid="food-labels"]').text();
66
+ expect(text).toContain("Angaben erhalten Sie im Restaurant");
67
+ expect(text).not.toContain("Ohne");
68
+ unchecked.unmount();
69
+ });
70
+ });
@@ -2,8 +2,6 @@ import { describe, expect, it } from "vitest";
2
2
  import type { Schemas } from "#shopware";
3
3
  import {
4
4
  allergensChecked,
5
- foodLabelCodes,
6
- foodLabelLegend,
7
5
  foodLabelText,
8
6
  getDiets,
9
7
  getFoodLabels,
@@ -141,9 +139,8 @@ describe("food labels (#485)", () => {
141
139
  expect(getFoodLabels(undefined)).toEqual({ allergens: [], additives: [] });
142
140
  });
143
141
 
144
- it("lists every code once and writes plain text", () => {
142
+ it("writes plain text", () => {
145
143
  const labels = getFoodLabels(withLabels());
146
- expect(foodLabelCodes(labels)).toEqual(["A", "G", "2"]);
147
144
  expect(foodLabelText(labels)).toBe(
148
145
  "Enthält: Weizen, Dinkel, Milch (inkl. Laktose). Zusatzstoffe: mit Konservierungsstoff.",
149
146
  );
@@ -160,23 +157,4 @@ describe("food labels (#485)", () => {
160
157
  ).toBe(true);
161
158
  expect(allergensChecked(product())).toBe(false);
162
159
  });
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
160
  });
@@ -1,28 +0,0 @@
1
- <script setup lang="ts">
2
- import type { Schemas } from "#shopware";
3
-
4
- /**
5
- * Explains the allergen and additive codes on the cards of the list
6
- * (#485). Native <details>, so the legend is in the SSR HTML.
7
- */
8
- const props = defineProps<{ products: Schemas["Product"][] }>();
9
-
10
- const legend = computed(() => foodLabelLegend(props.products));
11
- </script>
12
-
13
- <template>
14
- <details
15
- v-if="legend.length"
16
- class="mt-6 rounded-sb-card bg-sb-surface px-4 py-3 text-sm text-sb-ink"
17
- >
18
- <summary class="min-h-11 cursor-pointer py-2.5 font-semibold">
19
- Allergene und Zusatzstoffe
20
- </summary>
21
- <dl class="grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 pb-2">
22
- <template v-for="entry in legend" :key="entry.code">
23
- <dt class="font-semibold tabular-nums">{{ entry.code }}</dt>
24
- <dd class="text-sb-ink-muted">{{ entry.name }}</dd>
25
- </template>
26
- </dl>
27
- </details>
28
- </template>