@shopbite-de/storefront 1.23.3 → 1.24.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 +19 -0
- package/.github/workflows/build.yaml +1 -1
- package/.github/workflows/ci.yaml +6 -3
- package/CLAUDE.md +41 -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.vue +37 -53
- package/app/assets/css/main.css +20 -4
- 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/Item.vue +21 -10
- package/app/components/Category/Header.vue +9 -3
- package/app/components/Category/Listing.vue +51 -42
- package/app/components/Checkout/PaymentAndDelivery.vue +19 -3
- package/app/components/Checkout/Summary.vue +65 -1
- package/app/components/Cta.vue +4 -2
- package/app/components/Food/MarqueeItem.vue +20 -8
- package/app/components/Footer/Contact.vue +78 -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 +27 -13
- package/app/components/Header/Title.vue +1 -0
- package/app/components/Header.vue +5 -15
- package/app/components/Hero.vue +45 -2
- package/app/components/ImageGallery.vue +11 -5
- package/app/components/Product/Card.vue +9 -3
- package/app/components/Product/CardFooter.vue +22 -12
- package/app/components/User/RegistrationForm.vue +0 -1
- package/app/components/Wishlist.vue +2 -15
- package/app/composables/useAddToCart.ts +13 -13
- 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/{useCategory.ts → useCategoryById.ts} +1 -1
- package/app/composables/useCategorySeo.ts +22 -25
- 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/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/useTrackEvent.ts +29 -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 +25 -13
- 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 +24 -21
- package/app/plugins/matomo.ts +35 -0
- package/app/utils/hydrateWhenVisible.ts +20 -0
- package/app/utils/media.ts +33 -0
- package/app/utils/openingHours.ts +67 -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 +10 -9
- package/content.config.ts +3 -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/node.dockerfile +5 -2
- package/nuxt.config.ts +74 -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/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 +12 -18
- package/server/api/product/[productId]/cross-selling.get.ts +3 -9
- package/server/api/product/[productId].get.ts +4 -8
- 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/nuxt/AddressFields.test.ts +2 -73
- package/test/nuxt/AnimatedSection.test.ts +67 -0
- package/test/nuxt/CartItem.test.ts +95 -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 +34 -1
- 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/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 +112 -0
- package/test/unit/media.spec.ts +49 -0
- package/test/unit/openingHours.spec.ts +59 -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 +40 -30
- package/test/unit/useSortingSelection.spec.ts +39 -0
- package/app/composables/useValidCitiesForDelivery.ts +0 -12
|
@@ -149,7 +149,7 @@ onMounted(async () => {
|
|
|
149
149
|
</div>
|
|
150
150
|
<div class="flex-1 min-w-0">
|
|
151
151
|
<div class="flex flex-col gap-1">
|
|
152
|
-
<span class="text-xs text-
|
|
152
|
+
<span class="text-xs text-primary font-medium">
|
|
153
153
|
#{{ product.productNumber }}
|
|
154
154
|
</span>
|
|
155
155
|
<h3
|
|
@@ -157,7 +157,7 @@ onMounted(async () => {
|
|
|
157
157
|
>
|
|
158
158
|
{{ product.translated.name }}
|
|
159
159
|
</h3>
|
|
160
|
-
<p class="text-base font-bold text-primary
|
|
160
|
+
<p class="text-base font-bold text-primary">
|
|
161
161
|
{{
|
|
162
162
|
getFormattedPrice(
|
|
163
163
|
product.calculatedPrice.totalPrice,
|
|
@@ -222,16 +222,3 @@ onMounted(async () => {
|
|
|
222
222
|
</div>
|
|
223
223
|
</div>
|
|
224
224
|
</template>
|
|
225
|
-
|
|
226
|
-
<style scoped>
|
|
227
|
-
@import "tailwindcss";
|
|
228
|
-
@import "@nuxt/ui";
|
|
229
|
-
|
|
230
|
-
h1 {
|
|
231
|
-
@apply text-3xl sm:text-4xl lg:text-5xl text-pretty tracking-tight font-bold text-highlighted my-14;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
h2 {
|
|
235
|
-
@apply mt-0 text-2xl sm:text-3xl lg:text-4xl text-pretty tracking-tight font-bold text-highlighted my-10;
|
|
236
|
-
}
|
|
237
|
-
</style>
|
|
@@ -9,7 +9,7 @@ const LINE_ITEM_PRODUCT = "product";
|
|
|
9
9
|
const LINE_ITEM_CONTAINER = "container";
|
|
10
10
|
|
|
11
11
|
export function useAddToCart() {
|
|
12
|
-
const {
|
|
12
|
+
const { addLineItems } = useCartMutations();
|
|
13
13
|
const toast = useToast();
|
|
14
14
|
const { triggerProductAdded } = useProductEvents();
|
|
15
15
|
const { trackAddToCart: trackAddToCartEvent } = useTrackEvent();
|
|
@@ -138,20 +138,20 @@ export function useAddToCart() {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
async function addToCart(onSuccess?: () => void) {
|
|
141
|
-
if (!selectedProduct.value) return;
|
|
141
|
+
if (!selectedProduct.value || isLoading.value) return;
|
|
142
142
|
isLoading.value = true;
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
144
|
+
try {
|
|
145
|
+
// Failures are reported by useCartMutations; it resolves undefined.
|
|
146
|
+
const newCart = await addLineItems(createCartItems());
|
|
147
|
+
if (!newCart) return;
|
|
148
|
+
|
|
149
|
+
await showSuccessToast();
|
|
150
|
+
triggerProductAdded();
|
|
151
|
+
trackAddToCartEvent(selectedProduct.value, selectedQuantity.value);
|
|
152
|
+
onSuccess?.();
|
|
153
|
+
} finally {
|
|
154
|
+
isLoading.value = false;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -25,7 +25,7 @@ interface GeoapifyResponse {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function useAddressAutocomplete() {
|
|
28
|
-
const { boundingBoxCoordinates
|
|
28
|
+
const { boundingBoxCoordinates } = useAddressSuggestionArea();
|
|
29
29
|
|
|
30
30
|
async function getSuggestions(text: string): Promise<AddressSuggestion[]> {
|
|
31
31
|
if (!text || text.length < 3) {
|
|
@@ -54,24 +54,17 @@ export function useAddressAutocomplete() {
|
|
|
54
54
|
return [];
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
return data.value.features
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
street
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
-
.filter((suggestion: AddressSuggestion) => {
|
|
70
|
-
if (validCities.value.length === 0) return true;
|
|
71
|
-
return validCities.value.some(
|
|
72
|
-
(city) => city.toLowerCase() === suggestion.city.toLowerCase(),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
57
|
+
return data.value.features.map((feature: GeoapifyFeature) => {
|
|
58
|
+
const props = feature.properties;
|
|
59
|
+
return {
|
|
60
|
+
street: props.street
|
|
61
|
+
? `${props.street}${props.housenumber ? " " + props.housenumber : ""}`
|
|
62
|
+
: props.name || "",
|
|
63
|
+
city: props.city || "",
|
|
64
|
+
zipcode: props.postcode || "",
|
|
65
|
+
label: props.formatted || "",
|
|
66
|
+
};
|
|
67
|
+
});
|
|
75
68
|
} catch (error) {
|
|
76
69
|
console.error("Error fetching address suggestions:", error);
|
|
77
70
|
return [];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional area that narrows the Geoapify address suggestions
|
|
3
|
+
* (`filter=rect:lon1,lat1,lon2,lat2`), from
|
|
4
|
+
* `runtimeConfig.public.shopBite.addressAutocomplete.boundingBox`. Empty means
|
|
5
|
+
* no filter. Where the shop delivers is decided by the Shopware cart rules,
|
|
6
|
+
* not here (#251).
|
|
7
|
+
*/
|
|
8
|
+
export function useAddressSuggestionArea() {
|
|
9
|
+
const { addressAutocomplete } = useRuntimeConfig().public.shopBite;
|
|
10
|
+
|
|
11
|
+
const boundingBoxCoordinates = computed(() =>
|
|
12
|
+
addressAutocomplete.boundingBox.trim(),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return { boundingBoxCoordinates };
|
|
16
|
+
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { ref,
|
|
2
|
-
import type { Ref
|
|
1
|
+
import { ref, watch, toValue, onUnmounted } from "vue";
|
|
2
|
+
import type { Ref } from "vue";
|
|
3
3
|
import type { AddressSchema } from "~/validation/registrationSchema";
|
|
4
4
|
import type { AddressSuggestion } from "~/composables/useAddressAutocomplete";
|
|
5
5
|
|
|
6
6
|
export function useAddressValidation(
|
|
7
7
|
model: Ref<AddressSchema>,
|
|
8
8
|
options: {
|
|
9
|
-
isShipping?: Ref<boolean> | ComputedRef<boolean> | boolean;
|
|
10
9
|
getSuggestions: (query: string) => Promise<AddressSuggestion[] | undefined>;
|
|
11
|
-
validCities: Ref<string[]>;
|
|
12
10
|
},
|
|
13
11
|
) {
|
|
14
|
-
const {
|
|
12
|
+
const { getSuggestions } = options;
|
|
15
13
|
|
|
16
14
|
const showCorrection = ref(false);
|
|
17
15
|
const correction = ref<AddressSuggestion | null>(null);
|
|
@@ -41,19 +39,6 @@ export function useAddressValidation(
|
|
|
41
39
|
return false;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
const isInvalidCity = computed(() => {
|
|
45
|
-
if (!toValue(isShipping)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
const m = toValue(model);
|
|
49
|
-
if (!m.city || validCities.value.length === 0) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return !validCities.value.some(
|
|
53
|
-
(city) => city.toLowerCase() === m.city.toLowerCase(),
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
42
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
58
43
|
|
|
59
44
|
watch(
|
|
@@ -99,7 +84,6 @@ export function useAddressValidation(
|
|
|
99
84
|
return {
|
|
100
85
|
showCorrection,
|
|
101
86
|
correction,
|
|
102
|
-
isInvalidCity,
|
|
103
87
|
checkAddress,
|
|
104
88
|
flushPendingCheck,
|
|
105
89
|
applyCorrection,
|
|
@@ -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
|
+
}
|
|
@@ -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,25 +31,13 @@ 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
42
|
const robots = computed(() => {
|
|
46
43
|
const active = category.value?.active;
|
|
@@ -54,15 +51,14 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
54
51
|
useSeoMeta({
|
|
55
52
|
title: pageTitle,
|
|
56
53
|
description: pageDescription,
|
|
57
|
-
ogTitle:
|
|
54
|
+
ogTitle: fullTitle,
|
|
58
55
|
ogDescription: pageDescription,
|
|
59
56
|
ogUrl: seoUrl,
|
|
60
57
|
ogImage,
|
|
61
58
|
ogType: "website",
|
|
62
59
|
ogSiteName: siteName,
|
|
63
|
-
ogLocale: locale,
|
|
64
60
|
ogImageAlt,
|
|
65
|
-
twitterTitle:
|
|
61
|
+
twitterTitle: fullTitle,
|
|
66
62
|
twitterDescription: pageDescription,
|
|
67
63
|
twitterImage: ogImage,
|
|
68
64
|
twitterCard: "summary_large_image",
|
|
@@ -74,6 +70,7 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
74
70
|
link: [
|
|
75
71
|
{
|
|
76
72
|
rel: "canonical",
|
|
73
|
+
key: "canonical",
|
|
77
74
|
href: canonicalUrl.value,
|
|
78
75
|
},
|
|
79
76
|
],
|
|
@@ -91,7 +88,7 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
91
88
|
isPartOf: {
|
|
92
89
|
"@type": "WebSite",
|
|
93
90
|
name: siteName.value,
|
|
94
|
-
url:
|
|
91
|
+
url: siteConfig.url,
|
|
95
92
|
},
|
|
96
93
|
}
|
|
97
94
|
: {}),
|
|
@@ -103,12 +100,12 @@ export function useCategorySeo(category: Ref<Schemas["Category"] | undefined>) {
|
|
|
103
100
|
|
|
104
101
|
return {
|
|
105
102
|
pageTitle,
|
|
103
|
+
fullTitle,
|
|
106
104
|
pageDescription,
|
|
107
105
|
seoUrl,
|
|
108
106
|
ogImage,
|
|
109
107
|
canonicalUrl,
|
|
110
108
|
robots,
|
|
111
109
|
siteName,
|
|
112
|
-
locale,
|
|
113
110
|
};
|
|
114
111
|
}
|
|
@@ -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
|
+
}
|