@shopbite-de/storefront 2.0.2 → 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.
Files changed (32) hide show
  1. package/CLAUDE.md +4 -3
  2. package/api-types/storeApiSchema.json +227 -0
  3. package/api-types/storeApiTypes.d.ts +56 -2
  4. package/app/app.vue +10 -12
  5. package/app/components/Checkout/LoginOrRegister.vue +2 -8
  6. package/app/components/Checkout/PaymentAndDelivery.vue +3 -3
  7. package/app/components/Checkout/Summary.vue +53 -5
  8. package/app/components/Header.vue +1 -1
  9. package/app/components/Product/Detail.vue +22 -0
  10. package/app/components/Product/QuickView.vue +6 -0
  11. package/app/components/Wishlist.vue +264 -58
  12. package/app/components/WishlistSaveButton.vue +57 -0
  13. package/app/composables/useCheckoutMethodGuard.ts +19 -30
  14. package/app/composables/useOrderMode.ts +6 -8
  15. package/app/composables/useShippingMethodChoice.ts +37 -0
  16. package/app/composables/useTrackEvent.ts +3 -1
  17. package/app/composables/useWishlistEntries.ts +291 -0
  18. package/app/pages/anmelden.vue +1 -4
  19. package/app/pages/registrierung/bestaetigen.vue +0 -2
  20. package/package.json +1 -1
  21. package/test/nuxt/CartCheckoutPreset.test.ts +8 -5
  22. package/test/nuxt/CheckoutSummary.test.ts +39 -3
  23. package/test/nuxt/PaymentAndDelivery.test.ts +8 -5
  24. package/test/nuxt/RegisterConfirmPage.test.ts +1 -6
  25. package/test/nuxt/WishlistPage.test.ts +107 -0
  26. package/test/nuxt/WishlistSaveButton.test.ts +67 -0
  27. package/test/nuxt/useCheckoutMethodGuard.test.ts +12 -80
  28. package/test/nuxt/useShippingMethodChoice.test.ts +46 -0
  29. package/test/nuxt/useWishlistEntries.test.ts +207 -0
  30. package/app/components/AddToWishlist.vue +0 -40
  31. package/app/composables/useWishlistActions.ts +0 -96
  32. 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 { getWishlistProducts, items } = useWishlist();
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
- isAddingToCart,
13
- addingItemId,
14
- isLoading,
15
- clearWishlistHandler,
16
- addSingleItemToCart,
17
- addAllItemsToCart,
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
- const loadProductsByItemIds = async (itemIds: string[]): Promise<void> => {
23
- isLoading.value = true;
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 { data } = await apiClient.invoke("readProduct post /product", {
27
- body: { ids: itemIds || items.value },
28
- });
29
-
30
- if (data?.elements) {
31
- products.value = data.elements;
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][loadProductsByItemIds]", error);
69
+ console.error("[wishlist][loadProducts]", error);
70
+ } finally {
71
+ loadingProducts.value = false;
35
72
  }
73
+ }
36
74
 
37
- isLoading.value = false;
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
- watch(
41
- items,
42
- (items, oldItems) => {
43
- if (items.length !== oldItems?.length) {
44
- products.value = products.value.filter(({ id }: { id: string }) =>
45
- items.includes(id),
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
- if (!items.length) {
49
- return;
50
- }
51
- loadProductsByItemIds(items);
52
- },
53
- {
54
- immediate: true,
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
- onMounted(async () => {
59
- await getWishlistProducts();
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="isLoading && !products.length"
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="!products.length"
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="product in products"
87
- :key="product.id"
88
- class="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 border-b border-sb-line p-4 last:border-b-0 sm:grid-cols-[minmax(0,1fr)_auto_auto]"
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
- >{{ product.translated?.name ?? product.name }}</span
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(product.calculatedPrice?.totalPrice) }}</span
269
+ >Nr. {{ row.product.productNumber }} ·
270
+ {{ getFormattedPrice(row.price) }}</span
98
271
  >
99
272
  </p>
100
- <AddToWishlist :product="product" />
101
- <SbButton
102
- variant="tint"
103
- class="col-span-full sm:col-span-1"
104
- :loading="addingItemId === product.id"
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
- In den Warenkorb
108
- <span class="sr-only"
109
- >: {{ product.translated?.name ?? product.name }}</span
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
- </SbButton>
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="isAddingToCart" @click="addAllItemsToCart(products)"
308
+ <SbButton :loading="addingAll" @click="addAll"
116
309
  >Alle in den Warenkorb</SbButton
117
310
  >
118
- <SbButton variant="ghost" @click="clearWishlistHandler"
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>
@@ -41,24 +41,24 @@ type MethodGuardConfig<M extends CheckoutMethod> = {
41
41
  };
42
42
 
43
43
  /**
44
- * Detects a blocked shipping or payment method in the cart and switches to
45
- * an available one (sales-channel default first, otherwise the first
44
+ * Detects a blocked payment method in the cart and switches to an
45
+ * available one (sales-channel default first, otherwise the first
46
46
  * available), mirroring what Shopware's own storefront does.
47
47
  *
48
48
  * The Store API does not perform this switch itself. Without it, order
49
- * creation fails with `CHECKOUT__CART_INVALID`
50
- * (`shipping-method-blocked` / `payment-method-blocked`).
49
+ * creation fails with `CHECKOUT__CART_INVALID` (`payment-method-blocked`).
50
+ *
51
+ * A blocked shipping method is only reported, never switched: its rule
52
+ * usually needs the shipping address (delivery area), which a guest enters
53
+ * after choosing delivery or pickup. Switching turned every delivery into
54
+ * a pickup before the address was known (La Fattoria, 2.0.2). With an
55
+ * address the checkout says the method is not possible and the customer
56
+ * picks another one.
51
57
  */
52
58
  export function useCheckoutMethodGuard() {
53
59
  const { cart, refreshCart } = useCart();
54
- const {
55
- getShippingMethods,
56
- setShippingMethod,
57
- selectedShippingMethod,
58
- getPaymentMethods,
59
- setPaymentMethod,
60
- selectedPaymentMethod,
61
- } = useCheckout();
60
+ const { getPaymentMethods, setPaymentMethod, selectedPaymentMethod } =
61
+ useCheckout();
62
62
  const { sessionContext } = useSessionContext();
63
63
 
64
64
  const isShippingMethodBlocked = computed(() =>
@@ -70,15 +70,6 @@ export function useCheckoutMethodGuard() {
70
70
 
71
71
  const isResolving = ref(false);
72
72
 
73
- const shippingConfig: MethodGuardConfig<Schemas["ShippingMethod"]> = {
74
- isBlocked: () => isShippingMethodBlocked.value,
75
- selected: () => selectedShippingMethod.value,
76
- loadAvailable: async () =>
77
- (await getShippingMethods({ forceReload: true })).value,
78
- defaultId: () => sessionContext.value?.salesChannel?.shippingMethodId,
79
- select: (id) => setShippingMethod({ id }),
80
- };
81
-
82
73
  const paymentConfig: MethodGuardConfig<Schemas["PaymentMethod"]> = {
83
74
  isBlocked: () => isPaymentMethodBlocked.value,
84
75
  selected: () => selectedPaymentMethod.value,
@@ -137,11 +128,11 @@ export function useCheckoutMethodGuard() {
137
128
  }
138
129
 
139
130
  /**
140
- * Refreshes the cart and, if the selected shipping method is blocked,
141
- * switches to an available one.
131
+ * Refreshes the cart and tells whether the selected shipping method is
132
+ * available. Never switches it (see above).
142
133
  */
143
134
  function ensureAvailableShippingMethod(): Promise<boolean> {
144
- return run(() => resolve(shippingConfig));
135
+ return run(async () => !isShippingMethodBlocked.value);
145
136
  }
146
137
 
147
138
  /**
@@ -153,17 +144,15 @@ export function useCheckoutMethodGuard() {
153
144
  }
154
145
 
155
146
  /**
156
- * Refreshes the cart and resolves blocked shipping and payment methods.
157
- * Shipping is handled first because payment availability rules may
158
- * depend on the shipping method. If shipping cannot be resolved the
159
- * checkout stays blocked anyway, so payment is left untouched to avoid
160
- * a pointless switch.
147
+ * Refreshes the cart and resolves a blocked payment method. A blocked
148
+ * shipping method stays as it is; payment rules may depend on the
149
+ * shipping method, so payment is then left untouched as well.
161
150
  *
162
151
  * @returns `true` when both methods are available afterwards.
163
152
  */
164
153
  function ensureAvailableCheckoutMethods(): Promise<boolean> {
165
154
  return run(async () => {
166
- if (!(await resolve(shippingConfig))) return false;
155
+ if (isShippingMethodBlocked.value) return false;
167
156
  return resolve(paymentConfig);
168
157
  });
169
158
  }
@@ -5,15 +5,13 @@ import type { Schemas } from "#shopware";
5
5
  * sales channel as a choice before the customer starts ordering. Which
6
6
  * methods exist and which payment methods they allow is decided by the
7
7
  * Shopware rules; after a switch the guard moves a payment method the new
8
- * shipping method blocks.
8
+ * shipping method blocks. All active methods are offered, also those whose
9
+ * rule needs an address the guest has not entered yet.
9
10
  */
10
11
  export function useOrderMode() {
11
- const {
12
- shippingMethods,
13
- getShippingMethods,
14
- selectedShippingMethod,
15
- setShippingMethod,
16
- } = useCheckout();
12
+ const { selectedShippingMethod, setShippingMethod } = useCheckout();
13
+ const { methods: shippingMethods, load: loadShippingMethods } =
14
+ useShippingMethodChoice();
17
15
  const { refreshCart } = useCart();
18
16
  const { ensureAvailableCheckoutMethods } = useCheckoutMethodGuard();
19
17
 
@@ -55,7 +53,7 @@ export function useOrderMode() {
55
53
 
56
54
  async function load() {
57
55
  try {
58
- await getShippingMethods();
56
+ await loadShippingMethods();
59
57
  } catch (error) {
60
58
  console.error("[menu][useOrderMode] shipping methods", error);
61
59
  }
@@ -0,0 +1,37 @@
1
+ import type { Schemas } from "#shopware";
2
+
3
+ /**
4
+ * All active shipping methods of the sales channel, for the order mode
5
+ * above the menu and the shipping section of the checkout.
6
+ *
7
+ * `useCheckout().getShippingMethods()` asks the Store API for the methods
8
+ * whose availability rule matches right now. A rule on the shipping
9
+ * address (La Fattoria: "Valide Lieferung", city Obertshausen, Hausen or
10
+ * Lämmerspiel) never matches before the guest has entered an address, so
11
+ * "Lieferung" vanished from the choice. Whether the chosen method works
12
+ * for the address is checked in the cart (`shipping-method-blocked`).
13
+ */
14
+ export function useShippingMethodChoice() {
15
+ const { apiClient } = useShopwareContext();
16
+ const methods = useState<Schemas["ShippingMethod"][]>(
17
+ "shopbite-shipping-method-choice",
18
+ () => [],
19
+ );
20
+
21
+ async function load({ forceReload } = { forceReload: false }) {
22
+ if (methods.value.length && !forceReload) return methods;
23
+ const response = await apiClient.invoke(
24
+ "readShippingMethod post /shipping-method",
25
+ {
26
+ body: { associations: { prices: {} } },
27
+ query: { onlyAvailable: false },
28
+ },
29
+ );
30
+ methods.value = [...(response.data.elements ?? [])].sort(
31
+ (a, b) => (a.position ?? 0) - (b.position ?? 0),
32
+ );
33
+ return methods;
34
+ }
35
+
36
+ return { methods, load };
37
+ }
@@ -50,7 +50,9 @@ export function useTrackEvent() {
50
50
  push(["trackEcommerceOrder", order.orderNumber, order.price.totalPrice]);
51
51
  }
52
52
 
53
- function trackAddToWishlist(product: Schemas["Product"]) {
53
+ function trackAddToWishlist(
54
+ product: Pick<Schemas["Product"], "productNumber">,
55
+ ) {
54
56
  push(["trackEvent", "Product", "AddToWishlist", product.productNumber]);
55
57
  }
56
58