@shopbite-de/storefront 1.24.0 → 1.26.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/.env.example +3 -0
- package/CLAUDE.md +10 -3
- package/README.md +0 -1
- package/app/app.config.ts +3 -2
- package/app/app.vue +4 -1
- package/app/assets/css/main.css +16 -0
- package/app/components/AddToWishlist.vue +13 -6
- package/app/components/Cart/Bar.vue +102 -0
- package/app/components/Cart/QuickView.vue +4 -0
- package/app/components/Cart/Upsell.vue +106 -0
- package/app/components/Category/Listing.vue +11 -3
- package/app/components/Checkout/DeliveryTimeSelect.vue +28 -2
- package/app/components/Checkout/Summary.vue +25 -3
- package/app/components/DemoBanner.vue +13 -0
- package/app/components/Feature/Card.vue +121 -0
- package/app/components/Features.vue +14 -9
- package/app/components/Footer/Contact.vue +5 -1
- package/app/components/Header/Right.vue +44 -15
- package/app/components/Hero.vue +126 -36
- package/app/components/Product/Card.vue +102 -50
- package/app/components/Product/CardCompact.vue +72 -0
- package/app/components/Product/CardDietBadges.vue +38 -31
- package/app/components/Product/CardIngredients.vue +35 -0
- package/app/components/Product/CardSkeleton.vue +10 -18
- package/app/components/Product/Category.vue +9 -2
- package/app/components/Product/Configurator.vue +11 -7
- package/app/components/Product/CrossSelling.vue +45 -34
- package/app/components/Product/DeselectIngredient.vue +37 -31
- package/app/components/Product/Detail.vue +73 -13
- package/app/components/Product/QuickView.vue +77 -0
- package/app/components/Topseller.vue +44 -34
- package/app/composables/useAddToCart.ts +3 -30
- package/app/composables/useBusinessHours.ts +10 -3
- package/app/composables/useCartQuickView.ts +19 -0
- package/app/composables/useCartUpsell.ts +100 -0
- package/app/composables/useCategorySeo.ts +5 -4
- package/app/composables/useHolidays.ts +7 -3
- package/app/composables/useOpeningHoursData.ts +53 -0
- package/app/composables/useProductCartQuantity.ts +15 -0
- package/app/composables/useProductCrossSelling.ts +1 -0
- package/app/composables/useProductDetail.ts +15 -1
- package/app/composables/useProductEvents.ts +30 -0
- package/app/composables/useProductQuickView.ts +65 -0
- package/app/composables/useTopSellers.ts +22 -0
- package/app/composables/useTrackEvent.ts +7 -0
- package/app/pages/bestellung/bestaetigen.vue +0 -3
- package/app/pages/bestellung/warenkorb.vue +0 -3
- package/app/pages/bestellung/zahlung-versand.vue +0 -3
- package/app/pages/bestellung.vue +22 -14
- package/app/pages/index.vue +3 -1
- package/app/pages/suche.vue +18 -5
- package/app/types/Association.d.ts +1 -0
- package/app/utils/openingHours.ts +31 -8
- package/app/utils/product.ts +31 -0
- package/app/utils/retry.ts +17 -0
- package/content/index.yml +16 -11
- package/content.config.ts +13 -0
- package/docs/notes/2026-09-12-issue-319-stylesheet-cost.md +154 -0
- package/docs/notes/2026-09-12-issue-325-product-card.md +100 -0
- package/docs/notes/2026-09-12-issue-327-home-hero.md +64 -0
- package/docs/notes/2026-09-13-demo-banner.md +32 -0
- package/docs/notes/2026-09-13-issue-332-home-info-cards.md +46 -0
- package/docs/notes/2026-09-13-quick-view-flicker.md +65 -0
- package/docs/notes/2026-09-14-cart-upsell.md +105 -0
- package/docs/notes/2026-09-14-demo-noindex.md +57 -0
- package/docs/notes/2026-09-16-issue-339-checkout-hydration.md +49 -0
- package/docs/notes/2026-09-16-issue-349-order-button-loading.md +39 -0
- package/docs/notes/2026-09-16-issue-350-remove-pinia.md +41 -0
- package/docs/notes/2026-09-16-issue-355-opening-hours-error.md +57 -0
- package/nuxt.config.ts +25 -2
- package/package.json +2 -3
- package/scripts/perf/first-render.mjs +30 -0
- package/scripts/perf/h2-proxy.cjs +49 -0
- package/scripts/perf/lighthouse.sh +22 -0
- package/scripts/perf/quick-view-layout.mjs +126 -0
- package/server/api/listing/[categoryId].get.ts +2 -0
- package/server/api/search.get.ts +2 -0
- package/test/e2e/simple-checkout-as-recurring-customer.test.ts +13 -17
- package/test/nuxt/CartBar.test.ts +110 -0
- package/test/nuxt/CartUpsell.test.ts +125 -0
- package/test/nuxt/CheckoutSummary.test.ts +127 -0
- package/test/nuxt/DemoBanner.test.ts +12 -0
- package/test/nuxt/useAddToCart.test.ts +6 -19
- package/test/nuxt/useCartUpsell.test.ts +126 -0
- package/test/nuxt/useOpeningHoursData.test.ts +120 -0
- package/test/nuxt/useTrackEvent.test.ts +15 -0
- package/test/unit/openingHours.spec.ts +32 -1
- package/test/unit/product.spec.ts +72 -0
- package/test/unit/retry.spec.ts +58 -0
- package/test/unit/useCategorySeo.spec.ts +2 -1
- package/test/visual/playwright.config.ts +33 -0
- package/test/visual/visual.spec.ts +87 -0
- package/app/components/Product/CardDescription.vue +0 -27
- package/app/components/Product/CardFooter.vue +0 -61
- package/app/composables/useCheckoutStore.ts +0 -1
- package/app/stores/checkout.ts +0 -22
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Schemas } from "#shopware";
|
|
3
|
+
import { useMediaQuery } from "@vueuse/core";
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
product: Schemas["Product"] | undefined;
|
|
7
|
+
}>();
|
|
8
|
+
|
|
9
|
+
const open = defineModel<boolean>("open", { required: true });
|
|
10
|
+
|
|
11
|
+
// Bottom sheet on phones, side panel from the lg breakpoint (64rem).
|
|
12
|
+
const isDesktop = useMediaQuery("(min-width: 64rem)");
|
|
13
|
+
const direction = computed(() => (isDesktop.value ? "right" : "bottom"));
|
|
14
|
+
|
|
15
|
+
const sortedProperties = computed(
|
|
16
|
+
() =>
|
|
17
|
+
props.product?.sortedProperties as Schemas["PropertyGroup"][] | undefined,
|
|
18
|
+
);
|
|
19
|
+
const label = ref(props.product?.translated.name ?? props.product?.name ?? "");
|
|
20
|
+
const description = ref(props.product?.description);
|
|
21
|
+
|
|
22
|
+
watch(
|
|
23
|
+
() => props.product,
|
|
24
|
+
(product) => {
|
|
25
|
+
if (!product) return;
|
|
26
|
+
label.value = product.translated.name ?? product.name;
|
|
27
|
+
description.value = product.description;
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
function onVariantSelected(variant: Schemas["Product"]) {
|
|
32
|
+
label.value = variant.translated.name ?? variant.name;
|
|
33
|
+
description.value = variant.translated.description ?? variant.description;
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<!-- Only the body scrolls: header and footer stay in place without sticky
|
|
39
|
+
positioning, and shrink-0 keeps the flex column from squeezing the
|
|
40
|
+
header to its min-height (#325). -->
|
|
41
|
+
<UDrawer
|
|
42
|
+
v-model:open="open"
|
|
43
|
+
:direction="direction"
|
|
44
|
+
:close="true"
|
|
45
|
+
:ui="{
|
|
46
|
+
content: direction === 'right' ? 'w-full max-w-md' : 'max-h-[92vh]',
|
|
47
|
+
container: 'overflow-hidden',
|
|
48
|
+
header: 'shrink-0 items-start border-b border-default pb-3',
|
|
49
|
+
body: 'flex min-h-0 flex-col gap-5 overflow-y-auto',
|
|
50
|
+
}"
|
|
51
|
+
>
|
|
52
|
+
<template #title>
|
|
53
|
+
<span class="flex flex-col gap-0.5">
|
|
54
|
+
<span class="text-xs font-semibold text-primary">
|
|
55
|
+
#{{ product?.productNumber }}
|
|
56
|
+
</span>
|
|
57
|
+
<span class="text-xl font-bold text-highlighted">{{ label }}</span>
|
|
58
|
+
</span>
|
|
59
|
+
</template>
|
|
60
|
+
<template v-if="description" #description>
|
|
61
|
+
{{ description }}
|
|
62
|
+
</template>
|
|
63
|
+
<template #body>
|
|
64
|
+
<ProductCardIngredients
|
|
65
|
+
:sorted-properties="sortedProperties"
|
|
66
|
+
:with-diet-badges="true"
|
|
67
|
+
/>
|
|
68
|
+
<ProductDetail
|
|
69
|
+
v-if="product"
|
|
70
|
+
:key="product.id"
|
|
71
|
+
:product-id="product.id"
|
|
72
|
+
@product-added="open = false"
|
|
73
|
+
@variant-selected="onVariantSelected"
|
|
74
|
+
/>
|
|
75
|
+
</template>
|
|
76
|
+
</UDrawer>
|
|
77
|
+
</template>
|
|
@@ -1,43 +1,53 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// Top sellers as a horizontal snap scroller below the hero (#327); a tap
|
|
3
|
+
// opens the product quick view (#325). Renders nothing without top sellers.
|
|
4
4
|
const { loadTopSellers } = useTopSellers();
|
|
5
5
|
|
|
6
|
-
const topSellers = await
|
|
6
|
+
const { data: topSellers } = await useAsyncData("top-sellers", () =>
|
|
7
|
+
loadTopSellers(),
|
|
8
|
+
);
|
|
7
9
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
label: "Zur Speisekarte",
|
|
11
|
-
to: "/speisekarte",
|
|
12
|
-
color: "primary",
|
|
13
|
-
variant: "subtle",
|
|
14
|
-
trailingIcon: "i-lucide-arrow-right",
|
|
15
|
-
},
|
|
16
|
-
]);
|
|
10
|
+
const products = computed(() => topSellers.value ?? []);
|
|
11
|
+
const quickView = useProductQuickView(products);
|
|
17
12
|
</script>
|
|
18
13
|
|
|
19
14
|
<template>
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
<section v-if="products.length > 0" aria-labelledby="top-sellers-title">
|
|
16
|
+
<UContainer class="flex flex-col gap-3 pt-6 sm:pt-8">
|
|
17
|
+
<div class="flex items-baseline justify-between gap-4">
|
|
18
|
+
<h2
|
|
19
|
+
id="top-sellers-title"
|
|
20
|
+
class="text-xl font-extrabold tracking-tight text-highlighted sm:text-2xl"
|
|
21
|
+
>
|
|
22
|
+
Beliebt bei unseren Gästen
|
|
23
|
+
</h2>
|
|
24
|
+
<UButton
|
|
25
|
+
label="Speisekarte"
|
|
26
|
+
to="/speisekarte/"
|
|
27
|
+
variant="link"
|
|
28
|
+
color="primary"
|
|
29
|
+
trailing-icon="i-lucide-arrow-right"
|
|
30
|
+
class="shrink-0 px-0"
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</UContainer>
|
|
34
|
+
<!-- Scrolls edge to edge on phones, padded like the container. -->
|
|
35
|
+
<div
|
|
36
|
+
class="flex snap-x snap-mandatory gap-3 overflow-x-auto px-4 py-2 pb-4 sm:px-6 lg:px-8 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
|
25
37
|
>
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</AnimatedSection>
|
|
42
|
-
</div>
|
|
38
|
+
<div class="mx-auto flex w-full max-w-(--ui-container) gap-3">
|
|
39
|
+
<ProductCardCompact
|
|
40
|
+
v-for="product in products"
|
|
41
|
+
:key="product.id"
|
|
42
|
+
:product="product"
|
|
43
|
+
@select="quickView.show"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<LazyProductQuickView
|
|
48
|
+
v-if="quickView.mounted.value"
|
|
49
|
+
v-model:open="quickView.open.value"
|
|
50
|
+
:product="quickView.product.value"
|
|
51
|
+
/>
|
|
52
|
+
</section>
|
|
43
53
|
</template>
|
|
@@ -4,14 +4,13 @@ import { v5 as uuidv5, v4 as uuidv4 } from "uuid";
|
|
|
4
4
|
import { computed, ref } from "vue";
|
|
5
5
|
|
|
6
6
|
const UUID_NAMESPACE = "b098ef7e-0fa2-4073-b002-7ceec4360fbf";
|
|
7
|
-
const CART_SUCCESS_TITLE = "Gute Wahl!";
|
|
8
7
|
const LINE_ITEM_PRODUCT = "product";
|
|
9
8
|
const LINE_ITEM_CONTAINER = "container";
|
|
10
9
|
|
|
11
10
|
export function useAddToCart() {
|
|
12
11
|
const { addLineItems } = useCartMutations();
|
|
13
|
-
|
|
14
|
-
const {
|
|
12
|
+
// Feedback is the cart bar / header badge animation, not a toast (#325).
|
|
13
|
+
const { triggerCartItemAdded } = useProductEvents();
|
|
15
14
|
const { trackAddToCart: trackAddToCartEvent } = useTrackEvent();
|
|
16
15
|
|
|
17
16
|
const selectedExtras = ref<AssociationItemProduct[]>([]);
|
|
@@ -45,12 +44,6 @@ export function useAddToCart() {
|
|
|
45
44
|
"-",
|
|
46
45
|
);
|
|
47
46
|
|
|
48
|
-
console.log(
|
|
49
|
-
selectedProduct.value.translated.name,
|
|
50
|
-
extrasFormatted,
|
|
51
|
-
removedFormatted,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
47
|
return `${selectedProduct.value.translated.name}${extrasFormatted}${removedFormatted}`;
|
|
55
48
|
});
|
|
56
49
|
|
|
@@ -118,25 +111,6 @@ export function useAddToCart() {
|
|
|
118
111
|
];
|
|
119
112
|
}
|
|
120
113
|
|
|
121
|
-
async function showSuccessToast() {
|
|
122
|
-
if (!selectedProduct.value) return;
|
|
123
|
-
|
|
124
|
-
toast.add({
|
|
125
|
-
title: CART_SUCCESS_TITLE,
|
|
126
|
-
description: `${selectedProduct.value.translated.name} wurde in den Warenkorb gelegt.`,
|
|
127
|
-
icon: "i-lucide-shopping-cart",
|
|
128
|
-
color: "primary",
|
|
129
|
-
progress: true,
|
|
130
|
-
duration: 2000,
|
|
131
|
-
actions: [
|
|
132
|
-
{
|
|
133
|
-
label: "Zum Warenkorb",
|
|
134
|
-
to: "/bestellung/warenkorb",
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
114
|
async function addToCart(onSuccess?: () => void) {
|
|
141
115
|
if (!selectedProduct.value || isLoading.value) return;
|
|
142
116
|
isLoading.value = true;
|
|
@@ -146,8 +120,7 @@ export function useAddToCart() {
|
|
|
146
120
|
const newCart = await addLineItems(createCartItems());
|
|
147
121
|
if (!newCart) return;
|
|
148
122
|
|
|
149
|
-
|
|
150
|
-
triggerProductAdded();
|
|
123
|
+
triggerCartItemAdded(selectedProduct.value, selectedQuantity.value);
|
|
151
124
|
trackAddToCartEvent(selectedProduct.value, selectedQuantity.value);
|
|
152
125
|
onSuccess?.();
|
|
153
126
|
} finally {
|
|
@@ -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
|
-
|
|
14
|
-
|
|
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,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared state of the cart drawer (Header/Right.vue), so the header button
|
|
3
|
+
* and the sticky cart bar open the same drawer. The drawer (vaul) is created
|
|
4
|
+
* on first use instead of on every page (#314).
|
|
5
|
+
*/
|
|
6
|
+
export function useCartQuickView() {
|
|
7
|
+
const open = useState("cart-quick-view-open", () => false);
|
|
8
|
+
const mounted = useState("cart-quick-view-mounted", () => false);
|
|
9
|
+
|
|
10
|
+
async function show() {
|
|
11
|
+
if (!mounted.value) {
|
|
12
|
+
mounted.value = true;
|
|
13
|
+
await nextTick();
|
|
14
|
+
}
|
|
15
|
+
open.value = true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return { open, mounted, show };
|
|
19
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Schemas } from "#shopware";
|
|
2
|
+
|
|
3
|
+
const UPSELL_LIMIT = 6;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Suggestions on the order confirmation step (#338): products flagged with the custom
|
|
7
|
+
* field `shopbite_cart_upsell`, added with quantity 1 in one click. Named
|
|
8
|
+
* "upsell" because "cross-selling" already means the extras of a product.
|
|
9
|
+
*/
|
|
10
|
+
export function useCartUpsell() {
|
|
11
|
+
const { apiClient } = useShopwareContext();
|
|
12
|
+
const { addLineItems } = useCartMutations();
|
|
13
|
+
const { triggerCartItemAdded } = useProductEvents();
|
|
14
|
+
const { trackUpsellAdd } = useTrackEvent();
|
|
15
|
+
|
|
16
|
+
const pendingProductIds = ref(new Set<string>());
|
|
17
|
+
|
|
18
|
+
async function loadUpsellProducts(): Promise<Schemas["Product"][]> {
|
|
19
|
+
try {
|
|
20
|
+
const result = await apiClient.invoke("readProduct post /product", {
|
|
21
|
+
// A flag on a variant parent applies to all its variants.
|
|
22
|
+
|
|
23
|
+
// @ts-expect-error sw-inheritance is missing from the generated header type
|
|
24
|
+
headers: { "sw-inheritance": "true" },
|
|
25
|
+
body: {
|
|
26
|
+
filter: [
|
|
27
|
+
{
|
|
28
|
+
type: "equals",
|
|
29
|
+
field: "customFields.shopbite_cart_upsell",
|
|
30
|
+
value: true,
|
|
31
|
+
},
|
|
32
|
+
// No variant parents: one click cannot choose a variant. Shopware
|
|
33
|
+
// only counts the children of main products, so the child count
|
|
34
|
+
// of a variant is null, not 0.
|
|
35
|
+
{
|
|
36
|
+
type: "multi",
|
|
37
|
+
operator: "or",
|
|
38
|
+
queries: [
|
|
39
|
+
{ type: "equals", field: "childCount", value: 0 },
|
|
40
|
+
{ type: "equals", field: "childCount", value: null },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
limit: UPSELL_LIMIT,
|
|
45
|
+
sort: [{ field: "name", order: "ASC" }],
|
|
46
|
+
includes: {
|
|
47
|
+
product: [
|
|
48
|
+
"id",
|
|
49
|
+
"productNumber",
|
|
50
|
+
"name",
|
|
51
|
+
"translated",
|
|
52
|
+
"calculatedPrice",
|
|
53
|
+
"available",
|
|
54
|
+
"cover",
|
|
55
|
+
],
|
|
56
|
+
calculated_price: ["totalPrice"],
|
|
57
|
+
product_media: ["media"],
|
|
58
|
+
media: ["url", "thumbnails"],
|
|
59
|
+
media_thumbnail: ["url", "width"],
|
|
60
|
+
},
|
|
61
|
+
associations: {
|
|
62
|
+
cover: { associations: { media: {} } },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return result.data.elements;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error("[useCartUpsell][loadUpsellProducts]", e);
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isAdding(productId: string): boolean {
|
|
74
|
+
return pendingProductIds.value.has(productId);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function addUpsellProduct(product: Schemas["Product"]): Promise<void> {
|
|
78
|
+
if (isAdding(product.id)) return;
|
|
79
|
+
pendingProductIds.value.add(product.id);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
// Failures are reported by useCartMutations; it resolves undefined.
|
|
83
|
+
const newCart = await addLineItems([
|
|
84
|
+
{ id: product.id, quantity: 1, type: "product" },
|
|
85
|
+
]);
|
|
86
|
+
if (!newCart) return;
|
|
87
|
+
|
|
88
|
+
triggerCartItemAdded(product, 1);
|
|
89
|
+
trackUpsellAdd(product, 1);
|
|
90
|
+
} finally {
|
|
91
|
+
pendingProductIds.value.delete(product.id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
loadUpsellProducts,
|
|
97
|
+
addUpsellProduct,
|
|
98
|
+
isAdding,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -39,10 +39,11 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
39
39
|
|
|
40
40
|
const siteName = computed(() => config.public.site?.name || "");
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// Only inactive categories get their own rule; otherwise @nuxtjs/robots
|
|
43
|
+
// renders the site rule, which is noindex on the demo shop.
|
|
44
|
+
const robots = computed(() =>
|
|
45
|
+
category.value?.active === false ? "noindex,nofollow" : undefined,
|
|
46
|
+
);
|
|
46
47
|
|
|
47
48
|
const canonicalUrl = computed(() => seoUrl.value || "");
|
|
48
49
|
|
|
@@ -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
|
-
|
|
10
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quantity of a product in the cart, across plain line items and the
|
|
3
|
+
* container items that carry extras (the product is the first child, #325).
|
|
4
|
+
*/
|
|
5
|
+
export function useProductCartQuantity(getProductId: () => string) {
|
|
6
|
+
const { cartItems } = useCart();
|
|
7
|
+
|
|
8
|
+
const quantity = computed(() =>
|
|
9
|
+
cartItems.value
|
|
10
|
+
.filter((item) => lineItemHoldsProduct(item, getProductId()))
|
|
11
|
+
.reduce((sum, item) => sum + (item.quantity ?? 0), 0),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return { quantity };
|
|
15
|
+
}
|
|
@@ -4,13 +4,26 @@ import type { AssociationItemProduct } from "~/types/Association";
|
|
|
4
4
|
export function useProductDetail(getProductId: () => string) {
|
|
5
5
|
const { trackProductView } = useTrackEvent();
|
|
6
6
|
|
|
7
|
-
const { data: productDetails, pending } = useFetch<{
|
|
7
|
+
const { data: productDetails, pending: isDetailLoading } = useFetch<{
|
|
8
8
|
product: Schemas["Product"];
|
|
9
9
|
configurator?: Schemas["PropertyGroup"][];
|
|
10
10
|
}>(() => `/api/product/${getProductId()}`, {
|
|
11
11
|
key: () => `product-${getProductId() ?? "none"}`,
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
// The extras belong to the product family: the backend resolves the
|
|
15
|
+
// cross-selling of a variant to the one of its parent. Keyed by the listing
|
|
16
|
+
// product, the request runs alongside the detail request instead of after
|
|
17
|
+
// it, and switching a variant does not reload the extras. Together with the
|
|
18
|
+
// single loading state below this keeps the quick view from re-rendering
|
|
19
|
+
// in stages (skeleton, options, extras).
|
|
20
|
+
const { associationItems, isAssociationsLoading } =
|
|
21
|
+
useProductCrossSelling(getProductId);
|
|
22
|
+
|
|
23
|
+
const pending = computed(
|
|
24
|
+
() => isDetailLoading.value || isAssociationsLoading.value,
|
|
25
|
+
);
|
|
26
|
+
|
|
14
27
|
const {
|
|
15
28
|
selectedProduct,
|
|
16
29
|
selectedQuantity,
|
|
@@ -50,6 +63,7 @@ export function useProductDetail(getProductId: () => string) {
|
|
|
50
63
|
|
|
51
64
|
return {
|
|
52
65
|
productDetails,
|
|
66
|
+
associationItems,
|
|
53
67
|
pending,
|
|
54
68
|
selectedProduct,
|
|
55
69
|
selectedQuantity,
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
+
import type { Schemas } from "#shopware";
|
|
1
2
|
import { ref, watch } from "vue";
|
|
2
3
|
|
|
4
|
+
export type CartAddition = {
|
|
5
|
+
id: number;
|
|
6
|
+
product: Schemas["Product"];
|
|
7
|
+
quantity: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
3
10
|
const productAddedTrigger = ref(0);
|
|
11
|
+
const lastCartAddition = ref<CartAddition | null>(null);
|
|
4
12
|
|
|
5
13
|
export const useProductEvents = () => {
|
|
14
|
+
/** Product added to the cart or the wishlist; closes the search. */
|
|
6
15
|
const triggerProductAdded = () => {
|
|
7
16
|
productAddedTrigger.value++;
|
|
8
17
|
};
|
|
9
18
|
|
|
19
|
+
/** A product went into the cart; the cart bar and the header badge react (#325). */
|
|
20
|
+
const triggerCartItemAdded = (
|
|
21
|
+
product: Schemas["Product"],
|
|
22
|
+
quantity: number,
|
|
23
|
+
) => {
|
|
24
|
+
lastCartAddition.value = {
|
|
25
|
+
id: productAddedTrigger.value + 1,
|
|
26
|
+
product,
|
|
27
|
+
quantity,
|
|
28
|
+
};
|
|
29
|
+
triggerProductAdded();
|
|
30
|
+
};
|
|
31
|
+
|
|
10
32
|
const onProductAdded = (callback: () => void) => {
|
|
11
33
|
watch(productAddedTrigger, () => {
|
|
12
34
|
if (productAddedTrigger.value > 0) {
|
|
@@ -15,8 +37,16 @@ export const useProductEvents = () => {
|
|
|
15
37
|
});
|
|
16
38
|
};
|
|
17
39
|
|
|
40
|
+
const onCartItemAdded = (callback: (addition: CartAddition) => void) => {
|
|
41
|
+
watch(lastCartAddition, (addition) => {
|
|
42
|
+
if (addition) callback(addition);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
18
46
|
return {
|
|
19
47
|
triggerProductAdded,
|
|
48
|
+
triggerCartItemAdded,
|
|
20
49
|
onProductAdded,
|
|
50
|
+
onCartItemAdded,
|
|
21
51
|
};
|
|
22
52
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Schemas } from "#shopware";
|
|
2
|
+
import type { LocationQueryRaw } from "vue-router";
|
|
3
|
+
|
|
4
|
+
/** Query parameter that holds the product number of the open quick view. */
|
|
5
|
+
export const PRODUCT_QUICK_VIEW_PARAM = "produkt";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The product quick view (options, quantity, add to cart) is a drawer over
|
|
9
|
+
* the listing whose state lives in the URL: `?produkt=<productNumber>` opens
|
|
10
|
+
* it, so a product can be linked and the back button closes it (#325).
|
|
11
|
+
*/
|
|
12
|
+
export function useProductQuickView(
|
|
13
|
+
products: MaybeRefOrGetter<Schemas["Product"][]>,
|
|
14
|
+
) {
|
|
15
|
+
const route = useRoute();
|
|
16
|
+
const router = useRouter();
|
|
17
|
+
|
|
18
|
+
const requestedNumber = computed(() => {
|
|
19
|
+
const value = route.query[PRODUCT_QUICK_VIEW_PARAM];
|
|
20
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const product = computed(() =>
|
|
24
|
+
requestedNumber.value
|
|
25
|
+
? toValue(products).find(
|
|
26
|
+
(candidate) => candidate.productNumber === requestedNumber.value,
|
|
27
|
+
)
|
|
28
|
+
: undefined,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// The drawer is created on first use, not with the page (#314).
|
|
32
|
+
const mounted = ref(false);
|
|
33
|
+
watch(
|
|
34
|
+
product,
|
|
35
|
+
(value) => {
|
|
36
|
+
if (value) mounted.value = true;
|
|
37
|
+
},
|
|
38
|
+
{ immediate: true },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const open = computed({
|
|
42
|
+
get: () => product.value !== undefined,
|
|
43
|
+
set: (value) => {
|
|
44
|
+
if (!value) close();
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function show(candidate: Schemas["Product"]) {
|
|
49
|
+
if (requestedNumber.value === candidate.productNumber) return;
|
|
50
|
+
router.push({
|
|
51
|
+
query: {
|
|
52
|
+
...route.query,
|
|
53
|
+
[PRODUCT_QUICK_VIEW_PARAM]: candidate.productNumber,
|
|
54
|
+
} satisfies LocationQueryRaw,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function close() {
|
|
59
|
+
if (!requestedNumber.value) return;
|
|
60
|
+
const { [PRODUCT_QUICK_VIEW_PARAM]: _omitted, ...query } = route.query;
|
|
61
|
+
router.replace({ query });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { product, open, mounted, show, close };
|
|
65
|
+
}
|