@shopbite-de/storefront 2.0.3 → 2.1.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.
- package/CLAUDE.md +3 -2
- package/api-types/storeApiSchema.json +227 -0
- package/api-types/storeApiTypes.d.ts +56 -2
- package/app/app.vue +10 -12
- package/app/components/Checkout/LoginOrRegister.vue +2 -8
- package/app/components/Header.vue +1 -1
- package/app/components/Product/Detail.vue +22 -0
- package/app/components/Product/QuickView.vue +6 -0
- package/app/components/Wishlist.vue +264 -58
- package/app/components/WishlistSaveButton.vue +57 -0
- package/app/composables/useTrackEvent.ts +3 -1
- package/app/composables/useWishlistEntries.ts +291 -0
- package/app/pages/anmelden.vue +1 -4
- package/app/pages/registrierung/bestaetigen.vue +0 -2
- package/package.json +1 -1
- package/test/nuxt/RegisterConfirmPage.test.ts +1 -6
- package/test/nuxt/WishlistPage.test.ts +107 -0
- package/test/nuxt/WishlistSaveButton.test.ts +67 -0
- package/test/nuxt/useWishlistEntries.test.ts +207 -0
- package/app/components/AddToWishlist.vue +0 -40
- package/app/composables/useWishlistActions.ts +0 -96
- package/test/nuxt/useWishlistActions.test.ts +0 -117
|
@@ -1,79 +1,246 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { Schemas } from "#shopware";
|
|
3
|
+
import type { LocationQueryRaw } from "vue-router";
|
|
4
|
+
import type { AssociationItemProduct } from "~/types/Association";
|
|
5
|
+
import type { WishlistEntry } from "~/composables/useWishlistEntries";
|
|
6
|
+
import { withQuickViewConfiguration } from "~/utils/productUrl";
|
|
3
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The wishlist with configured dishes (#467). Each row names the dish with
|
|
10
|
+
* its configuration ("+Extra Salami, ohne Pilze"), shows today's price of
|
|
11
|
+
* dish and extras, adds it to the cart as the product sheet would (same
|
|
12
|
+
* container line item, `useAddToCart`) and opens the sheet with the saved
|
|
13
|
+
* configuration ("Anpassen", the quick view URL of #411 on this page).
|
|
14
|
+
*/
|
|
4
15
|
withDefaults(defineProps<{ showMenuButton?: boolean }>(), {
|
|
5
16
|
showMenuButton: false,
|
|
6
17
|
});
|
|
7
18
|
|
|
8
|
-
const
|
|
19
|
+
const route = useRoute();
|
|
9
20
|
const { apiClient } = useShopwareContext();
|
|
10
21
|
const { getFormattedPrice } = useCommercePrice();
|
|
22
|
+
const { entries, loaded, remove, clear } = useWishlistEntries();
|
|
11
23
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} = useWishlistActions();
|
|
24
|
+
setSelectedProduct,
|
|
25
|
+
setSelectedExtras,
|
|
26
|
+
setDeselectedIngredients,
|
|
27
|
+
selectedQuantity,
|
|
28
|
+
addToCart,
|
|
29
|
+
} = useAddToCart();
|
|
19
30
|
|
|
20
31
|
const products = ref<Schemas["Product"][]>([]);
|
|
32
|
+
const extras = ref<Schemas["Product"][]>([]);
|
|
33
|
+
const loadingProducts = ref(false);
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
async function loadProducts(list: WishlistEntry[]) {
|
|
36
|
+
const productIds = [...new Set(list.map((entry) => entry.productId))];
|
|
37
|
+
const extraNumbers = [...new Set(list.flatMap((entry) => entry.extras))];
|
|
38
|
+
if (!productIds.length) {
|
|
39
|
+
products.value = [];
|
|
40
|
+
extras.value = [];
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
loadingProducts.value = true;
|
|
25
44
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
const [dishes, extraProducts] = await Promise.all([
|
|
46
|
+
apiClient.invoke("readProduct post /product", {
|
|
47
|
+
// @ts-expect-error sw-inheritance is missing from the generated header type
|
|
48
|
+
headers: { "sw-inheritance": "true" },
|
|
49
|
+
body: { ids: productIds, limit: productIds.length },
|
|
50
|
+
}),
|
|
51
|
+
extraNumbers.length
|
|
52
|
+
? apiClient.invoke("readProduct post /product", {
|
|
53
|
+
body: {
|
|
54
|
+
filter: [
|
|
55
|
+
{
|
|
56
|
+
type: "equalsAny",
|
|
57
|
+
field: "productNumber",
|
|
58
|
+
value: extraNumbers.join("|"),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
limit: extraNumbers.length,
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
: Promise.resolve(undefined),
|
|
65
|
+
]);
|
|
66
|
+
products.value = dishes.data.elements ?? [];
|
|
67
|
+
extras.value = extraProducts?.data.elements ?? [];
|
|
33
68
|
} catch (error) {
|
|
34
|
-
console.error("[wishlist][
|
|
69
|
+
console.error("[wishlist][loadProducts]", error);
|
|
70
|
+
} finally {
|
|
71
|
+
loadingProducts.value = false;
|
|
35
72
|
}
|
|
73
|
+
}
|
|
36
74
|
|
|
37
|
-
|
|
75
|
+
watch(
|
|
76
|
+
() => entries.value.map((entry) => entry.id).join(),
|
|
77
|
+
() => loadProducts(entries.value),
|
|
78
|
+
{ immediate: true },
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
function nameOf(product: Schemas["Product"] | undefined) {
|
|
82
|
+
return product?.translated?.name ?? product?.name ?? "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type Row = {
|
|
86
|
+
entry: WishlistEntry;
|
|
87
|
+
product: Schemas["Product"];
|
|
88
|
+
extras: Schemas["Product"][];
|
|
89
|
+
configuration: string;
|
|
90
|
+
price: number;
|
|
91
|
+
// a parent with variants (saved before #467) needs a choice first
|
|
92
|
+
needsChoice: boolean;
|
|
38
93
|
};
|
|
39
94
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
const rows = computed<Row[]>(() =>
|
|
96
|
+
entries.value.flatMap((entry) => {
|
|
97
|
+
const product = products.value.find(
|
|
98
|
+
(candidate) => candidate.id === entry.productId,
|
|
99
|
+
);
|
|
100
|
+
if (!product) return [];
|
|
101
|
+
const chosenExtras = entry.extras
|
|
102
|
+
.map((number) =>
|
|
103
|
+
extras.value.find((extra) => extra.productNumber === number),
|
|
104
|
+
)
|
|
105
|
+
.filter((extra): extra is Schemas["Product"] => !!extra);
|
|
106
|
+
const configuration = [
|
|
107
|
+
...chosenExtras.map((extra) => `+${nameOf(extra)}`),
|
|
108
|
+
...entry.without.map((name) => `ohne ${name}`),
|
|
109
|
+
].join(", ");
|
|
110
|
+
const price =
|
|
111
|
+
(product.calculatedPrice?.unitPrice ?? 0) +
|
|
112
|
+
chosenExtras.reduce(
|
|
113
|
+
(sum, extra) => sum + (extra.calculatedPrice?.unitPrice ?? 0),
|
|
114
|
+
0,
|
|
46
115
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
entry,
|
|
119
|
+
product,
|
|
120
|
+
extras: chosenExtras,
|
|
121
|
+
configuration,
|
|
122
|
+
price,
|
|
123
|
+
needsChoice: (product.childCount ?? 0) > 0,
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
}),
|
|
56
127
|
);
|
|
57
128
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
129
|
+
// "Anpassen" opens the product sheet on this page.
|
|
130
|
+
const quickView = useProductQuickView(products);
|
|
131
|
+
|
|
132
|
+
function customizeLink(row: Row) {
|
|
133
|
+
return {
|
|
134
|
+
query: withQuickViewConfiguration(route.query, {
|
|
135
|
+
productNumber: row.product.productNumber,
|
|
136
|
+
without: row.entry.without,
|
|
137
|
+
extras: row.entry.extras,
|
|
138
|
+
}) as LocationQueryRaw,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function rowLabel(row: Row) {
|
|
143
|
+
return row.configuration
|
|
144
|
+
? `${nameOf(row.product)} (${row.configuration})`
|
|
145
|
+
: nameOf(row.product);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const addingId = ref<string | null>(null);
|
|
149
|
+
const addingAll = ref(false);
|
|
150
|
+
const failed = ref<string | null>(null);
|
|
151
|
+
|
|
152
|
+
function asExtra(extra: Schemas["Product"]): AssociationItemProduct {
|
|
153
|
+
return {
|
|
154
|
+
label: nameOf(extra),
|
|
155
|
+
value: extra.id,
|
|
156
|
+
productNumber: extra.productNumber,
|
|
157
|
+
price: getFormattedPrice(extra.calculatedPrice?.unitPrice),
|
|
158
|
+
unitPrice: extra.calculatedPrice?.unitPrice,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Adds one row with the same line item the product sheet creates. */
|
|
163
|
+
async function addRow(row: Row) {
|
|
164
|
+
setSelectedProduct(row.product);
|
|
165
|
+
setSelectedExtras(row.extras.map(asExtra));
|
|
166
|
+
setDeselectedIngredients(row.entry.without);
|
|
167
|
+
selectedQuantity.value = 1;
|
|
168
|
+
let added = false;
|
|
169
|
+
await addToCart(() => (added = true));
|
|
170
|
+
return added;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function addOne(row: Row) {
|
|
174
|
+
addingId.value = row.entry.id;
|
|
175
|
+
failed.value = null;
|
|
176
|
+
try {
|
|
177
|
+
if (!(await addRow(row))) failed.value = rowLabel(row);
|
|
178
|
+
} finally {
|
|
179
|
+
addingId.value = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function addAll() {
|
|
184
|
+
addingAll.value = true;
|
|
185
|
+
failed.value = null;
|
|
186
|
+
try {
|
|
187
|
+
for (const row of rows.value) {
|
|
188
|
+
if (row.needsChoice) continue;
|
|
189
|
+
if (!(await addRow(row))) {
|
|
190
|
+
failed.value = rowLabel(row);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
} finally {
|
|
195
|
+
addingAll.value = false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const removingId = ref<string | null>(null);
|
|
200
|
+
async function removeRow(row: Row) {
|
|
201
|
+
removingId.value = row.entry.id;
|
|
202
|
+
try {
|
|
203
|
+
await remove(row.entry.id);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error("[wishlist][remove]", error);
|
|
206
|
+
} finally {
|
|
207
|
+
removingId.value = null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const confirmClear = ref(false);
|
|
212
|
+
const clearing = ref(false);
|
|
213
|
+
async function clearAll() {
|
|
214
|
+
clearing.value = true;
|
|
215
|
+
try {
|
|
216
|
+
await clear();
|
|
217
|
+
confirmClear.value = false;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error("[wishlist][clear]", error);
|
|
220
|
+
} finally {
|
|
221
|
+
clearing.value = false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
61
224
|
</script>
|
|
62
225
|
|
|
63
226
|
<template>
|
|
64
227
|
<div class="flex flex-col gap-6 font-body text-sb-ink">
|
|
65
228
|
<p
|
|
66
|
-
v-if="
|
|
229
|
+
v-if="!loaded || (loadingProducts && !rows.length)"
|
|
67
230
|
role="status"
|
|
68
231
|
class="text-sb-ink-muted"
|
|
69
232
|
>
|
|
70
233
|
Merkliste wird geladen …
|
|
71
234
|
</p>
|
|
72
235
|
<div
|
|
73
|
-
v-else-if="!
|
|
236
|
+
v-else-if="!rows.length"
|
|
74
237
|
class="flex flex-col items-start gap-4 rounded-sb-card border border-sb-line bg-sb-surface p-6"
|
|
75
238
|
>
|
|
76
239
|
<p>Ihre Merkliste ist leer.</p>
|
|
240
|
+
<p class="text-sm text-sb-ink-muted">
|
|
241
|
+
Im Gericht merken Sie es mit dem Herz, so wie Sie es zusammengestellt
|
|
242
|
+
haben.
|
|
243
|
+
</p>
|
|
77
244
|
<SbButton v-if="showMenuButton" to="/speisekarte/"
|
|
78
245
|
>Zur Speisekarte</SbButton
|
|
79
246
|
>
|
|
@@ -83,42 +250,81 @@ onMounted(async () => {
|
|
|
83
250
|
class="flex flex-col overflow-hidden rounded-sb-card border border-sb-line bg-sb-surface"
|
|
84
251
|
>
|
|
85
252
|
<li
|
|
86
|
-
v-for="
|
|
87
|
-
:key="
|
|
88
|
-
|
|
253
|
+
v-for="row in rows"
|
|
254
|
+
:key="row.entry.id"
|
|
255
|
+
:aria-label="rowLabel(row)"
|
|
256
|
+
class="grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-3 gap-y-3 border-b border-sb-line p-4 last:border-b-0"
|
|
89
257
|
>
|
|
90
258
|
<p class="min-w-0">
|
|
91
259
|
<span
|
|
92
260
|
class="block font-bold [overflow-wrap:anywhere] hyphens-auto"
|
|
93
|
-
>{{
|
|
261
|
+
>{{ nameOf(row.product) }}</span
|
|
262
|
+
>
|
|
263
|
+
<span
|
|
264
|
+
v-if="row.configuration"
|
|
265
|
+
class="block text-sm [overflow-wrap:anywhere]"
|
|
266
|
+
>{{ row.configuration }}</span
|
|
94
267
|
>
|
|
95
268
|
<span class="text-sm text-sb-ink-muted tabular-nums"
|
|
96
|
-
>Nr. {{ product.productNumber }} ·
|
|
97
|
-
{{ getFormattedPrice(
|
|
269
|
+
>Nr. {{ row.product.productNumber }} ·
|
|
270
|
+
{{ getFormattedPrice(row.price) }}</span
|
|
98
271
|
>
|
|
99
272
|
</p>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
variant="
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
@click="addSingleItemToCart(product)"
|
|
273
|
+
<SbIconButton
|
|
274
|
+
:label="`${rowLabel(row)} von der Merkliste entfernen`"
|
|
275
|
+
variant="ghost"
|
|
276
|
+
:disabled="removingId === row.entry.id"
|
|
277
|
+
@click="removeRow(row)"
|
|
106
278
|
>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
279
|
+
<SbIcon name="close" />
|
|
280
|
+
</SbIconButton>
|
|
281
|
+
<div class="col-span-full flex flex-col gap-2 sm:flex-row">
|
|
282
|
+
<SbButton
|
|
283
|
+
v-if="!row.needsChoice"
|
|
284
|
+
variant="tint"
|
|
285
|
+
:loading="addingId === row.entry.id"
|
|
286
|
+
:disabled="addingAll"
|
|
287
|
+
@click="addOne(row)"
|
|
110
288
|
>
|
|
111
|
-
|
|
289
|
+
In den Warenkorb
|
|
290
|
+
<span class="sr-only">: {{ rowLabel(row) }}</span>
|
|
291
|
+
</SbButton>
|
|
292
|
+
<SbButton variant="secondary" :to="customizeLink(row)">
|
|
293
|
+
{{ row.needsChoice ? "Auswählen" : "Anpassen" }}
|
|
294
|
+
<span class="sr-only">: {{ rowLabel(row) }}</span>
|
|
295
|
+
</SbButton>
|
|
296
|
+
</div>
|
|
112
297
|
</li>
|
|
113
298
|
</ul>
|
|
299
|
+
<p
|
|
300
|
+
v-if="failed"
|
|
301
|
+
role="alert"
|
|
302
|
+
class="rounded-sb-control border-[1.5px] border-sb-danger p-4 text-sm"
|
|
303
|
+
>
|
|
304
|
+
{{ failed }} konnte nicht in den Warenkorb gelegt werden. Bitte
|
|
305
|
+
versuchen Sie es erneut.
|
|
306
|
+
</p>
|
|
114
307
|
<div class="flex flex-col gap-3 sm:flex-row">
|
|
115
|
-
<SbButton :loading="
|
|
308
|
+
<SbButton :loading="addingAll" @click="addAll"
|
|
116
309
|
>Alle in den Warenkorb</SbButton
|
|
117
310
|
>
|
|
118
|
-
<SbButton variant="ghost" @click="
|
|
311
|
+
<SbButton variant="ghost" @click="confirmClear = true"
|
|
119
312
|
>Merkliste leeren</SbButton
|
|
120
313
|
>
|
|
121
314
|
</div>
|
|
315
|
+
<SbConfirmDialog
|
|
316
|
+
v-model:open="confirmClear"
|
|
317
|
+
title="Merkliste leeren?"
|
|
318
|
+
description="Alle gemerkten Gerichte werden entfernt."
|
|
319
|
+
confirm-label="Merkliste leeren"
|
|
320
|
+
:loading="clearing"
|
|
321
|
+
@confirm="clearAll"
|
|
322
|
+
/>
|
|
122
323
|
</template>
|
|
324
|
+
<LazyProductQuickView
|
|
325
|
+
v-if="quickView.mounted.value"
|
|
326
|
+
v-model:open="quickView.open.value"
|
|
327
|
+
:product="quickView.product.value"
|
|
328
|
+
/>
|
|
123
329
|
</div>
|
|
124
330
|
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { WishlistConfiguration } from "~/composables/useWishlistEntries";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Saves the dish as configured right now (#467): variant, deselected
|
|
6
|
+
* ingredients and extras. A toggle with `aria-pressed` and a stable name;
|
|
7
|
+
* the pressed state follows the configuration, so changing an extra after
|
|
8
|
+
* saving shows the new combination as not saved yet.
|
|
9
|
+
*/
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
selection: WishlistConfiguration | undefined;
|
|
12
|
+
name: string;
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const { find, add, remove } = useWishlistEntries();
|
|
16
|
+
const { trackAddToWishlist } = useTrackEvent();
|
|
17
|
+
|
|
18
|
+
const saved = computed(() =>
|
|
19
|
+
props.selection ? find(props.selection) : undefined,
|
|
20
|
+
);
|
|
21
|
+
const busy = ref(false);
|
|
22
|
+
const failed = ref(false);
|
|
23
|
+
|
|
24
|
+
async function toggle() {
|
|
25
|
+
if (!props.selection || busy.value) return;
|
|
26
|
+
busy.value = true;
|
|
27
|
+
failed.value = false;
|
|
28
|
+
try {
|
|
29
|
+
if (saved.value) {
|
|
30
|
+
await remove(saved.value.id);
|
|
31
|
+
} else {
|
|
32
|
+
await add(props.selection);
|
|
33
|
+
trackAddToWishlist({ productNumber: props.selection.productNumber });
|
|
34
|
+
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error("[wishlist][toggle]", error);
|
|
37
|
+
failed.value = true;
|
|
38
|
+
} finally {
|
|
39
|
+
busy.value = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<SbIconButton
|
|
46
|
+
:label="`${name} merken`"
|
|
47
|
+
:pressed="!!saved"
|
|
48
|
+
:disabled="!selection"
|
|
49
|
+
:aria-busy="busy || undefined"
|
|
50
|
+
@click="toggle"
|
|
51
|
+
>
|
|
52
|
+
<SbIcon name="heart" :filled="!!saved" />
|
|
53
|
+
</SbIconButton>
|
|
54
|
+
<span class="sr-only" role="status">{{
|
|
55
|
+
failed ? "Merken hat nicht geklappt. Bitte versuchen Sie es erneut." : ""
|
|
56
|
+
}}</span>
|
|
57
|
+
</template>
|
|
@@ -50,7 +50,9 @@ export function useTrackEvent() {
|
|
|
50
50
|
push(["trackEcommerceOrder", order.orderNumber, order.price.totalPrice]);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function trackAddToWishlist(
|
|
53
|
+
function trackAddToWishlist(
|
|
54
|
+
product: Pick<Schemas["Product"], "productNumber">,
|
|
55
|
+
) {
|
|
54
56
|
push(["trackEvent", "Product", "AddToWishlist", product.productNumber]);
|
|
55
57
|
}
|
|
56
58
|
|