@shopbite-de/storefront 1.25.0 → 1.26.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
@@ -94,7 +94,7 @@ The storefront reads plain Shopware entities with fixed names; seed data must ma
94
94
 
95
95
  - **Navigation:** menu sections are the children of the sales channel navigation root (`readNavigation main-navigation`), optionally scoped by `runtimeConfig.public.shopBite.menuCategoryId`. Category icon comes from the custom field `shopbite_category_icon` (icones.js.org name such as `i-lucide-pizza`), set by the ShopBite plugin.
96
96
  - **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.
97
- - **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. Selected extras are sent as children of a `container` line item (`useAddToCart.ts`, handled by the ShopBite plugin). The product card has no buttons: the card opens the quick view drawer (`Product/QuickView.vue`), whose state is the `produkt` query parameter (product number) via `useProductQuickView` (#325).
97
+ - **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 product card has no buttons: the card opens the quick view drawer (`Product/QuickView.vue`), whose state is the `produkt` query parameter (product number) via `useProductQuickView` (#325).
98
98
  - **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.
99
99
  - **Variants:** standard configurator settings (`Product/Configurator.vue`); `server/api/product/variant.get.ts` resolves a variant by option ids.
100
100
 
@@ -126,7 +126,7 @@ The storefront reads plain Shopware entities with fixed names; seed data must ma
126
126
  - `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.
127
127
  - 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.
128
128
  - `@nuxtjs/sitemap` must stay before `@nuxt/content` in `modules`; content collections need the `sitemap` schema field to appear in the sitemap.
129
- - Shop contact data (NAP) lives in `runtimeConfig.public.site` (`address.*`, `telephone`, `googleBusinessProfileUrl`) and is rendered by `components/Footer/Contact.vue`. `useBusinessHours`/`useHolidays` use `immediate: false` (app.vue loads them on mount); a component that needs them in the SSR HTML calls `onServerPrefetch(() => refresh())`.
129
+ - Shop contact data (NAP) lives in `runtimeConfig.public.site` (`address.*`, `telephone`, `googleBusinessProfileUrl`) and is rendered by `components/Footer/Contact.vue`. `useBusinessHours`/`useHolidays` use `immediate: false` (app.vue loads them on mount); a component that needs them in the SSR HTML calls `onServerPrefetch(() => refresh())`. In the browser both requests are retried twice (`withRetries`); `useOpeningHoursData` gives components the combined loading/failed state and `retry()`, and reports a failure only after mounting (a failed server prefetch would otherwise break hydration, #355).
130
130
 
131
131
  ### Testing setup
132
132
 
package/README.md CHANGED
@@ -128,7 +128,6 @@ app/
128
128
  ├── components/ Cart, Checkout, Product, Food, Navigation, Header, …
129
129
  ├── composables/ Business logic — useBusinessHours, useDeliveryTime, useAddToCart, …
130
130
  ├── pages/ German routes: /speisekarte, /warenkorb, /konto, /bestellung
131
- ├── stores/ Pinia (checkout state)
132
131
  ├── validation/ Zod schemas for forms
133
132
  └── assets/css/ Tailwind v4 theme tokens
134
133
  server/api/ Cached Store API proxies + the Geoapify key guard
@@ -45,6 +45,11 @@ const {
45
45
  } = useDeliveryTime(now);
46
46
 
47
47
  const { isClosedHoliday } = useHolidays();
48
+ const {
49
+ isLoaded: isOpeningHoursLoaded,
50
+ hasFailed: hasOpeningHoursFailed,
51
+ retry: retryOpeningHours,
52
+ } = useOpeningHoursData();
48
53
 
49
54
  const validationError = computed<string | null>(() =>
50
55
  selected.value ? validate(selected.value) : null,
@@ -134,7 +139,28 @@ function handleTimeInput(event: Event): void {
134
139
  </script>
135
140
 
136
141
  <template>
137
- <div v-if="isClosedHoliday(now) === false" class="flex flex-col gap-2 mt-4">
142
+ <div v-if="hasOpeningHoursFailed" class="mt-4">
143
+ <UAlert
144
+ color="error"
145
+ variant="subtle"
146
+ icon="i-lucide-circle-alert"
147
+ title="Öffnungszeiten konnten nicht geladen werden"
148
+ description="Ohne Öffnungszeiten können wir keine Lieferzeit anbieten."
149
+ :actions="[
150
+ {
151
+ label: 'Erneut versuchen',
152
+ icon: 'i-lucide-refresh-cw',
153
+ color: 'error',
154
+ variant: 'outline',
155
+ onClick: retryOpeningHours,
156
+ },
157
+ ]"
158
+ />
159
+ </div>
160
+ <div
161
+ v-else-if="isOpeningHoursLoaded && isClosedHoliday(now) === false"
162
+ class="flex flex-col gap-2 mt-4"
163
+ >
138
164
  <div class="flex flex-row items-center justify-between gap-4">
139
165
  <label for="delivery-time" class="flex-1">
140
166
  Wunschlieferung- oder Abholzeit ab:
@@ -171,7 +197,7 @@ function handleTimeInput(event: Event): void {
171
197
  variant="subtle"
172
198
  />
173
199
  </div>
174
- <div v-else-if="isClosedHoliday(now) === true">
200
+ <div v-else-if="isOpeningHoursLoaded && isClosedHoliday(now) === true">
175
201
  <UBadge
176
202
  variant="subtle"
177
203
  class="w-full"
@@ -9,6 +9,8 @@ const { refreshCart } = useCart();
9
9
  const { isLoggedIn, isGuestSession, refreshUser } = useUser();
10
10
  const { isCheckoutEnabled, refresh } = useShopBiteConfig();
11
11
  const { trackOrder } = useTrackEvent();
12
+ const { isLoading: isLoadingOpeningHours, hasFailed: hasOpeningHoursFailed } =
13
+ useOpeningHoursData();
12
14
  const {
13
15
  isShippingMethodBlocked,
14
16
  isPaymentMethodBlocked,
@@ -146,13 +148,27 @@ const blockedMethodIcon = computed(() =>
146
148
 
147
149
  const isPlacingOrder = ref(false);
148
150
  const selectedDeliveryTime = ref("");
149
- const isValidTime = ref(true);
151
+ // DeliveryTimeSelect reports `false` during its setup (no time selected before
152
+ // the business hours load in the browser). Starting with `true` rendered the
153
+ // order button differently on the server and at hydration (#339).
154
+ const isValidTime = ref(false);
150
155
 
151
156
  const checkoutButtonLabel = computed<string>(() => {
152
157
  if (!customerDataAvailable.value) {
153
158
  return "Bitte einloggen oder Kundendaten erfassen";
154
159
  }
155
160
 
161
+ // app.vue loads business hours and holidays after mounting. Until then (or
162
+ // when that fails) an invalid time says nothing about the shop being closed
163
+ // (#349, #355).
164
+ if (isLoadingOpeningHours.value) {
165
+ return "Lade Öffnungszeiten …";
166
+ }
167
+
168
+ if (hasOpeningHoursFailed.value) {
169
+ return "Öffnungszeiten konnten nicht geladen werden";
170
+ }
171
+
156
172
  if (!isValidTime.value) {
157
173
  return "Wir haben aktuell leider geschlossen";
158
174
  }
@@ -202,7 +218,9 @@ const checkoutButtonLabel = computed<string>(() => {
202
218
  <UButton
203
219
  :icon="isValidToProceed ? 'i-lucide-shopping-cart' : 'i-lucide-lock'"
204
220
  :disabled="!isValidToProceed || isPlacingOrder"
205
- :loading="isPlacingOrder"
221
+ :loading="
222
+ isPlacingOrder || (customerDataAvailable && isLoadingOpeningHours)
223
+ "
206
224
  :label="checkoutButtonLabel"
207
225
  size="xl"
208
226
  block
@@ -6,7 +6,7 @@ import type {
6
6
 
7
7
  // The extras are loaded by useProductDetail together with the product, so
8
8
  // the list renders once and stays put when a variant is switched.
9
- defineProps<{
9
+ const props = defineProps<{
10
10
  associations: AssociationItem[];
11
11
  }>();
12
12
 
@@ -14,50 +14,163 @@ const emit = defineEmits<{
14
14
  "extras-selected": [selectedExtras: AssociationItemProduct[]];
15
15
  }>();
16
16
 
17
+ // Long extras lists made the quick view a long scroll: a group shows its first
18
+ // entries, the rest on request, and a search field once the list is long.
19
+ const PREVIEW_LIMIT = 6;
20
+ const SEARCH_THRESHOLD = 15;
21
+
22
+ const { getFormattedPrice } = useCommercePrice();
23
+
17
24
  const selectedExtras = ref<AssociationItemProduct[]>([]);
25
+ // Only the first group starts open, the others show their selection summary.
26
+ const openGroups = ref<string[]>(
27
+ props.associations[0] ? [props.associations[0].label] : [],
28
+ );
29
+ const expandedGroups = ref<string[]>([]);
30
+ const queries = ref<Record<string, string>>({});
18
31
 
19
32
  const isSelected = (extra: AssociationItemProduct) =>
20
33
  selectedExtras.value.some((selected) => selected.value === extra.value);
21
34
 
22
- function toggle(extra: AssociationItemProduct) {
23
- selectedExtras.value = isSelected(extra)
24
- ? selectedExtras.value.filter((selected) => selected.value !== extra.value)
25
- : [...selectedExtras.value, extra];
35
+ function setSelected(extra: AssociationItemProduct, selected: boolean) {
36
+ selectedExtras.value = selected
37
+ ? [...selectedExtras.value, extra]
38
+ : selectedExtras.value.filter((item) => item.value !== extra.value);
26
39
  }
27
40
 
41
+ function toggleGroup(label: string) {
42
+ openGroups.value = openGroups.value.includes(label)
43
+ ? openGroups.value.filter((open) => open !== label)
44
+ : [...openGroups.value, label];
45
+ }
46
+
47
+ function visibleProducts(association: AssociationItem) {
48
+ const query = queries.value[association.label]?.trim().toLowerCase();
49
+ if (query) {
50
+ return association.products.filter((extra) =>
51
+ extra.label.toLowerCase().includes(query),
52
+ );
53
+ }
54
+ // Hiding one or two entries behind a button saves less than the button costs.
55
+ const collapsed =
56
+ association.products.length > PREVIEW_LIMIT + 2 &&
57
+ !expandedGroups.value.includes(association.label);
58
+ return collapsed
59
+ ? association.products.slice(0, PREVIEW_LIMIT)
60
+ : association.products;
61
+ }
62
+
63
+ function hiddenCount(association: AssociationItem) {
64
+ if (queries.value[association.label]?.trim()) return 0;
65
+ return association.products.length - visibleProducts(association).length;
66
+ }
67
+
68
+ function summary(association: AssociationItem) {
69
+ const selected = association.products.filter(isSelected);
70
+ if (selected.length === 0) return "optional";
71
+ const price = selected.reduce(
72
+ (sum, extra) => sum + (extra.unitPrice ?? 0),
73
+ 0,
74
+ );
75
+ return `${selected.length} gewählt · +${getFormattedPrice(price)}`;
76
+ }
77
+
78
+ const baseId = useId();
79
+ const groupId = (index: number) => `${baseId}-extras-${index}`;
80
+
28
81
  watch(selectedExtras, () => emit("extras-selected", selectedExtras.value));
29
82
  </script>
30
83
 
31
84
  <template>
32
85
  <div
33
- v-for="association in associations"
86
+ v-for="(association, index) in associations"
34
87
  :key="association.label"
35
- class="flex flex-col gap-2"
88
+ class="flex flex-col"
36
89
  >
37
- <div class="flex items-baseline justify-between">
90
+ <button
91
+ type="button"
92
+ class="flex items-center gap-2 py-1 text-start"
93
+ :aria-expanded="openGroups.includes(association.label)"
94
+ :aria-controls="groupId(index)"
95
+ @click="toggleGroup(association.label)"
96
+ >
97
+ <UIcon
98
+ name="i-lucide-chevron-down"
99
+ class="size-5 shrink-0 text-muted transition-transform"
100
+ :class="{ '-rotate-90': !openGroups.includes(association.label) }"
101
+ />
38
102
  <span class="font-semibold text-highlighted">{{
39
103
  association.label
40
104
  }}</span>
41
- <span class="text-xs text-muted">optional</span>
42
- </div>
105
+ <span
106
+ class="ms-auto text-xs"
107
+ :class="
108
+ association.products.some(isSelected)
109
+ ? 'font-medium text-primary'
110
+ : 'text-muted'
111
+ "
112
+ >
113
+ {{ summary(association) }}
114
+ </span>
115
+ </button>
116
+
43
117
  <div
44
- class="flex flex-wrap gap-2"
45
- role="group"
46
- :aria-label="association.label"
118
+ v-if="openGroups.includes(association.label)"
119
+ :id="groupId(index)"
120
+ class="flex flex-col gap-1 pt-2"
47
121
  >
122
+ <UInput
123
+ v-if="association.products.length > SEARCH_THRESHOLD"
124
+ v-model="queries[association.label]"
125
+ icon="i-lucide-search"
126
+ :placeholder="`${association.label} durchsuchen`"
127
+ :aria-label="`${association.label} durchsuchen`"
128
+ class="mb-1 w-full"
129
+ />
130
+ <div
131
+ class="flex flex-col divide-y divide-default"
132
+ role="group"
133
+ :aria-label="association.label"
134
+ >
135
+ <UCheckbox
136
+ v-for="extra in visibleProducts(association)"
137
+ :key="extra.value"
138
+ variant="card"
139
+ size="lg"
140
+ :model-value="isSelected(extra)"
141
+ :ui="{
142
+ root: 'items-center rounded-none border-0 px-1 py-2.5',
143
+ wrapper: 'ms-3',
144
+ label: 'flex items-baseline justify-between gap-3 font-normal',
145
+ }"
146
+ @update:model-value="setSelected(extra, $event === true)"
147
+ >
148
+ <template #label>
149
+ <span>{{ extra.label }}</span>
150
+ <span class="shrink-0 text-sm text-muted tabular-nums">
151
+ +{{ extra.price }}
152
+ </span>
153
+ </template>
154
+ </UCheckbox>
155
+ </div>
156
+ <p
157
+ v-if="
158
+ queries[association.label]?.trim() &&
159
+ visibleProducts(association).length === 0
160
+ "
161
+ class="py-2 text-sm text-muted"
162
+ >
163
+ Keine Treffer
164
+ </p>
48
165
  <UButton
49
- v-for="extra in association.products"
50
- :key="extra.value"
51
- size="lg"
52
- class="rounded-full"
53
- :color="isSelected(extra) ? 'primary' : 'neutral'"
54
- :variant="isSelected(extra) ? 'subtle' : 'outline'"
55
- :icon="isSelected(extra) ? 'i-lucide-check' : 'i-lucide-plus'"
56
- :aria-pressed="isSelected(extra)"
57
- @click="toggle(extra)"
166
+ v-if="hiddenCount(association) > 0"
167
+ variant="link"
168
+ color="primary"
169
+ trailing-icon="i-lucide-chevron-down"
170
+ class="self-start px-1"
171
+ @click="expandedGroups = [...expandedGroups, association.label]"
58
172
  >
59
- {{ extra.label }}
60
- <span class="font-normal opacity-80">+{{ extra.price }}</span>
173
+ Alle {{ association.products.length }} anzeigen
61
174
  </UButton>
62
175
  </div>
63
176
  </div>
@@ -28,7 +28,14 @@ watch(deselected, () => emit("ingredients-deselected", deselected.value));
28
28
 
29
29
  <template>
30
30
  <div v-if="ingredients.length > 0" class="flex flex-col gap-2">
31
- <span class="font-semibold text-highlighted">Ohne</span>
31
+ <!-- The quick view lists the ingredients only here (no chip row above
32
+ repeating them): tapping one removes it from the order. Both states
33
+ carry an icon of the same size, so toggling a chip keeps its width
34
+ and never rewraps the row (the drawer grew on phones). -->
35
+ <div class="flex items-baseline justify-between">
36
+ <span class="font-semibold text-highlighted">Zutaten</span>
37
+ <span class="text-xs text-muted">antippen zum Entfernen</span>
38
+ </div>
32
39
  <div
33
40
  class="flex flex-wrap gap-2"
34
41
  role="group"
@@ -42,7 +49,7 @@ watch(deselected, () => emit("ingredients-deselected", deselected.value));
42
49
  :class="{ 'line-through': deselected.includes(ingredient) }"
43
50
  :color="deselected.includes(ingredient) ? 'error' : 'neutral'"
44
51
  :variant="deselected.includes(ingredient) ? 'subtle' : 'outline'"
45
- :icon="deselected.includes(ingredient) ? 'i-lucide-x' : undefined"
52
+ :icon="deselected.includes(ingredient) ? 'i-lucide-plus' : 'i-lucide-x'"
46
53
  :aria-pressed="deselected.includes(ingredient)"
47
54
  :label="ingredient"
48
55
  @click="toggle(ingredient)"
@@ -53,9 +53,10 @@ const onAddToCart = () => emit("product-added");
53
53
  </script>
54
54
 
55
55
  <template>
56
- <div class="flex flex-col gap-5">
57
- <!-- One placeholder in the shape of the loaded body (options, extras,
58
- ingredients), shown until product and extras are both loaded. -->
56
+ <div class="flex flex-1 flex-col gap-5">
57
+ <!-- One placeholder in the shape of the loaded body (options,
58
+ ingredients, extras), shown until product and extras are both
59
+ loaded. -->
59
60
  <div v-if="pending" class="flex flex-col gap-5" aria-busy="true">
60
61
  <div class="flex flex-col gap-2">
61
62
  <USkeleton class="h-5 w-24" />
@@ -64,18 +65,15 @@ const onAddToCart = () => emit("product-added");
64
65
  <div class="flex flex-col gap-2">
65
66
  <USkeleton class="h-5 w-20" />
66
67
  <div class="flex flex-wrap gap-2">
67
- <USkeleton class="h-10 w-32 rounded-full" />
68
- <USkeleton class="h-10 w-28 rounded-full" />
69
- <USkeleton class="h-10 w-36 rounded-full" />
70
- <USkeleton class="h-10 w-24 rounded-full" />
68
+ <USkeleton class="h-8 w-20 rounded-full" />
69
+ <USkeleton class="h-8 w-24 rounded-full" />
70
+ <USkeleton class="h-8 w-16 rounded-full" />
71
+ <USkeleton class="h-8 w-28 rounded-full" />
71
72
  </div>
72
73
  </div>
73
- <div class="flex flex-col gap-2">
74
- <USkeleton class="h-5 w-16" />
75
- <div class="flex flex-wrap gap-2">
76
- <USkeleton class="h-10 w-28 rounded-full" />
77
- <USkeleton class="h-10 w-24 rounded-full" />
78
- </div>
74
+ <div class="flex flex-col gap-3">
75
+ <USkeleton class="h-5 w-28" />
76
+ <USkeleton v-for="row in 4" :key="row" class="h-7 w-full" />
79
77
  </div>
80
78
  </div>
81
79
  <template v-else-if="productDetails?.configurator">
@@ -84,16 +82,16 @@ const onAddToCart = () => emit("product-added");
84
82
  :c="productDetails.configurator"
85
83
  @variant-switched="onVariantSwitched"
86
84
  />
87
- <ProductCrossSelling
88
- v-if="associationItems.length > 0"
89
- :associations="associationItems"
90
- @extras-selected="onExtras"
91
- />
92
85
  <ProductDeselectIngredient
93
86
  v-if="selectedProduct"
94
87
  :product="selectedProduct"
95
88
  @ingredients-deselected="onIngredientsDeselected"
96
89
  />
90
+ <ProductCrossSelling
91
+ v-if="associationItems.length > 0"
92
+ :associations="associationItems"
93
+ @extras-selected="onExtras"
94
+ />
97
95
  </template>
98
96
 
99
97
  <div
@@ -61,10 +61,11 @@ function onVariantSelected(variant: Schemas["Product"]) {
61
61
  {{ description }}
62
62
  </template>
63
63
  <template #body>
64
- <ProductCardIngredients
65
- :sorted-properties="sortedProperties"
66
- :with-diet-badges="true"
67
- />
64
+ <!-- Diet badges only: the ingredients are listed once, in the
65
+ deselectable "Zutaten" section of ProductDetail. -->
66
+ <div class="flex flex-wrap gap-1.5 empty:hidden">
67
+ <ProductCardDietBadges :sorted-properties="sortedProperties" />
68
+ </div>
68
69
  <ProductDetail
69
70
  v-if="product"
70
71
  :key="product.id"
@@ -7,11 +7,17 @@ export type ServiceInterval = { start: Date; end: Date };
7
7
  export function useBusinessHours() {
8
8
  const { apiClient } = useShopwareContext();
9
9
 
10
- const { data, pending, refresh } = useAsyncData(
10
+ const { data, pending, status, refresh } = useAsyncData(
11
11
  "business-hours",
12
12
  async () => {
13
- const response = await apiClient.invoke(
14
- "shopbite.business-hour.get get /shopbite/business-hour",
13
+ // Retried in the browser only: on the server a retry would delay the
14
+ // page, and app.vue loads the data again after mounting (#355).
15
+ const response = await withRetries(
16
+ () =>
17
+ apiClient.invoke(
18
+ "shopbite.business-hour.get get /shopbite/business-hour",
19
+ ),
20
+ import.meta.client ? OPENING_HOURS_RETRY_DELAYS : [],
15
21
  );
16
22
 
17
23
  return response.data.businessHours;
@@ -154,6 +160,7 @@ export function useBusinessHours() {
154
160
  return {
155
161
  businessHours: data,
156
162
  isLoading: pending,
163
+ status,
157
164
  refresh,
158
165
  isStoreOpen,
159
166
  getServiceIntervals,
@@ -3,11 +3,14 @@ import { useShopwareContext } from "#imports";
3
3
  export function useHolidays() {
4
4
  const { apiClient } = useShopwareContext();
5
5
 
6
- const { data, pending, refresh } = useAsyncData(
6
+ const { data, pending, status, refresh } = useAsyncData(
7
7
  "holidays",
8
8
  async () => {
9
- const response = await apiClient.invoke(
10
- "shopbite.holiday.get get /shopbite/holiday",
9
+ // Retried in the browser only: on the server a retry would delay the
10
+ // page, and app.vue loads the data again after mounting (#355).
11
+ const response = await withRetries(
12
+ () => apiClient.invoke("shopbite.holiday.get get /shopbite/holiday"),
13
+ import.meta.client ? OPENING_HOURS_RETRY_DELAYS : [],
11
14
  );
12
15
 
13
16
  return response.data.holidays;
@@ -36,6 +39,7 @@ export function useHolidays() {
36
39
  holidays: data,
37
40
  isClosedHoliday,
38
41
  isLoading: pending,
42
+ status,
39
43
  refresh,
40
44
  };
41
45
  }
@@ -0,0 +1,53 @@
1
+ /** Delays before the browser requests business hours or holidays again. */
2
+ export const OPENING_HOURS_RETRY_DELAYS = [1000, 3000] as const;
3
+
4
+ /**
5
+ * Load state of business hours and holidays, which app.vue fetches after
6
+ * mounting (#349, #355). `hasFailed` once a request failed after its retries
7
+ * and no attempt is running; `retry()` requests the missing data again.
8
+ *
9
+ * `hasFailed` stays `false` until the calling component is mounted: an error
10
+ * from a server prefetch (footer) would otherwise render differently on the
11
+ * server, where the checkout was rendered before it, and at hydration.
12
+ */
13
+ export function useOpeningHoursData() {
14
+ const {
15
+ businessHours,
16
+ status: businessHoursStatus,
17
+ refresh: refreshBusinessHours,
18
+ } = useBusinessHours();
19
+ const {
20
+ holidays,
21
+ status: holidaysStatus,
22
+ refresh: refreshHolidays,
23
+ } = useHolidays();
24
+
25
+ const isMounted = ref(false);
26
+ onMounted(() => {
27
+ isMounted.value = true;
28
+ });
29
+
30
+ const isLoaded = computed(() =>
31
+ Boolean(businessHours.value && holidays.value),
32
+ );
33
+
34
+ const hasFailed = computed(() => {
35
+ if (!isMounted.value || isLoaded.value) return false;
36
+ const missing = [
37
+ businessHours.value ? null : businessHoursStatus.value,
38
+ holidays.value ? null : holidaysStatus.value,
39
+ ].filter((status) => status !== null);
40
+ return missing.includes("error") && !missing.includes("pending");
41
+ });
42
+
43
+ const isLoading = computed(() => !isLoaded.value && !hasFailed.value);
44
+
45
+ async function retry(): Promise<void> {
46
+ await Promise.all([
47
+ businessHours.value ? undefined : refreshBusinessHours(),
48
+ holidays.value ? undefined : refreshHolidays(),
49
+ ]);
50
+ }
51
+
52
+ return { isLoaded, isLoading, hasFailed, retry };
53
+ }
@@ -5,13 +5,10 @@ useSeoMeta({
5
5
  });
6
6
 
7
7
  const { isLoggedIn, isGuestSession } = useUser();
8
- const { setStep } = useCheckoutStore();
9
8
 
10
9
  if (!isLoggedIn.value && !isGuestSession.value) {
11
10
  await navigateTo("/bestellung/warenkorb");
12
11
  }
13
-
14
- setStep(2);
15
12
  </script>
16
13
 
17
14
  <template>
@@ -6,9 +6,6 @@ useSeoMeta({
6
6
 
7
7
  const { isLoggedIn, isGuestSession } = useUser();
8
8
  const { isEmpty } = useCart();
9
- const { setStep } = useCheckoutStore();
10
-
11
- setStep(0);
12
9
 
13
10
  const isCustomerAvailable = computed<boolean>(() => {
14
11
  return isLoggedIn.value || isGuestSession.value;
@@ -5,13 +5,10 @@ useSeoMeta({
5
5
  });
6
6
 
7
7
  const { isLoggedIn, isGuestSession } = useUser();
8
- const { setStep } = useCheckoutStore();
9
8
 
10
9
  if (!isLoggedIn.value && !isGuestSession.value) {
11
10
  await navigateTo("/bestellung/warenkorb");
12
11
  }
13
-
14
- setStep(1);
15
12
  </script>
16
13
 
17
14
  <template>
@@ -1,15 +1,34 @@
1
1
  <script setup lang="ts">
2
2
  import type { StepperItem } from "@nuxt/ui";
3
3
 
4
- const checkoutStore = useCheckoutStore();
5
- const { step } = storeToRefs(checkoutStore);
6
-
7
4
  const stepRoutes = [
8
5
  "/bestellung/warenkorb",
9
6
  "/bestellung/zahlung-versand",
10
7
  "/bestellung/bestaetigen",
11
8
  ] as const;
12
9
 
10
+ const route = useRoute();
11
+ const isPaymentReturnRoute = computed(() =>
12
+ /^\/bestellung\/[0-9a-f]{32}(\/erfolg|\/fehler)?$/.test(route.path),
13
+ );
14
+
15
+ // The active step follows the route, so the server renders the same step the
16
+ // browser hydrates. Setting it from the child pages ran after the stepper had
17
+ // been rendered on the server (#339).
18
+ const step = computed<number>({
19
+ get: () =>
20
+ Math.max(
21
+ 0,
22
+ stepRoutes.findIndex((path) => path === route.path),
23
+ ),
24
+ set: (index) => {
25
+ const path = stepRoutes[index];
26
+ if (path && path !== route.path) {
27
+ navigateTo(path);
28
+ }
29
+ },
30
+ });
31
+
13
32
  const items = computed(
14
33
  () =>
15
34
  [
@@ -30,17 +49,6 @@ const items = computed(
30
49
  },
31
50
  ] satisfies StepperItem[],
32
51
  );
33
-
34
- const route = useRoute();
35
- const isPaymentReturnRoute = computed(() =>
36
- /^\/bestellung\/[0-9a-f]{32}(\/erfolg|\/fehler)?$/.test(route.path),
37
- );
38
- watch(step, (newStep) => {
39
- if (isPaymentReturnRoute.value) {
40
- return;
41
- }
42
- navigateTo(stepRoutes[newStep]);
43
- });
44
52
  </script>
45
53
 
46
54
  <template>
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Runs `request` and, when it throws, runs it again after each of `delays`
3
+ * (milliseconds). The error of the last attempt is thrown.
4
+ */
5
+ export async function withRetries<T>(
6
+ request: () => Promise<T>,
7
+ delays: readonly number[],
8
+ ): Promise<T> {
9
+ for (const delay of delays) {
10
+ try {
11
+ return await request();
12
+ } catch {
13
+ await new Promise((resolve) => setTimeout(resolve, delay));
14
+ }
15
+ }
16
+ return request();
17
+ }