@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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { Schemas, operations } from "#shopware";
|
|
2
|
+
|
|
3
|
+
type LineItems =
|
|
4
|
+
operations["addLineItem post /checkout/cart/line-item"]["body"]["items"];
|
|
5
|
+
|
|
6
|
+
const CART_LOCKED_STATUS = 409;
|
|
7
|
+
const CART_LOCKED_CODE = "CHECKOUT__CART_LOCKED";
|
|
8
|
+
const LOCK_RETRY_DELAY_MS = 400;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Shopware rejects a cart write while another write for the same cart
|
|
12
|
+
* token is still running ("locked due to concurrent write operation").
|
|
13
|
+
*/
|
|
14
|
+
export function isCartLockedError(error: unknown): boolean {
|
|
15
|
+
const candidate = error as {
|
|
16
|
+
status?: number;
|
|
17
|
+
details?: { errors?: { code?: string }[] };
|
|
18
|
+
};
|
|
19
|
+
return (
|
|
20
|
+
candidate?.status === CART_LOCKED_STATUS ||
|
|
21
|
+
(candidate?.details?.errors ?? []).some(
|
|
22
|
+
(detail) => detail.code === CART_LOCKED_CODE,
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Module-level so every component instance in the browser shares one
|
|
28
|
+
// queue. On the server this state would be shared across requests, so
|
|
29
|
+
// server-side calls bypass it (see `enqueue`/`setQuantity`).
|
|
30
|
+
let queue: Promise<unknown> = Promise.resolve();
|
|
31
|
+
const pendingQuantities = new Map<string, number>();
|
|
32
|
+
const queuedQuantityTasks = new Map<string, Promise<void>>();
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Serializes all cart writes and coalesces rapid quantity changes.
|
|
36
|
+
*
|
|
37
|
+
* The Store API allows only one write per cart at a time; firing them
|
|
38
|
+
* concurrently (e.g. quick +/- clicks) yields `CHECKOUT__CART_LOCKED`
|
|
39
|
+
* conflicts. Every write goes through one queue, a quantity change made
|
|
40
|
+
* while another is in flight only sends the latest value, a lock conflict
|
|
41
|
+
* is retried once, and a final failure is reported to the customer and
|
|
42
|
+
* the cart re-synced. See issue #241.
|
|
43
|
+
*/
|
|
44
|
+
export function useCartMutations() {
|
|
45
|
+
const { cart, refreshCart, addProducts, changeProductQuantity, removeItem } =
|
|
46
|
+
useCart();
|
|
47
|
+
const toast = useToast();
|
|
48
|
+
|
|
49
|
+
const pendingCount = useState("cart-mutations-pending", () => 0);
|
|
50
|
+
const isMutating = computed(() => pendingCount.value > 0);
|
|
51
|
+
|
|
52
|
+
/** Retries the actual API request (not the whole task) once on a lock conflict. */
|
|
53
|
+
async function withLockRetry<T>(request: () => Promise<T>): Promise<T> {
|
|
54
|
+
try {
|
|
55
|
+
return await request();
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (!isCartLockedError(error)) throw error;
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_DELAY_MS));
|
|
59
|
+
return request();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sends one cart write and syncs the shared cart state from its
|
|
65
|
+
* response. The layer's write functions already do that internally;
|
|
66
|
+
* doing it here as well keeps the queue's contract explicit.
|
|
67
|
+
*/
|
|
68
|
+
async function write(
|
|
69
|
+
request: () => Promise<Schemas["Cart"]>,
|
|
70
|
+
): Promise<Schemas["Cart"]> {
|
|
71
|
+
const newCart = await withLockRetry(request);
|
|
72
|
+
await refreshCart(newCart);
|
|
73
|
+
return newCart;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Runs `task` after every previously queued cart write. Resolves with
|
|
78
|
+
* `undefined` when the write failed; the failure is already reported.
|
|
79
|
+
*/
|
|
80
|
+
function enqueue<T>(
|
|
81
|
+
task: () => Promise<T>,
|
|
82
|
+
failureTitle: string,
|
|
83
|
+
): Promise<T | undefined> {
|
|
84
|
+
pendingCount.value++;
|
|
85
|
+
const run = async (): Promise<T | undefined> => {
|
|
86
|
+
try {
|
|
87
|
+
return await task();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("[cart][mutation]", error);
|
|
90
|
+
toast.add({
|
|
91
|
+
title: failureTitle,
|
|
92
|
+
description: "Bitte versuche es erneut.",
|
|
93
|
+
color: "error",
|
|
94
|
+
icon: "i-lucide-x-circle",
|
|
95
|
+
progress: false,
|
|
96
|
+
});
|
|
97
|
+
await refreshCart().catch(() => {});
|
|
98
|
+
return undefined;
|
|
99
|
+
} finally {
|
|
100
|
+
pendingCount.value--;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
// No shared queue on the server: it would span unrelated requests.
|
|
104
|
+
if (import.meta.server) return run();
|
|
105
|
+
|
|
106
|
+
const result = queue.then(run, run);
|
|
107
|
+
queue = result;
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Changes a line item's quantity. Calls made while a change for the
|
|
113
|
+
* same line item is still waiting are merged into one request carrying
|
|
114
|
+
* the latest value.
|
|
115
|
+
*/
|
|
116
|
+
function setQuantity(lineItemId: string, quantity: number): Promise<void> {
|
|
117
|
+
if (import.meta.server) {
|
|
118
|
+
return enqueue(
|
|
119
|
+
() => write(() => changeProductQuantity({ id: lineItemId, quantity })),
|
|
120
|
+
"Menge konnte nicht geändert werden",
|
|
121
|
+
).then(() => undefined);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
pendingQuantities.set(lineItemId, quantity);
|
|
125
|
+
const queued = queuedQuantityTasks.get(lineItemId);
|
|
126
|
+
if (queued) return queued;
|
|
127
|
+
|
|
128
|
+
const task = enqueue(async () => {
|
|
129
|
+
queuedQuantityTasks.delete(lineItemId);
|
|
130
|
+
const target = pendingQuantities.get(lineItemId);
|
|
131
|
+
pendingQuantities.delete(lineItemId);
|
|
132
|
+
if (target === undefined) return;
|
|
133
|
+
|
|
134
|
+
const current = cart.value?.lineItems?.find(
|
|
135
|
+
(item) => item.id === lineItemId,
|
|
136
|
+
)?.quantity;
|
|
137
|
+
if (target === current) return;
|
|
138
|
+
|
|
139
|
+
await write(() =>
|
|
140
|
+
changeProductQuantity({ id: lineItemId, quantity: target }),
|
|
141
|
+
);
|
|
142
|
+
}, "Menge konnte nicht geändert werden").then(() => undefined);
|
|
143
|
+
|
|
144
|
+
queuedQuantityTasks.set(lineItemId, task);
|
|
145
|
+
return task;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function removeLineItem(lineItem: Schemas["LineItem"]) {
|
|
149
|
+
return enqueue(
|
|
150
|
+
() => write(() => removeItem(lineItem)),
|
|
151
|
+
"Artikel konnte nicht entfernt werden",
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function addLineItems(items: LineItems) {
|
|
156
|
+
return enqueue(
|
|
157
|
+
() => write(() => addProducts(items)),
|
|
158
|
+
"Artikel konnte nicht in den Warenkorb gelegt werden",
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
isMutating,
|
|
164
|
+
setQuantity,
|
|
165
|
+
removeLineItem,
|
|
166
|
+
addLineItems,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Schemas } from "#shopware";
|
|
2
2
|
import type { NitroFetchRequest } from "nitropack";
|
|
3
3
|
|
|
4
|
-
export async function
|
|
4
|
+
export async function useCategoryById(categoryId: Ref<string>) {
|
|
5
5
|
const { data: category } = await useFetch<Schemas["Category"]>(
|
|
6
6
|
`/api/category/${categoryId.value}` as NitroFetchRequest,
|
|
7
7
|
);
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { Schemas } from "#shopware";
|
|
2
|
+
import { formatPageTitle, toAbsoluteUrl } from "../utils/seo";
|
|
2
3
|
|
|
3
4
|
export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
4
5
|
const config = useRuntimeConfig();
|
|
6
|
+
const siteConfig = useSiteConfig();
|
|
5
7
|
const storeName = config.public.site?.name || "";
|
|
6
8
|
|
|
7
|
-
const pageTitle = computed(
|
|
8
|
-
|
|
9
|
+
const pageTitle = computed(
|
|
10
|
+
() =>
|
|
9
11
|
category.value?.translated?.metaTitle ??
|
|
10
12
|
category.value?.metaTitle ??
|
|
11
13
|
category.value?.translated?.name ??
|
|
12
|
-
category.value?.name
|
|
14
|
+
category.value?.name,
|
|
15
|
+
);
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
// <title> gets the template via app.vue; og/twitter titles need it spelled out.
|
|
18
|
+
const fullTitle = computed(() =>
|
|
19
|
+
formatPageTitle(
|
|
20
|
+
pageTitle.value,
|
|
21
|
+
storeName,
|
|
22
|
+
config.public.site?.titleTemplate ?? "",
|
|
23
|
+
),
|
|
24
|
+
);
|
|
16
25
|
|
|
17
26
|
const pageDescription = computed(
|
|
18
27
|
() =>
|
|
@@ -22,30 +31,19 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
22
31
|
category.value?.description,
|
|
23
32
|
);
|
|
24
33
|
|
|
25
|
-
const seoUrl = computed(() =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return base + path;
|
|
29
|
-
});
|
|
34
|
+
const seoUrl = computed(() =>
|
|
35
|
+
toAbsoluteUrl(siteConfig.url, category.value?.seoUrl || ""),
|
|
36
|
+
);
|
|
30
37
|
|
|
31
38
|
const ogImage = computed(() => category.value?.media?.url);
|
|
32
39
|
|
|
33
40
|
const siteName = computed(() => config.public.site?.name || "");
|
|
34
|
-
const locale = computed(() => {
|
|
35
|
-
try {
|
|
36
|
-
const lang = import.meta.client
|
|
37
|
-
? document?.documentElement?.lang
|
|
38
|
-
: undefined;
|
|
39
|
-
return (lang || "de").replace("_", "-");
|
|
40
|
-
} catch {
|
|
41
|
-
return "de";
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
);
|
|
49
47
|
|
|
50
48
|
const canonicalUrl = computed(() => seoUrl.value || "");
|
|
51
49
|
|
|
@@ -54,15 +52,14 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
54
52
|
useSeoMeta({
|
|
55
53
|
title: pageTitle,
|
|
56
54
|
description: pageDescription,
|
|
57
|
-
ogTitle:
|
|
55
|
+
ogTitle: fullTitle,
|
|
58
56
|
ogDescription: pageDescription,
|
|
59
57
|
ogUrl: seoUrl,
|
|
60
58
|
ogImage,
|
|
61
59
|
ogType: "website",
|
|
62
60
|
ogSiteName: siteName,
|
|
63
|
-
ogLocale: locale,
|
|
64
61
|
ogImageAlt,
|
|
65
|
-
twitterTitle:
|
|
62
|
+
twitterTitle: fullTitle,
|
|
66
63
|
twitterDescription: pageDescription,
|
|
67
64
|
twitterImage: ogImage,
|
|
68
65
|
twitterCard: "summary_large_image",
|
|
@@ -74,6 +71,7 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
74
71
|
link: [
|
|
75
72
|
{
|
|
76
73
|
rel: "canonical",
|
|
74
|
+
key: "canonical",
|
|
77
75
|
href: canonicalUrl.value,
|
|
78
76
|
},
|
|
79
77
|
],
|
|
@@ -91,7 +89,7 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
91
89
|
isPartOf: {
|
|
92
90
|
"@type": "WebSite",
|
|
93
91
|
name: siteName.value,
|
|
94
|
-
url:
|
|
92
|
+
url: siteConfig.url,
|
|
95
93
|
},
|
|
96
94
|
}
|
|
97
95
|
: {}),
|
|
@@ -103,12 +101,12 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
103
101
|
|
|
104
102
|
return {
|
|
105
103
|
pageTitle,
|
|
104
|
+
fullTitle,
|
|
106
105
|
pageDescription,
|
|
107
106
|
seoUrl,
|
|
108
107
|
ogImage,
|
|
109
108
|
canonicalUrl,
|
|
110
109
|
robots,
|
|
111
110
|
siteName,
|
|
112
|
-
locale,
|
|
113
111
|
};
|
|
114
112
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { Schemas } from "#shopware";
|
|
2
|
+
|
|
3
|
+
const SHIPPING_METHOD_BLOCKED_KEY = "shipping-method-blocked";
|
|
4
|
+
const PAYMENT_METHOD_BLOCKED_KEY = "payment-method-blocked";
|
|
5
|
+
|
|
6
|
+
type CartError = {
|
|
7
|
+
key?: string;
|
|
8
|
+
messageKey?: string;
|
|
9
|
+
message?: string;
|
|
10
|
+
level?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type CheckoutMethod = { id: string; name?: string };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes `cart.errors`, which the Store API delivers either as an
|
|
17
|
+
* array or as an object keyed by error id.
|
|
18
|
+
*/
|
|
19
|
+
export function getCartErrors(cart?: Schemas["Cart"]): CartError[] {
|
|
20
|
+
return Object.values(cart?.errors ?? {}) as CartError[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hasCartError(cart: Schemas["Cart"] | undefined, key: string) {
|
|
24
|
+
return getCartErrors(cart).some((error) => error.messageKey === key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function hasBlockedShippingMethod(cart?: Schemas["Cart"]): boolean {
|
|
28
|
+
return hasCartError(cart, SHIPPING_METHOD_BLOCKED_KEY);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function hasBlockedPaymentMethod(cart?: Schemas["Cart"]): boolean {
|
|
32
|
+
return hasCartError(cart, PAYMENT_METHOD_BLOCKED_KEY);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type MethodGuardConfig<M extends CheckoutMethod> = {
|
|
36
|
+
/** Human readable label, e.g. "Versandart" */
|
|
37
|
+
label: string;
|
|
38
|
+
icon: string;
|
|
39
|
+
isBlocked: () => boolean;
|
|
40
|
+
selected: () => M | null;
|
|
41
|
+
loadAvailable: () => Promise<M[]>;
|
|
42
|
+
defaultId: () => string | undefined;
|
|
43
|
+
select: (id: string) => Promise<void>;
|
|
44
|
+
displayName: (method: M) => string | undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Detects a blocked shipping or payment method in the cart and switches to
|
|
49
|
+
* an available one (sales-channel default first, otherwise the first
|
|
50
|
+
* available), mirroring what Shopware's own storefront does.
|
|
51
|
+
*
|
|
52
|
+
* The Store API does not perform this switch itself. Without it, order
|
|
53
|
+
* creation fails with `CHECKOUT__CART_INVALID`
|
|
54
|
+
* (`shipping-method-blocked` / `payment-method-blocked`).
|
|
55
|
+
*/
|
|
56
|
+
export function useCheckoutMethodGuard() {
|
|
57
|
+
const { cart, refreshCart } = useCart();
|
|
58
|
+
const {
|
|
59
|
+
getShippingMethods,
|
|
60
|
+
setShippingMethod,
|
|
61
|
+
selectedShippingMethod,
|
|
62
|
+
getPaymentMethods,
|
|
63
|
+
setPaymentMethod,
|
|
64
|
+
selectedPaymentMethod,
|
|
65
|
+
} = useCheckout();
|
|
66
|
+
const { sessionContext } = useSessionContext();
|
|
67
|
+
const toast = useToast();
|
|
68
|
+
|
|
69
|
+
const isShippingMethodBlocked = computed(() =>
|
|
70
|
+
hasBlockedShippingMethod(cart.value),
|
|
71
|
+
);
|
|
72
|
+
const isPaymentMethodBlocked = computed(() =>
|
|
73
|
+
hasBlockedPaymentMethod(cart.value),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const isResolving = ref(false);
|
|
77
|
+
|
|
78
|
+
const shippingConfig: MethodGuardConfig<Schemas["ShippingMethod"]> = {
|
|
79
|
+
label: "Versandart",
|
|
80
|
+
icon: "i-lucide-truck",
|
|
81
|
+
isBlocked: () => isShippingMethodBlocked.value,
|
|
82
|
+
selected: () => selectedShippingMethod.value,
|
|
83
|
+
loadAvailable: async () =>
|
|
84
|
+
(await getShippingMethods({ forceReload: true })).value,
|
|
85
|
+
defaultId: () => sessionContext.value?.salesChannel?.shippingMethodId,
|
|
86
|
+
select: (id) => setShippingMethod({ id }),
|
|
87
|
+
displayName: (method) => method.name,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const paymentConfig: MethodGuardConfig<Schemas["PaymentMethod"]> = {
|
|
91
|
+
label: "Zahlart",
|
|
92
|
+
icon: "i-lucide-badge-euro",
|
|
93
|
+
isBlocked: () => isPaymentMethodBlocked.value,
|
|
94
|
+
selected: () => selectedPaymentMethod.value,
|
|
95
|
+
loadAvailable: async () =>
|
|
96
|
+
(await getPaymentMethods({ forceReload: true })).value,
|
|
97
|
+
defaultId: () => sessionContext.value?.salesChannel?.paymentMethodId,
|
|
98
|
+
select: (id) => setPaymentMethod({ id }),
|
|
99
|
+
displayName: (method) => method.distinguishableName ?? method.name,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Expects a freshly loaded cart. Switches the method if it is blocked.
|
|
104
|
+
*
|
|
105
|
+
* @returns `true` when an unblocked method is selected afterwards.
|
|
106
|
+
*/
|
|
107
|
+
async function resolve<M extends CheckoutMethod>(
|
|
108
|
+
config: MethodGuardConfig<M>,
|
|
109
|
+
): Promise<boolean> {
|
|
110
|
+
if (!config.isBlocked()) return true;
|
|
111
|
+
|
|
112
|
+
const blocked = config.selected();
|
|
113
|
+
const available = await config.loadAvailable();
|
|
114
|
+
const candidates = available.filter((method) => method.id !== blocked?.id);
|
|
115
|
+
const defaultId = config.defaultId();
|
|
116
|
+
const target =
|
|
117
|
+
candidates.find((method) => method.id === defaultId) ?? candidates[0];
|
|
118
|
+
|
|
119
|
+
if (!target) return false;
|
|
120
|
+
|
|
121
|
+
await config.select(target.id);
|
|
122
|
+
await refreshCart();
|
|
123
|
+
if (config.isBlocked()) return false;
|
|
124
|
+
|
|
125
|
+
const blockedName = blocked ? config.displayName(blocked) : undefined;
|
|
126
|
+
const targetName = config.displayName(target) ?? config.label;
|
|
127
|
+
toast.add({
|
|
128
|
+
title: `${config.label} geändert`,
|
|
129
|
+
description: blockedName
|
|
130
|
+
? `${blockedName} ist nicht mehr verfügbar. ${targetName} wurde ausgewählt.`
|
|
131
|
+
: `${targetName} wurde ausgewählt.`,
|
|
132
|
+
color: "warning",
|
|
133
|
+
icon: config.icon,
|
|
134
|
+
progress: false,
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Calls are serialized: the guard performs side effects (cart refresh,
|
|
140
|
+
// method switch, toast), so overlapping runs (e.g. the mount-time check
|
|
141
|
+
// plus a quick click on the order button) must not race each other.
|
|
142
|
+
// A call made while another one is in flight waits for it and then
|
|
143
|
+
// re-checks the latest cart state.
|
|
144
|
+
let queue: Promise<unknown> = Promise.resolve();
|
|
145
|
+
|
|
146
|
+
function run(task: () => Promise<boolean>): Promise<boolean> {
|
|
147
|
+
const execute = async () => {
|
|
148
|
+
isResolving.value = true;
|
|
149
|
+
try {
|
|
150
|
+
await refreshCart();
|
|
151
|
+
return await task();
|
|
152
|
+
} finally {
|
|
153
|
+
isResolving.value = false;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const result = queue.then(execute, execute);
|
|
157
|
+
queue = result.catch(() => {});
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Refreshes the cart and, if the selected shipping method is blocked,
|
|
163
|
+
* switches to an available one.
|
|
164
|
+
*/
|
|
165
|
+
function ensureAvailableShippingMethod(): Promise<boolean> {
|
|
166
|
+
return run(() => resolve(shippingConfig));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Refreshes the cart and, if the selected payment method is blocked,
|
|
171
|
+
* switches to an available one.
|
|
172
|
+
*/
|
|
173
|
+
function ensureAvailablePaymentMethod(): Promise<boolean> {
|
|
174
|
+
return run(() => resolve(paymentConfig));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Refreshes the cart and resolves blocked shipping and payment methods.
|
|
179
|
+
* Shipping is handled first because payment availability rules may
|
|
180
|
+
* depend on the shipping method. If shipping cannot be resolved the
|
|
181
|
+
* checkout stays blocked anyway, so payment is left untouched to avoid
|
|
182
|
+
* a pointless switch and toast.
|
|
183
|
+
*
|
|
184
|
+
* @returns `true` when both methods are available afterwards.
|
|
185
|
+
*/
|
|
186
|
+
function ensureAvailableCheckoutMethods(): Promise<boolean> {
|
|
187
|
+
return run(async () => {
|
|
188
|
+
if (!(await resolve(shippingConfig))) return false;
|
|
189
|
+
return resolve(paymentConfig);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
isShippingMethodBlocked,
|
|
195
|
+
isPaymentMethodBlocked,
|
|
196
|
+
isResolving,
|
|
197
|
+
ensureAvailableShippingMethod,
|
|
198
|
+
ensureAvailablePaymentMethod,
|
|
199
|
+
ensureAvailableCheckoutMethods,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matomo script, or `null` if Matomo is not configured.
|
|
3
|
+
*
|
|
4
|
+
* Without `matomoUrl` the @nuxt/scripts registry falls back to
|
|
5
|
+
* `https://cdn.matomo.cloud/<cloudId>/matomo.js` and requests
|
|
6
|
+
* `https://cdn.matomo.cloud/undefined/matomo.js` on every page (#294), so the
|
|
7
|
+
* script must only be created with a complete config. The values come from
|
|
8
|
+
* `runtimeConfig.public.scripts.matomoAnalytics` (NUXT_PUBLIC_SCRIPTS_MATOMO_ANALYTICS_*),
|
|
9
|
+
* which the registry merges in itself (#259).
|
|
10
|
+
*
|
|
11
|
+
* Only `plugins/matomo.ts` imports this composable, dynamically after
|
|
12
|
+
* `onNuxtReady`, so the registry code stays out of the entry chunk (#314).
|
|
13
|
+
* Page views are tracked by the plugin (`watch: false`): the registry's
|
|
14
|
+
* own page watcher hooks `page:finish`, which has already fired for the
|
|
15
|
+
* first page by then. Tracking calls go through `useTrackEvent`, which
|
|
16
|
+
* writes to the `_paq` queue directly.
|
|
17
|
+
*/
|
|
18
|
+
export function useMatomo() {
|
|
19
|
+
if (!useMatomoConfig().enabled) return null;
|
|
20
|
+
|
|
21
|
+
return useScriptMatomoAnalytics({
|
|
22
|
+
watch: false,
|
|
23
|
+
scriptOptions: { trigger: "onNuxtReady" },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matomo settings from `runtimeConfig.public.scripts.matomoAnalytics`
|
|
3
|
+
* (NUXT_PUBLIC_SCRIPTS_MATOMO_ANALYTICS_*). `enabled` is only true with a
|
|
4
|
+
* complete configuration (#294). Kept apart from `useMatomo` so callers that
|
|
5
|
+
* only need the flag do not import the @nuxt/scripts registry (#314).
|
|
6
|
+
*/
|
|
7
|
+
export function useMatomoConfig() {
|
|
8
|
+
const { matomoUrl, siteId } =
|
|
9
|
+
useRuntimeConfig().public.scripts.matomoAnalytics;
|
|
10
|
+
|
|
11
|
+
return { matomoUrl, siteId, enabled: Boolean(matomoUrl && siteId) };
|
|
12
|
+
}
|