@shopbite-de/storefront 1.23.3 → 1.25.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 +22 -0
- package/.github/workflows/build.yaml +1 -1
- package/.github/workflows/ci.yaml +6 -3
- package/CLAUDE.md +48 -3
- package/README.md +139 -40
- package/api-gen.config.json +9 -0
- package/api-types/storeApiSchema.shopbite.overrides.json +35 -0
- package/api-types/storeApiTypes.d.ts +95 -81
- package/app/app.config.ts +3 -2
- package/app/app.vue +40 -53
- package/app/assets/css/main.css +36 -4
- package/app/components/AddToWishlist.vue +13 -6
- package/app/components/Address/Fields.vue +2 -21
- package/app/components/AnimatedSection.vue +9 -4
- package/app/components/BottomNavi.vue +9 -2
- package/app/components/Cart/Bar.vue +102 -0
- package/app/components/Cart/Item.vue +21 -10
- package/app/components/Cart/QuickView.vue +4 -0
- package/app/components/Cart/Upsell.vue +106 -0
- package/app/components/Category/Header.vue +9 -3
- package/app/components/Category/Listing.vue +62 -45
- package/app/components/Checkout/PaymentAndDelivery.vue +19 -3
- package/app/components/Checkout/Summary.vue +70 -2
- package/app/components/Cta.vue +4 -2
- 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/Food/MarqueeItem.vue +20 -8
- package/app/components/Footer/Contact.vue +82 -0
- package/app/components/Footer/StoreStatus.vue +30 -0
- package/app/components/Footer.vue +2 -1
- package/app/components/Header/Body.vue +1 -1
- package/app/components/Header/Right.vue +60 -17
- package/app/components/Header/Title.vue +1 -0
- package/app/components/Header.vue +5 -15
- package/app/components/Hero.vue +169 -36
- package/app/components/ImageGallery.vue +11 -5
- package/app/components/Product/Card.vue +104 -46
- 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/components/User/RegistrationForm.vue +0 -1
- package/app/components/Wishlist.vue +2 -15
- package/app/composables/useAddToCart.ts +13 -40
- package/app/composables/useAddressAutocomplete.ts +12 -19
- package/app/composables/useAddressSuggestionArea.ts +16 -0
- package/app/composables/useAddressValidation.ts +3 -19
- package/app/composables/useCartMutations.ts +168 -0
- package/app/composables/useCartQuickView.ts +19 -0
- package/app/composables/useCartUpsell.ts +100 -0
- package/app/composables/{useCategory.ts → useCategoryById.ts} +1 -1
- package/app/composables/useCategorySeo.ts +27 -29
- package/app/composables/useCheckoutMethodGuard.ts +201 -0
- package/app/composables/useMatomo.ts +25 -0
- package/app/composables/useMatomoConfig.ts +12 -0
- package/app/composables/useMenuSectionSchema.ts +55 -0
- package/app/composables/useNavigation.ts +12 -9
- package/app/composables/usePageSeo.ts +50 -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/useRestaurantSchema.ts +64 -0
- package/app/composables/useScrollAnimation.ts +39 -8
- package/app/composables/useSearchTracking.ts +33 -0
- package/app/composables/useSeoUrlRoute.ts +58 -0
- package/app/composables/useSortingSelection.ts +28 -0
- package/app/composables/useStoreStatus.ts +48 -0
- package/app/composables/useTopSellers.ts +22 -0
- package/app/composables/useTrackEvent.ts +36 -23
- package/app/pages/[...all].vue +4 -4
- package/app/pages/account/recover/password/index.vue +1 -0
- package/app/pages/anmelden.vue +4 -0
- package/app/pages/bestellung/[id]/erfolg.vue +1 -5
- package/app/pages/bestellung/[id]/fehler.vue +2 -2
- package/app/pages/bestellung/[id]/index.vue +9 -3
- package/app/pages/bestellung/bestaetigen.vue +1 -5
- package/app/pages/bestellung/warenkorb.vue +1 -5
- package/app/pages/bestellung/zahlung-versand.vue +1 -5
- package/app/pages/c/[...all].vue +2 -35
- package/app/pages/index.vue +28 -14
- package/app/pages/kontakt.vue +4 -0
- package/app/pages/konto/adressen.vue +4 -0
- package/app/pages/konto/bestellung/[id].vue +4 -0
- package/app/pages/konto/bestellungen.vue +4 -0
- package/app/pages/konto/index.vue +4 -0
- package/app/pages/konto/profil.vue +4 -0
- package/app/pages/maintenance.vue +6 -0
- package/app/pages/merkliste.vue +1 -7
- package/app/pages/passwort-vergessen.vue +1 -0
- package/app/pages/registrierung/bestaetigen.vue +4 -0
- package/app/pages/registrierung/index.vue +4 -0
- package/app/pages/speisekarte/[...all].vue +2 -36
- package/app/pages/suche.vue +42 -26
- package/app/plugins/matomo.ts +35 -0
- package/app/types/Association.d.ts +1 -0
- package/app/utils/hydrateWhenVisible.ts +20 -0
- package/app/utils/media.ts +33 -0
- package/app/utils/openingHours.ts +90 -0
- package/app/utils/product.ts +31 -0
- package/app/utils/schema.ts +235 -0
- package/app/utils/seo.ts +56 -0
- package/app/utils/seoPath.ts +57 -0
- package/content/index.yml +26 -20
- package/content.config.ts +16 -0
- package/docs/notes/2026-07-05-issue-259-matomo-broken.md +7 -0
- package/docs/notes/2026-09-08-issue-240-shipping-method-blocked.md +83 -0
- package/docs/notes/2026-09-08-issue-241-cart-lock-conflicts.md +63 -0
- package/docs/notes/2026-09-08-issue-244-category-url-trailing-slash.md +65 -0
- package/docs/notes/2026-09-08-issue-276-payment-method-blocked.md +39 -0
- package/docs/notes/2026-09-08-issue-277-typecheck.md +99 -0
- package/docs/notes/2026-09-10-issue-250-animated-section.md +23 -0
- package/docs/notes/2026-09-10-issue-251-shop-data-in-base-layer.md +30 -0
- package/docs/notes/2026-09-10-issue-272-restaurant-schema.md +27 -0
- package/docs/notes/2026-09-10-issue-273-performance-media.md +64 -0
- package/docs/notes/2026-09-10-issue-274-seo-basics.md +49 -0
- package/docs/notes/2026-09-10-issue-275-accessibility.md +46 -0
- package/docs/notes/2026-09-10-issue-290-footer-nap.md +28 -0
- package/docs/notes/2026-09-10-issue-291-seo-url-trailing-slash.md +24 -0
- package/docs/notes/2026-09-10-issue-294-matomo-without-config.md +33 -0
- package/docs/notes/2026-09-10-issue-295-search-hydration-mismatch.md +25 -0
- package/docs/notes/2026-09-10-issue-296-track-direct-search.md +19 -0
- package/docs/notes/2026-09-10-issue-312-store-api-criteria-post.md +64 -0
- package/docs/notes/2026-09-10-issue-313-wishlist-scoped-tailwind.md +29 -0
- package/docs/notes/2026-09-10-issue-314-mobile-js-cost.md +119 -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/node.dockerfile +5 -2
- package/nuxt.config.ts +98 -15
- package/package.json +5 -3
- package/patches/@shopware__nuxt-module@1.5.1.patch +32 -0
- package/pnpm-workspace.yaml +2 -0
- package/public/hero-poster.webp +0 -0
- 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/__sitemap__/urls.get.ts +49 -0
- package/server/api/category/[categoryId].get.ts +20 -9
- package/server/api/content/home.get.ts +14 -0
- package/server/api/content/page.get.ts +22 -0
- package/server/api/listing/[categoryId].get.ts +14 -18
- package/server/api/product/[productId]/cross-selling.get.ts +3 -9
- package/server/api/product/[productId].get.ts +4 -8
- package/server/api/search.get.ts +2 -0
- package/server/plugins/site-url.ts +13 -0
- package/server/plugins/sitemap-trailing-slash.ts +26 -0
- package/server/utils/sitemap.ts +60 -0
- package/server/utils/storeApi.ts +34 -0
- package/shopware.d.ts +35 -11
- package/test/e2e/simple-checkout-as-recurring-customer.test.ts +13 -17
- package/test/nuxt/AddressFields.test.ts +2 -73
- package/test/nuxt/AnimatedSection.test.ts +67 -0
- package/test/nuxt/CartBar.test.ts +110 -0
- package/test/nuxt/CartItem.test.ts +95 -0
- package/test/nuxt/CartUpsell.test.ts +125 -0
- package/test/nuxt/DemoBanner.test.ts +12 -0
- package/test/nuxt/FooterContact.test.ts +102 -0
- package/test/nuxt/FooterStoreStatus.test.ts +48 -0
- package/test/nuxt/HeaderRight.test.ts +14 -10
- package/test/nuxt/Hero.test.ts +68 -0
- package/test/nuxt/PaymentAndDelivery.test.ts +67 -8
- package/test/nuxt/RegistrationForm.test.ts +3 -0
- package/test/nuxt/useAddToCart.test.ts +37 -17
- package/test/nuxt/useAddressAutocomplete.test.ts +2 -38
- package/test/nuxt/useAddressSuggestionArea.test.ts +27 -0
- package/test/nuxt/useBusinessHours.test.ts +1 -1
- package/test/nuxt/useCartMutations.test.ts +225 -0
- package/test/nuxt/useCartUpsell.test.ts +126 -0
- package/test/nuxt/useCheckoutMethodGuard.test.ts +386 -0
- package/test/nuxt/useScrollAnimation.test.ts +55 -49
- package/test/nuxt/useSearchTracking.test.ts +71 -0
- package/test/nuxt/useSeoUrlRoute.test.ts +93 -0
- package/test/nuxt/useStoreStatus.test.ts +77 -0
- package/test/nuxt/useTrackEvent.test.ts +127 -0
- package/test/unit/media.spec.ts +49 -0
- package/test/unit/openingHours.spec.ts +90 -0
- package/test/unit/product.spec.ts +72 -0
- package/test/unit/schema.spec.ts +243 -0
- package/test/unit/seo.spec.ts +107 -0
- package/test/unit/seoPath.spec.ts +116 -0
- package/test/unit/sitemap.spec.ts +88 -0
- package/test/unit/useCategorySeo.spec.ts +42 -31
- package/test/unit/useSortingSelection.spec.ts +39 -0
- 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 -51
- package/app/composables/useValidCitiesForDelivery.ts +0 -12
package/app/pages/suche.vue
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { Schemas } from "#shopware";
|
|
3
3
|
import type { NitroFetchRequest } from "nitropack";
|
|
4
|
+
import ProductCard from "~/components/Product/Card.vue";
|
|
5
|
+
|
|
6
|
+
// Cards hydrate as they scroll into view, see Category/Listing.vue (#314).
|
|
7
|
+
const ProductCardWhenVisible = hydrateWhenVisible(ProductCard);
|
|
4
8
|
|
|
5
9
|
definePageMeta({
|
|
6
10
|
layout: "listing",
|
|
7
11
|
});
|
|
8
12
|
|
|
13
|
+
useSeoMeta({
|
|
14
|
+
title: "Suche",
|
|
15
|
+
});
|
|
16
|
+
|
|
9
17
|
const route = useRoute();
|
|
10
18
|
const router = useRouter();
|
|
11
19
|
const { searchFallbackCategoryId } = useRuntimeConfig().public.shopBite;
|
|
@@ -22,20 +30,21 @@ const {
|
|
|
22
30
|
changeSorting,
|
|
23
31
|
} = useListingSearch(searchQuery.value);
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
33
|
+
// Derived from the listing data instead of snapshotted at setup time, which
|
|
34
|
+
// rendered the placeholder on the server and the actual sorting on the
|
|
35
|
+
// client: a hydration mismatch (#295, same as #239 in Category/Listing.vue).
|
|
36
|
+
const { currentSorting } = useSortingSelection(currentSortingOrder);
|
|
37
|
+
|
|
38
|
+
// Re-fetch when the URL query changes (e.g. user searches again from this
|
|
39
|
+
// page). applySearch sends no order, so the response falls back to the
|
|
40
|
+
// default sorting; drop the override so the select follows it.
|
|
41
|
+
watch(searchQuery, (q) => {
|
|
42
|
+
currentSorting.value = SORTING_PLACEHOLDER;
|
|
43
|
+
return applySearch(q);
|
|
37
44
|
});
|
|
38
45
|
|
|
46
|
+
useSearchTracking(searchQuery, elements, showSkeleton);
|
|
47
|
+
|
|
39
48
|
// Fallback: fetch a curated category listing when search returns no results.
|
|
40
49
|
// The category should have a dynamic product group assigned in Shopware.
|
|
41
50
|
const showFallback = computed(
|
|
@@ -59,20 +68,20 @@ const { data: fallbackProducts, refresh: refreshFallback } = useLazyAsyncData<
|
|
|
59
68
|
{ immediate: false },
|
|
60
69
|
);
|
|
61
70
|
|
|
71
|
+
// One quick view for the results and the fallback suggestions (#325).
|
|
72
|
+
const quickView = useProductQuickView(() => [
|
|
73
|
+
...elements.value,
|
|
74
|
+
...(fallbackProducts.value ?? []),
|
|
75
|
+
]);
|
|
76
|
+
|
|
62
77
|
watch(showFallback, (visible) => {
|
|
63
78
|
if (visible && !fallbackProducts.value) {
|
|
64
79
|
refreshFallback();
|
|
65
80
|
}
|
|
66
81
|
});
|
|
67
82
|
|
|
68
|
-
const currentSorting = ref(currentSortingOrder.value ?? "Sortieren");
|
|
69
|
-
|
|
70
|
-
watch(currentSortingOrder, (val) => {
|
|
71
|
-
if (val) currentSorting.value = val;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
83
|
watch(currentSorting, async (val) => {
|
|
75
|
-
if (val === currentSortingOrder.value) return;
|
|
84
|
+
if (val === SORTING_PLACEHOLDER || val === currentSortingOrder.value) return;
|
|
76
85
|
await changeSorting(val, searchQuery.value);
|
|
77
86
|
});
|
|
78
87
|
|
|
@@ -89,6 +98,11 @@ function submitSearch() {
|
|
|
89
98
|
<UContainer>
|
|
90
99
|
<UPage>
|
|
91
100
|
<UPageBody>
|
|
101
|
+
<LazyProductQuickView
|
|
102
|
+
v-if="quickView.mounted.value"
|
|
103
|
+
v-model:open="quickView.open.value"
|
|
104
|
+
:product="quickView.product.value"
|
|
105
|
+
/>
|
|
92
106
|
<div class="flex flex-col gap-4">
|
|
93
107
|
<div class="flex flex-col sm:flex-row gap-4">
|
|
94
108
|
<UInput
|
|
@@ -132,7 +146,7 @@ function submitSearch() {
|
|
|
132
146
|
|
|
133
147
|
<div
|
|
134
148
|
v-if="showSkeleton"
|
|
135
|
-
class="
|
|
149
|
+
class="grid grid-cols-1 gap-4 xl:grid-cols-2"
|
|
136
150
|
aria-busy="true"
|
|
137
151
|
aria-label="Produkte werden geladen"
|
|
138
152
|
>
|
|
@@ -141,15 +155,16 @@ function submitSearch() {
|
|
|
141
155
|
|
|
142
156
|
<div
|
|
143
157
|
v-else-if="elements.length > 0"
|
|
144
|
-
class="
|
|
158
|
+
class="grid grid-cols-1 gap-4 transition-opacity duration-200 xl:grid-cols-2"
|
|
145
159
|
:class="{ 'opacity-40 pointer-events-none': loading }"
|
|
146
160
|
>
|
|
147
|
-
<
|
|
161
|
+
<ProductCardWhenVisible
|
|
148
162
|
v-for="product in elements"
|
|
149
163
|
:key="product.id"
|
|
150
164
|
:product="product"
|
|
151
165
|
:with-favorite-button="true"
|
|
152
|
-
:
|
|
166
|
+
:selectable="true"
|
|
167
|
+
@select="quickView.show"
|
|
153
168
|
/>
|
|
154
169
|
</div>
|
|
155
170
|
|
|
@@ -159,13 +174,14 @@ function submitSearch() {
|
|
|
159
174
|
</p>
|
|
160
175
|
<template v-if="showFallback && fallbackProducts?.length">
|
|
161
176
|
<p class="text-sm font-medium mt-2">Das könnte dir gefallen:</p>
|
|
162
|
-
<div class="
|
|
163
|
-
<
|
|
177
|
+
<div class="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
|
178
|
+
<ProductCardWhenVisible
|
|
164
179
|
v-for="product in fallbackProducts"
|
|
165
180
|
:key="product.id"
|
|
166
181
|
:product="product"
|
|
167
182
|
:with-favorite-button="true"
|
|
168
|
-
:
|
|
183
|
+
:selectable="true"
|
|
184
|
+
@select="quickView.show"
|
|
169
185
|
/>
|
|
170
186
|
</div>
|
|
171
187
|
</template>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Registers Matomo (incl. page view tracking) on every page, but only when it
|
|
2
|
+
// is configured. Replaces the unconditional @nuxt/scripts registry entry (#294).
|
|
3
|
+
//
|
|
4
|
+
// The registry composable is imported after `onNuxtReady`, so its code (and
|
|
5
|
+
// the script it injects) stays off the critical path of the first paint
|
|
6
|
+
// (#314). Page views are pushed here: the registry's own watcher would only
|
|
7
|
+
// hook `page:finish`, which has already fired for the first page.
|
|
8
|
+
export default defineNuxtPlugin({
|
|
9
|
+
name: "shopbite:matomo",
|
|
10
|
+
setup(nuxtApp) {
|
|
11
|
+
if (import.meta.server || !useMatomoConfig().enabled) return;
|
|
12
|
+
|
|
13
|
+
onNuxtReady(async () => {
|
|
14
|
+
const { useMatomo } = await import("~/composables/useMatomo");
|
|
15
|
+
|
|
16
|
+
await nuxtApp.runWithContext(() => {
|
|
17
|
+
if (!useMatomo()) return;
|
|
18
|
+
|
|
19
|
+
const route = useRoute();
|
|
20
|
+
const { trackPageView } = useTrackEvent();
|
|
21
|
+
let lastPath = route.fullPath;
|
|
22
|
+
trackPageView(lastPath);
|
|
23
|
+
|
|
24
|
+
nuxtApp.hook("page:finish", async () => {
|
|
25
|
+
const path = route.fullPath;
|
|
26
|
+
if (path === lastPath) return;
|
|
27
|
+
lastPath = path;
|
|
28
|
+
// The title is applied to the DOM in the next animation frame.
|
|
29
|
+
await nextTick();
|
|
30
|
+
requestAnimationFrame(() => trackPageView(path));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAsyncComponent, hydrateOnVisible, type Component } from "vue";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a component so that its server-rendered markup is kept and hydrated
|
|
5
|
+
* only once it comes within `margin` of the viewport (#314).
|
|
6
|
+
*
|
|
7
|
+
* Unlike `<LazyX hydrate-on-visible>`, the component stays in the chunk of
|
|
8
|
+
* the importer: nothing extra is requested before the first instance can
|
|
9
|
+
* hydrate. The margin should exceed the reveal margin of `AnimatedSection`
|
|
10
|
+
* (100px) so the scroll animation still runs after hydration.
|
|
11
|
+
*/
|
|
12
|
+
export function hydrateWhenVisible<T extends Component>(
|
|
13
|
+
component: T,
|
|
14
|
+
margin = "600px",
|
|
15
|
+
): T {
|
|
16
|
+
return defineAsyncComponent({
|
|
17
|
+
loader: () => Promise.resolve(component),
|
|
18
|
+
hydrate: hydrateOnVisible({ rootMargin: `${margin} 0px` }),
|
|
19
|
+
}) as T;
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type Thumbnail = { url?: string; width?: number };
|
|
2
|
+
type Media = {
|
|
3
|
+
url?: string;
|
|
4
|
+
thumbnails?: Thumbnail[] | null;
|
|
5
|
+
metaData?: { width?: number; height?: number } | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `srcset` from the Shopware thumbnails of a media entity (e.g. 400, 800
|
|
10
|
+
* and 1920 px wide), so the browser picks the size it needs instead of the
|
|
11
|
+
* original (#273). Returns `undefined` without thumbnails.
|
|
12
|
+
*/
|
|
13
|
+
export function mediaSrcSet(
|
|
14
|
+
media: Media | null | undefined,
|
|
15
|
+
): string | undefined {
|
|
16
|
+
const entries = (media?.thumbnails ?? [])
|
|
17
|
+
.filter(
|
|
18
|
+
(thumbnail): thumbnail is { url: string; width: number } =>
|
|
19
|
+
Boolean(thumbnail.url) && Boolean(thumbnail.width),
|
|
20
|
+
)
|
|
21
|
+
.sort((a, b) => a.width - b.width)
|
|
22
|
+
.map((thumbnail) => `${thumbnail.url} ${thumbnail.width}w`);
|
|
23
|
+
|
|
24
|
+
return entries.length ? entries.join(", ") : undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Intrinsic size of a media entity for `width`/`height` attributes (no layout shift). */
|
|
28
|
+
export function mediaSize(
|
|
29
|
+
media: Media | null | undefined,
|
|
30
|
+
): { width: number; height: number } | undefined {
|
|
31
|
+
const { width, height } = media?.metaData ?? {};
|
|
32
|
+
return width && height ? { width, height } : undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
type BusinessHourLike = {
|
|
2
|
+
/** 1 = Monday … 7 = Sunday */
|
|
3
|
+
dayOfWeek?: number;
|
|
4
|
+
openingTime?: string;
|
|
5
|
+
closingTime?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** A run of consecutive weekdays with identical opening hours. */
|
|
9
|
+
export type OpeningHoursRow = {
|
|
10
|
+
/** e.g. `Mo` or `Mi–Fr` */
|
|
11
|
+
days: string;
|
|
12
|
+
/** e.g. `["11:30–14:30", "17:30–23:00"]`; empty on closed days */
|
|
13
|
+
intervals: string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const DAY_LABELS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] as const;
|
|
17
|
+
|
|
18
|
+
const formatTime = (time: string) => time.slice(0, 5);
|
|
19
|
+
|
|
20
|
+
/** Intervals of one weekday (1 = Monday … 7 = Sunday), e.g. `["11:30–14:30"]`. */
|
|
21
|
+
export function intervalsForDay(
|
|
22
|
+
businessHours: BusinessHourLike[],
|
|
23
|
+
dayOfWeek: number,
|
|
24
|
+
): string[] {
|
|
25
|
+
return businessHours
|
|
26
|
+
.filter(
|
|
27
|
+
(bh) => bh.dayOfWeek === dayOfWeek && bh.openingTime && bh.closingTime,
|
|
28
|
+
)
|
|
29
|
+
.sort((a, b) => a.openingTime!.localeCompare(b.openingTime!))
|
|
30
|
+
.map(
|
|
31
|
+
(bh) => `${formatTime(bh.openingTime!)}–${formatTime(bh.closingTime!)}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Today's hours as a sentence for the information cards (#332):
|
|
37
|
+
* `Heute 11:30–14:30 und 17:30–23:00`, or `Heute Ruhetag` on a closed day.
|
|
38
|
+
*/
|
|
39
|
+
export function formatTodayHours(
|
|
40
|
+
businessHours: BusinessHourLike[],
|
|
41
|
+
date: Date,
|
|
42
|
+
): string {
|
|
43
|
+
const dayOfWeek = date.getDay() === 0 ? 7 : date.getDay();
|
|
44
|
+
const intervals = intervalsForDay(businessHours, dayOfWeek);
|
|
45
|
+
return intervals.length === 0
|
|
46
|
+
? "Heute Ruhetag"
|
|
47
|
+
: `Heute ${intervals.join(" und ")}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Groups business hours into display rows: consecutive days (Monday to
|
|
52
|
+
* Sunday) with the same intervals share a row. Returns an empty list if no
|
|
53
|
+
* day has opening hours.
|
|
54
|
+
*/
|
|
55
|
+
export function groupOpeningHours(
|
|
56
|
+
businessHours: BusinessHourLike[],
|
|
57
|
+
): OpeningHoursRow[] {
|
|
58
|
+
const intervalsByDay = DAY_LABELS.map((_, index) =>
|
|
59
|
+
intervalsForDay(businessHours, index + 1),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (intervalsByDay.every((intervals) => intervals.length === 0)) return [];
|
|
63
|
+
|
|
64
|
+
const rows: OpeningHoursRow[] = [];
|
|
65
|
+
let firstDay = 0;
|
|
66
|
+
|
|
67
|
+
for (let day = 1; day <= DAY_LABELS.length; day++) {
|
|
68
|
+
const sameAsGroup =
|
|
69
|
+
day < DAY_LABELS.length &&
|
|
70
|
+
intervalsByDay[day]!.join() === intervalsByDay[firstDay]!.join();
|
|
71
|
+
if (sameAsGroup) continue;
|
|
72
|
+
|
|
73
|
+
const lastDay = day - 1;
|
|
74
|
+
rows.push({
|
|
75
|
+
days:
|
|
76
|
+
firstDay === lastDay
|
|
77
|
+
? DAY_LABELS[firstDay]!
|
|
78
|
+
: `${DAY_LABELS[firstDay]}–${DAY_LABELS[lastDay]}`,
|
|
79
|
+
intervals: intervalsByDay[firstDay]!,
|
|
80
|
+
});
|
|
81
|
+
firstDay = day;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return rows;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `tel:` link for a displayed phone number, e.g. `+49 6104 71427`. */
|
|
88
|
+
export function toTelHref(telephone: string): string {
|
|
89
|
+
return `tel:${telephone.replace(/[^\d+]/g, "")}`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Schemas } from "#shopware";
|
|
2
|
+
|
|
3
|
+
const MAIN_INGREDIENTS_GROUP = "Hauptzutaten";
|
|
4
|
+
|
|
5
|
+
/** `available` is optional in the projection; missing means orderable. */
|
|
6
|
+
export function productIsAvailable(product: Schemas["Product"]): boolean {
|
|
7
|
+
return product.available !== false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether a cart line item holds the product, as a plain line item or as a
|
|
12
|
+
* container item carrying extras (the product is the first child, #325).
|
|
13
|
+
*/
|
|
14
|
+
export function lineItemHoldsProduct(
|
|
15
|
+
item: Schemas["LineItem"],
|
|
16
|
+
productId: string,
|
|
17
|
+
): boolean {
|
|
18
|
+
return (
|
|
19
|
+
item.referencedId === productId ||
|
|
20
|
+
(item.children ?? []).some((child) => child.referencedId === productId)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getMainIngredients(
|
|
25
|
+
sortedProperties: Schemas["PropertyGroup"][] | undefined,
|
|
26
|
+
): Schemas["PropertyGroupOption"][] {
|
|
27
|
+
const group = sortedProperties?.find(
|
|
28
|
+
(propertyGroup) => propertyGroup.translated.name === MAIN_INGREDIENTS_GROUP,
|
|
29
|
+
);
|
|
30
|
+
return group?.options ?? [];
|
|
31
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Builders for the schema.org JSON-LD of the shop (#272). Pure functions, so
|
|
2
|
+
// they stay platform-neutral and unit-testable; the composables gather the
|
|
3
|
+
// data and hand it in.
|
|
4
|
+
|
|
5
|
+
const DAY_NAMES = [
|
|
6
|
+
"Monday",
|
|
7
|
+
"Tuesday",
|
|
8
|
+
"Wednesday",
|
|
9
|
+
"Thursday",
|
|
10
|
+
"Friday",
|
|
11
|
+
"Saturday",
|
|
12
|
+
"Sunday",
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
type BusinessHourLike = {
|
|
16
|
+
/** 1 = Monday … 7 = Sunday */
|
|
17
|
+
dayOfWeek?: number;
|
|
18
|
+
openingTime?: string;
|
|
19
|
+
closingTime?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type HolidayLike = {
|
|
23
|
+
start?: string;
|
|
24
|
+
end?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type SiteInfo = {
|
|
28
|
+
name: string;
|
|
29
|
+
url: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
image?: string;
|
|
32
|
+
telephone?: string;
|
|
33
|
+
cuisine?: string;
|
|
34
|
+
priceRange?: string;
|
|
35
|
+
googleBusinessProfileUrl?: string;
|
|
36
|
+
address?: {
|
|
37
|
+
street?: string;
|
|
38
|
+
postalCode?: string;
|
|
39
|
+
city?: string;
|
|
40
|
+
country?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type MenuSectionInfo = {
|
|
45
|
+
name: string;
|
|
46
|
+
url?: string;
|
|
47
|
+
sections?: MenuSectionInfo[];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type MenuItemInfo = {
|
|
51
|
+
name: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
image?: string;
|
|
54
|
+
price?: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const formatTime = (time: string) => time.slice(0, 5);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Weekly opening hours. Days with identical intervals share one entry, so
|
|
61
|
+
* `Mo–Fr 11:30–14:30` becomes a single specification with five days.
|
|
62
|
+
*/
|
|
63
|
+
export function buildOpeningHoursSpecification(
|
|
64
|
+
businessHours: BusinessHourLike[],
|
|
65
|
+
) {
|
|
66
|
+
const days = new Map<string, string[]>();
|
|
67
|
+
|
|
68
|
+
for (const bh of businessHours) {
|
|
69
|
+
const day = DAY_NAMES[(bh.dayOfWeek ?? 0) - 1];
|
|
70
|
+
if (!day || !bh.openingTime || !bh.closingTime) continue;
|
|
71
|
+
const key = `${formatTime(bh.openingTime)}-${formatTime(bh.closingTime)}`;
|
|
72
|
+
days.set(key, [...(days.get(key) ?? []), day]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return [...days.entries()].map(([key, dayOfWeek]) => {
|
|
76
|
+
const [opens, closes] = key.split("-");
|
|
77
|
+
return {
|
|
78
|
+
"@type": "OpeningHoursSpecification",
|
|
79
|
+
dayOfWeek: dayOfWeek.sort(
|
|
80
|
+
(a, b) =>
|
|
81
|
+
DAY_NAMES.indexOf(a as (typeof DAY_NAMES)[number]) -
|
|
82
|
+
DAY_NAMES.indexOf(b as (typeof DAY_NAMES)[number]),
|
|
83
|
+
),
|
|
84
|
+
opens,
|
|
85
|
+
closes,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Closing days (holidays, vacation) as special opening hours. Google's
|
|
92
|
+
* convention for a closed day is `opens` and `closes` at `00:00`.
|
|
93
|
+
*/
|
|
94
|
+
export function buildSpecialOpeningHoursSpecification(holidays: HolidayLike[]) {
|
|
95
|
+
return holidays
|
|
96
|
+
.filter((holiday) => holiday.start && holiday.end)
|
|
97
|
+
.map((holiday) => ({
|
|
98
|
+
"@type": "OpeningHoursSpecification",
|
|
99
|
+
validFrom: holiday.start!.slice(0, 10),
|
|
100
|
+
validThrough: holiday.end!.slice(0, 10),
|
|
101
|
+
opens: "00:00",
|
|
102
|
+
closes: "00:00",
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function buildAddress(address: SiteInfo["address"]) {
|
|
107
|
+
if (!address?.street && !address?.city) return undefined;
|
|
108
|
+
return compact({
|
|
109
|
+
"@type": "PostalAddress",
|
|
110
|
+
streetAddress: address.street,
|
|
111
|
+
// Nuxt parses a numeric env value into a number; schema.org wants text.
|
|
112
|
+
postalCode: address.postalCode ? String(address.postalCode) : undefined,
|
|
113
|
+
addressLocality: address.city,
|
|
114
|
+
addressCountry: address.country,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The shop as a `Restaurant` (a `LocalBusiness`) with its menu sections.
|
|
120
|
+
* Empty values are left out, so a shop without address or phone still gets a
|
|
121
|
+
* valid node.
|
|
122
|
+
*/
|
|
123
|
+
export function buildRestaurantSchema(input: {
|
|
124
|
+
site: SiteInfo;
|
|
125
|
+
businessHours?: BusinessHourLike[];
|
|
126
|
+
holidays?: HolidayLike[];
|
|
127
|
+
menuUrl?: string;
|
|
128
|
+
menuSections?: MenuSectionInfo[];
|
|
129
|
+
}) {
|
|
130
|
+
const { site } = input;
|
|
131
|
+
const openingHours = buildOpeningHoursSpecification(
|
|
132
|
+
input.businessHours ?? [],
|
|
133
|
+
);
|
|
134
|
+
const specialHours = buildSpecialOpeningHoursSpecification(
|
|
135
|
+
input.holidays ?? [],
|
|
136
|
+
);
|
|
137
|
+
const sections = buildMenuSections(input.menuSections ?? []);
|
|
138
|
+
|
|
139
|
+
return compact({
|
|
140
|
+
"@context": "https://schema.org",
|
|
141
|
+
"@type": "Restaurant",
|
|
142
|
+
"@id": `${site.url}#restaurant`,
|
|
143
|
+
name: site.name,
|
|
144
|
+
description: site.description,
|
|
145
|
+
url: site.url,
|
|
146
|
+
image: site.image,
|
|
147
|
+
telephone: site.telephone,
|
|
148
|
+
servesCuisine: site.cuisine,
|
|
149
|
+
priceRange: site.priceRange,
|
|
150
|
+
address: buildAddress(site.address),
|
|
151
|
+
sameAs: site.googleBusinessProfileUrl
|
|
152
|
+
? [site.googleBusinessProfileUrl]
|
|
153
|
+
: undefined,
|
|
154
|
+
openingHoursSpecification: openingHours.length ? openingHours : undefined,
|
|
155
|
+
specialOpeningHoursSpecification: specialHours.length
|
|
156
|
+
? specialHours
|
|
157
|
+
: undefined,
|
|
158
|
+
hasMenu:
|
|
159
|
+
input.menuUrl || sections.length
|
|
160
|
+
? compact({
|
|
161
|
+
"@type": "Menu",
|
|
162
|
+
"@id": `${site.url}#menu`,
|
|
163
|
+
name: "Speisekarte",
|
|
164
|
+
url: input.menuUrl,
|
|
165
|
+
hasMenuSection: sections.length ? sections : undefined,
|
|
166
|
+
})
|
|
167
|
+
: undefined,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Menu sections with their subsections (category tree of the menu). */
|
|
172
|
+
function buildMenuSections(
|
|
173
|
+
sections: MenuSectionInfo[],
|
|
174
|
+
): Record<string, unknown>[] {
|
|
175
|
+
return sections.map((section) => {
|
|
176
|
+
const subsections = buildMenuSections(section.sections ?? []);
|
|
177
|
+
return compact({
|
|
178
|
+
"@type": "MenuSection",
|
|
179
|
+
name: section.name,
|
|
180
|
+
url: section.url,
|
|
181
|
+
hasMenuSection: subsections.length ? subsections : undefined,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A category page as a `MenuSection` with its products as `MenuItem`s. */
|
|
187
|
+
export function buildMenuSectionSchema(input: {
|
|
188
|
+
name: string;
|
|
189
|
+
description?: string;
|
|
190
|
+
url?: string;
|
|
191
|
+
image?: string;
|
|
192
|
+
currency: string;
|
|
193
|
+
items: MenuItemInfo[];
|
|
194
|
+
restaurantUrl?: string;
|
|
195
|
+
}) {
|
|
196
|
+
return compact({
|
|
197
|
+
"@context": "https://schema.org",
|
|
198
|
+
"@type": "MenuSection",
|
|
199
|
+
name: input.name,
|
|
200
|
+
description: input.description,
|
|
201
|
+
url: input.url,
|
|
202
|
+
image: input.image,
|
|
203
|
+
hasMenuItem: input.items.map((item) =>
|
|
204
|
+
compact({
|
|
205
|
+
"@type": "MenuItem",
|
|
206
|
+
name: item.name,
|
|
207
|
+
description: item.description,
|
|
208
|
+
image: item.image,
|
|
209
|
+
offers:
|
|
210
|
+
item.price !== undefined
|
|
211
|
+
? {
|
|
212
|
+
"@type": "Offer",
|
|
213
|
+
price: item.price.toFixed(2),
|
|
214
|
+
priceCurrency: input.currency,
|
|
215
|
+
}
|
|
216
|
+
: undefined,
|
|
217
|
+
}),
|
|
218
|
+
),
|
|
219
|
+
isPartOf: input.restaurantUrl
|
|
220
|
+
? { "@type": "Menu", "@id": `${input.restaurantUrl}#menu` }
|
|
221
|
+
: undefined,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Drops `undefined`, empty strings and empty arrays. */
|
|
226
|
+
function compact<T extends Record<string, unknown>>(object: T): T {
|
|
227
|
+
return Object.fromEntries(
|
|
228
|
+
Object.entries(object).filter(
|
|
229
|
+
([, value]) =>
|
|
230
|
+
value !== undefined &&
|
|
231
|
+
value !== "" &&
|
|
232
|
+
!(Array.isArray(value) && value.length === 0),
|
|
233
|
+
),
|
|
234
|
+
) as T;
|
|
235
|
+
}
|
package/app/utils/seo.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { hasProtocol, joinURL, withTrailingSlash } from "ufo";
|
|
2
|
+
|
|
3
|
+
type SiteInfo = {
|
|
4
|
+
name: string;
|
|
5
|
+
city?: string;
|
|
6
|
+
cuisine?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Applies the site title template (`%s` = page title, `%siteName` = shop
|
|
11
|
+
* name). A missing title or the bare shop name renders as the shop name.
|
|
12
|
+
*/
|
|
13
|
+
export function formatPageTitle(
|
|
14
|
+
title: string | null | undefined,
|
|
15
|
+
siteName: string,
|
|
16
|
+
template: string,
|
|
17
|
+
): string {
|
|
18
|
+
if (!title || title === siteName) return siteName;
|
|
19
|
+
if (!template) return title;
|
|
20
|
+
return template.replaceAll("%siteName", siteName).replaceAll("%s", title);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a site-relative path against the site URL. Absolute URLs are kept,
|
|
25
|
+
* and so is the trailing slash of the path: Shopware SEO URLs such as
|
|
26
|
+
* `/c/Pizza/` only resolve with it.
|
|
27
|
+
*/
|
|
28
|
+
export function toAbsoluteUrl(siteUrl: string, pathOrUrl: string): string {
|
|
29
|
+
if (hasProtocol(pathOrUrl, { acceptRelative: true })) return pathOrUrl;
|
|
30
|
+
const url = joinURL(siteUrl, pathOrUrl);
|
|
31
|
+
return pathOrUrl.endsWith("/") ? withTrailingSlash(url) : url;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Default home page title: `<Shopname> <Ort> | Online bestellen & liefern lassen`. */
|
|
35
|
+
export function buildHomeTitle({ name, city }: SiteInfo): string {
|
|
36
|
+
const place = city && !name.includes(city) ? `${name} ${city}` : name;
|
|
37
|
+
return `${place} | Online bestellen & liefern lassen`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Default home page description from city and cuisine, if any is configured. */
|
|
41
|
+
export function buildHomeDescription({
|
|
42
|
+
name,
|
|
43
|
+
city,
|
|
44
|
+
cuisine,
|
|
45
|
+
}: SiteInfo): string | undefined {
|
|
46
|
+
if (cuisine && city) {
|
|
47
|
+
return `${cuisine} in ${city}: Bei ${name} online bestellen und liefern lassen oder abholen.`;
|
|
48
|
+
}
|
|
49
|
+
if (city) {
|
|
50
|
+
return `${name} in ${city}: Online bestellen und liefern lassen oder abholen.`;
|
|
51
|
+
}
|
|
52
|
+
if (cuisine) {
|
|
53
|
+
return `${cuisine}: Bei ${name} online bestellen und liefern lassen oder abholen.`;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|