@shopbite-de/storefront 2.6.0 → 2.7.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 +13 -0
- package/.github/workflows/ci.yaml +2 -0
- package/CLAUDE.md +54 -30
- package/GLOSSARY.md +327 -0
- package/README.md +5 -6
- package/app/app.vue +50 -40
- package/app/components/Address/Card.vue +2 -2
- package/app/components/Address/Detail.vue +17 -45
- package/app/components/Address/Form.vue +38 -26
- package/app/components/BranchSwitch.vue +40 -0
- package/app/components/Cart/Bar.vue +9 -9
- package/app/components/Cart/Item.vue +27 -36
- package/app/components/Cart/QuickView.vue +17 -16
- package/app/components/Cart/Upsell.vue +19 -27
- package/app/components/Category/Breadcrumb.vue +3 -8
- package/app/components/Category/FilterGroup.vue +6 -6
- package/app/components/Category/Listing.vue +44 -66
- package/app/components/Checkout/DeliveryTimeSelect.vue +21 -48
- package/app/components/Checkout/OrderMessage.vue +29 -0
- package/app/components/Checkout/OrdererAddress.vue +40 -0
- package/app/components/Checkout/PaymentAndDelivery.vue +40 -35
- package/app/components/Checkout/Summary.vue +89 -74
- package/app/components/Checkout/VoucherInput.vue +8 -8
- package/app/components/Contact/Form.vue +97 -13
- package/app/components/Footer.vue +2 -2
- package/app/components/Header.vue +9 -9
- package/app/components/Home/Categories.vue +13 -17
- package/app/components/Home/Facts.vue +6 -4
- package/app/components/Home/Hero.vue +1 -1
- package/app/components/Home/Highlights.vue +8 -8
- package/app/components/Home/Restaurant.vue +2 -2
- package/app/components/Menu/BonCard.vue +21 -37
- package/app/components/Menu/CartPanel.vue +2 -2
- package/app/components/Menu/CategoryIndex.vue +8 -12
- package/app/components/Menu/OrderMode.vue +2 -2
- package/app/components/Menu/SectionHeader.vue +6 -10
- package/app/components/Navigation/MobileTop.vue +12 -20
- package/app/components/Order/Confirmation.vue +10 -10
- package/app/components/Order/Detail.vue +47 -49
- package/app/components/Product/Configurator.vue +46 -30
- package/app/components/Product/CrossSelling.vue +56 -71
- package/app/components/Product/DeselectIngredient.vue +10 -11
- package/app/components/Product/Detail.vue +62 -55
- package/app/components/Product/FoodLabels.vue +4 -9
- package/app/components/Product/QuickView.vue +22 -30
- package/app/components/User/Detail.vue +20 -43
- package/app/components/User/LoginForm.vue +11 -17
- package/app/components/User/RegistrationForm.vue +3 -3
- package/app/components/Wishlist.vue +99 -106
- package/app/components/WishlistSaveButton.vue +17 -9
- package/app/composables/useAccountAddresses.ts +89 -0
- package/app/composables/useAccountOrders.ts +35 -0
- package/app/composables/useAddToCart.ts +63 -110
- package/app/composables/useCartData.ts +55 -0
- package/app/composables/useCartMutations.ts +93 -85
- package/app/composables/useCartUpsell.ts +27 -71
- package/app/composables/useCategoryListing.ts +36 -59
- package/app/composables/useCategorySeo.ts +11 -16
- package/app/composables/useCheckoutMethodGuard.ts +22 -46
- package/app/composables/useCheckoutMethods.ts +89 -0
- package/app/composables/useCheckoutOrderMessage.ts +19 -0
- package/app/composables/useCheckoutOrderer.ts +69 -0
- package/app/composables/useCommercePrice.ts +46 -9
- package/app/composables/useContactForm.ts +25 -32
- package/app/composables/useCustomer.ts +169 -0
- package/app/composables/useDeliveryTime.ts +112 -122
- package/app/composables/useHolidays.ts +12 -62
- package/app/composables/useHomeMenuCategories.ts +5 -5
- package/app/composables/useListingSearch.ts +9 -8
- package/app/composables/useLiveShopData.ts +15 -9
- package/app/composables/useMenuRootId.ts +3 -6
- package/app/composables/useMenuSection.ts +14 -0
- package/app/composables/useMenuSectionSchema.ts +23 -30
- package/app/composables/useNavigation.ts +24 -29
- package/app/composables/useOpeningHours.ts +21 -0
- package/app/composables/useOpeningHoursData.ts +9 -9
- package/app/composables/useOrder.ts +37 -0
- package/app/composables/useOrderMode.ts +18 -16
- package/app/composables/usePlaceOrder.ts +37 -0
- package/app/composables/useProductCartQuantity.ts +6 -6
- package/app/composables/useProductDetail.ts +28 -53
- package/app/composables/useProductEvents.ts +6 -5
- package/app/composables/useProductQuickView.ts +35 -68
- package/app/composables/useRegistrationForm.ts +85 -34
- package/app/composables/useRestaurantSchema.ts +7 -7
- package/app/composables/useSearchTracking.ts +6 -6
- package/app/composables/useSectionRoute.ts +48 -0
- package/app/composables/useServiceSchedule.ts +23 -0
- package/app/composables/useShippingLeadTime.ts +8 -6
- package/app/composables/useShippingMethodChoice.ts +13 -23
- package/app/composables/useShippingMethods.ts +31 -0
- package/app/composables/useShopConfig.ts +60 -0
- package/app/composables/useShopData.ts +20 -0
- package/app/composables/useSortingSelection.ts +5 -8
- package/app/composables/useStoreStatus.ts +13 -37
- package/app/composables/useTopSellers.ts +3 -3
- package/app/composables/useTrackEvent.ts +29 -24
- package/app/composables/useVoucherCode.ts +47 -12
- package/app/composables/useWishlistEntries.ts +233 -177
- package/app/error.vue +3 -2
- package/app/layouts/account.vue +4 -3
- package/app/pages/[...all].vue +6 -16
- package/app/pages/account/recover/password/index.vue +6 -14
- package/app/pages/anmelden.vue +1 -1
- package/app/pages/bestellung/[id]/erfolg.vue +3 -3
- package/app/pages/bestellung/[id]/fehler.vue +18 -29
- package/app/pages/bestellung/kasse.vue +24 -7
- package/app/pages/konto/adressen.vue +95 -40
- package/app/pages/konto/bestellungen.vue +10 -13
- package/app/pages/konto/index.vue +12 -2
- package/app/pages/konto/profil.vue +241 -42
- package/app/pages/passwort-vergessen.vue +5 -10
- package/app/pages/registrierung/bestaetigen.vue +9 -23
- package/app/pages/registrierung/index.vue +19 -11
- package/app/pages/suche.vue +29 -29
- package/app/plugins/shopware-layer-offline.ts +38 -0
- package/app/plugins/visitor-has-session.server.ts +19 -0
- package/app/utils/accountMessages.ts +74 -0
- package/app/utils/accountReads.ts +34 -0
- package/app/utils/bffWrite.ts +89 -0
- package/app/utils/dish.ts +121 -0
- package/app/utils/leadTime.ts +25 -29
- package/app/utils/media.ts +11 -17
- package/app/utils/menuGroups.ts +22 -35
- package/app/utils/money.ts +41 -0
- package/app/utils/openingHours.ts +30 -30
- package/app/utils/orderStatus.ts +17 -0
- package/app/utils/productUrl.ts +14 -31
- package/app/utils/restaurantTime.ts +326 -0
- package/app/utils/schema.ts +39 -42
- package/app/utils/wishlist.ts +139 -0
- package/docs/adr/0001-backend-agnostic-storefront.md +409 -0
- package/eslint.config.mjs +42 -2
- package/nuxt.config.ts +28 -0
- package/package.json +1 -1
- package/server/adapters/memory/cart.ts +370 -0
- package/server/adapters/memory/catalog.ts +367 -0
- package/server/adapters/memory/contact.ts +89 -0
- package/server/adapters/memory/customer.ts +458 -0
- package/server/adapters/memory/demo-menu.json +1190 -0
- package/server/adapters/memory/demoImages.ts +13 -0
- package/server/adapters/memory/demoMenu.ts +234 -0
- package/server/adapters/memory/demoNavigation.ts +71 -0
- package/server/adapters/memory/index.ts +122 -0
- package/server/adapters/memory/navigation.ts +168 -0
- package/server/adapters/memory/ordering.ts +379 -0
- package/server/adapters/memory/seed.ts +136 -0
- package/server/adapters/memory/wishlist.ts +166 -0
- package/server/adapters/notImplemented.ts +67 -0
- package/server/adapters/registry.ts +32 -0
- package/server/adapters/runtimeConfig.ts +14 -0
- package/server/adapters/shopware/cart.ts +792 -0
- package/server/adapters/shopware/catalog.ts +850 -0
- package/server/adapters/shopware/checkout.ts +138 -0
- package/server/adapters/shopware/contact.ts +255 -0
- package/server/adapters/shopware/customer.ts +460 -0
- package/server/adapters/shopware/index.ts +165 -0
- package/server/adapters/shopware/menuRoot.ts +24 -0
- package/server/adapters/shopware/navigation.ts +426 -0
- package/server/adapters/shopware/ordering.ts +1185 -0
- package/server/adapters/shopware/request.ts +67 -0
- package/server/adapters/shopware/shop.ts +249 -0
- package/server/adapters/shopware/storeApi.ts +62 -0
- package/server/adapters/shopware/wishlist.ts +473 -0
- package/server/api/__sitemap__/urls.get.ts +10 -38
- package/server/api/account/addresses/[addressId]/default.post.ts +13 -0
- package/server/api/account/addresses/[addressId].delete.ts +14 -0
- package/server/api/account/addresses/[addressId].patch.ts +15 -0
- package/server/api/account/addresses/index.get.ts +6 -0
- package/server/api/account/addresses/index.post.ts +9 -0
- package/server/api/account/email.post.ts +10 -0
- package/server/api/account/index.delete.ts +11 -0
- package/server/api/account/index.get.ts +9 -0
- package/server/api/account/login.post.ts +14 -0
- package/server/api/account/logout.post.ts +11 -0
- package/server/api/account/orders.get.ts +13 -0
- package/server/api/account/password-reset/confirm.post.ts +13 -0
- package/server/api/account/password-reset.post.ts +16 -0
- package/server/api/account/password.post.ts +18 -0
- package/server/api/account/profile.patch.ts +6 -0
- package/server/api/account/register/confirm.post.ts +13 -0
- package/server/api/account/register.post.ts +15 -0
- package/server/api/breadcrumb/[sectionId].get.ts +33 -0
- package/server/api/cart/index.get.ts +4 -0
- package/server/api/cart/lines/[lineId].delete.ts +6 -0
- package/server/api/cart/lines/[lineId].patch.ts +10 -0
- package/server/api/cart/lines.post.ts +10 -0
- package/server/api/cart/vouchers/[code].delete.ts +9 -0
- package/server/api/cart/vouchers.post.ts +12 -0
- package/server/api/checkout/guest.post.ts +13 -0
- package/server/api/checkout/orderer/addresses/[addressId].patch.ts +16 -0
- package/server/api/checkout/orderer.get.ts +10 -0
- package/server/api/checkout/orders.post.ts +60 -0
- package/server/api/checkout/payment-methods.get.ts +9 -0
- package/server/api/checkout/selection.get.ts +10 -0
- package/server/api/checkout/selection.post.ts +14 -0
- package/server/api/checkout/shipping-methods.get.ts +9 -0
- package/server/api/contact/form.get.ts +13 -0
- package/server/api/contact/index.post.ts +24 -0
- package/server/api/listing/[sectionId].get.ts +33 -0
- package/server/api/menu/dishes/[dishId]/variant.get.ts +29 -0
- package/server/api/menu/dishes/[dishId].get.ts +19 -0
- package/server/api/menu/dishes/index.get.ts +26 -0
- package/server/api/menu/media/[name].get.ts +18 -0
- package/server/api/menu/root.get.ts +12 -0
- package/server/api/menu/sections/[sectionId].get.ts +18 -0
- package/server/api/menu/upsell.get.ts +12 -0
- package/server/api/navigation/[kind].get.ts +75 -0
- package/server/api/orders/[orderId]/payment.post.ts +24 -0
- package/server/api/orders/[orderId].get.ts +13 -0
- package/server/api/payment-methods.get.ts +11 -15
- package/server/api/resolve-path.get.ts +20 -0
- package/server/api/search.get.ts +16 -80
- package/server/api/session.post.ts +18 -0
- package/server/api/shop/branches.get.ts +9 -0
- package/server/api/shop/config.get.ts +9 -0
- package/server/api/shop/holidays.get.ts +9 -0
- package/server/api/shop/opening-hours.get.ts +9 -0
- package/server/api/top-sellers.get.ts +14 -50
- package/server/api/wishlist/entries/[entryId].delete.ts +8 -0
- package/server/api/wishlist/entries.post.ts +13 -0
- package/server/api/wishlist/index.get.ts +13 -0
- package/server/api/wishlist/merge.post.ts +12 -0
- package/server/plugins/visitor-session.ts +35 -0
- package/server/ports/CartPort.ts +48 -0
- package/server/ports/CatalogPort.ts +66 -0
- package/server/ports/CheckoutPort.ts +128 -0
- package/server/ports/ContactPort.ts +38 -0
- package/server/ports/CustomerPort.ts +154 -0
- package/server/ports/NavigationPort.ts +58 -0
- package/server/ports/OrderPort.ts +31 -0
- package/server/ports/ShopPort.ts +29 -0
- package/server/ports/WishlistPort.ts +47 -0
- package/server/ports/index.ts +42 -0
- package/server/ports/session.ts +22 -0
- package/server/routes/llms.txt.ts +28 -154
- package/server/session/forwardedFor.ts +24 -0
- package/server/session/sameOrigin.ts +47 -0
- package/server/session/seal.ts +147 -0
- package/server/session/visitorSession.ts +288 -0
- package/server/utils/accountRoutes.ts +173 -0
- package/server/utils/backend.ts +21 -0
- package/server/utils/backoff.ts +18 -5
- package/server/utils/cacheKeys.ts +11 -0
- package/server/utils/cachePurge.ts +47 -27
- package/server/utils/cartRoutes.ts +124 -0
- package/server/utils/catalogData.ts +24 -0
- package/server/utils/checkoutRoutes.ts +326 -0
- package/server/utils/contactRoutes.ts +86 -0
- package/server/utils/domainHttp.ts +73 -0
- package/server/utils/listingParams.ts +49 -20
- package/server/utils/llmsTxt.ts +64 -19
- package/server/utils/navigationData.ts +14 -0
- package/server/utils/orderPlacement.ts +322 -0
- package/server/utils/outageBreaker.ts +126 -0
- package/server/utils/pathRoutes.ts +160 -0
- package/server/utils/requestBody.ts +43 -0
- package/server/utils/shopData.ts +132 -0
- package/server/utils/sitemap.ts +14 -36
- package/server/utils/storeApi.ts +71 -23
- package/server/utils/visitorSession.ts +209 -0
- package/server/utils/wishlistRoutes.ts +55 -0
- package/shared/domain/customer/index.ts +2 -0
- package/shared/domain/customer/types.ts +88 -0
- package/shared/domain/discoverability/index.ts +4 -0
- package/shared/domain/discoverability/paths.ts +93 -0
- package/shared/domain/discoverability/route.ts +32 -0
- package/shared/domain/discoverability/types.ts +75 -0
- package/shared/domain/index.ts +11 -0
- package/shared/domain/kernel/calendar.ts +88 -0
- package/shared/domain/kernel/errors.ts +100 -0
- package/shared/domain/kernel/freeze.ts +13 -0
- package/shared/domain/kernel/ids.ts +6 -0
- package/shared/domain/kernel/index.ts +8 -0
- package/shared/domain/kernel/media.ts +17 -0
- package/shared/domain/kernel/money.ts +104 -0
- package/shared/domain/kernel/timeOfDay.ts +39 -0
- package/shared/domain/menu/dishConfiguration.ts +72 -0
- package/shared/domain/menu/index.ts +3 -0
- package/shared/domain/menu/types.ts +185 -0
- package/shared/domain/ordering/index.ts +3 -0
- package/shared/domain/ordering/time.ts +114 -0
- package/shared/domain/ordering/types.ts +195 -0
- package/shared/domain/restaurant/holiday.ts +38 -0
- package/shared/domain/restaurant/index.ts +4 -0
- package/shared/domain/restaurant/openingInterval.ts +97 -0
- package/shared/domain/restaurant/types.ts +75 -0
- package/test/a11y/presets.test.ts +49 -31
- package/test/contract/cart.contract.ts +592 -0
- package/test/contract/cart.spec.ts +5 -0
- package/test/contract/cartFixtures.ts +573 -0
- package/test/contract/catalog.contract.ts +714 -0
- package/test/contract/catalog.spec.ts +5 -0
- package/test/contract/catalogFixtures.ts +572 -0
- package/test/contract/checkout.contract.ts +123 -0
- package/test/contract/checkout.spec.ts +5 -0
- package/test/contract/contact.contract.ts +149 -0
- package/test/contract/contact.spec.ts +4 -0
- package/test/contract/contactFixtures.ts +148 -0
- package/test/contract/customer.contract.ts +831 -0
- package/test/contract/customer.spec.ts +4 -0
- package/test/contract/customerFixtures.ts +468 -0
- package/test/contract/fixtures.ts +260 -0
- package/test/contract/harness.ts +45 -0
- package/test/contract/navigation.contract.ts +336 -0
- package/test/contract/navigation.spec.ts +5 -0
- package/test/contract/navigationFixtures.ts +311 -0
- package/test/contract/ordering.contract.ts +655 -0
- package/test/contract/ordering.spec.ts +4 -0
- package/test/contract/orderingFixtures.ts +498 -0
- package/test/contract/shop.contract.ts +164 -0
- package/test/contract/shop.spec.ts +5 -0
- package/test/contract/wishlist.contract.ts +375 -0
- package/test/contract/wishlist.spec.ts +4 -0
- package/test/contract/wishlistFixtures.ts +199 -0
- package/test/nuxt/AccountPagesPreset.test.ts +320 -83
- package/test/nuxt/AuthPagesPreset.test.ts +17 -24
- package/test/nuxt/CartBar.test.ts +12 -8
- package/test/nuxt/CartCheckoutPreset.test.ts +36 -33
- package/test/nuxt/CartItem.test.ts +39 -20
- package/test/nuxt/CartQuickView.test.ts +106 -0
- package/test/nuxt/CartUpsell.test.ts +37 -39
- package/test/nuxt/CategoryBreadcrumb.test.ts +26 -0
- package/test/nuxt/CheckoutFormsPreset.test.ts +92 -13
- package/test/nuxt/CheckoutOnePage.test.ts +28 -21
- package/test/nuxt/CheckoutPageMessage.test.ts +31 -0
- package/test/nuxt/CheckoutSummary.test.ts +163 -48
- package/test/nuxt/CheckoutVoucherInput.test.ts +77 -80
- package/test/nuxt/ContactFormPreset.test.ts +97 -36
- package/test/nuxt/DeliveryTimeSelect.test.ts +72 -45
- package/test/nuxt/FooterStoreStatus.test.ts +2 -2
- package/test/nuxt/HeaderFooterPreset.test.ts +11 -19
- package/test/nuxt/HomeCategories.test.ts +47 -0
- package/test/nuxt/HomeLeadTimes.test.ts +3 -3
- package/test/nuxt/MenuBonCard.test.ts +45 -32
- package/test/nuxt/NavigationMobileTop.test.ts +30 -28
- package/test/nuxt/OrderPagesPreset.test.ts +83 -52
- package/test/nuxt/PaymentAndDelivery.test.ts +25 -26
- package/test/nuxt/ProductConfigurator.test.ts +81 -0
- package/test/nuxt/ProductCrossSelling.test.ts +23 -20
- package/test/nuxt/ProductDeselectIngredient.test.ts +6 -9
- package/test/nuxt/ProductFoodLabels.test.ts +7 -24
- package/test/nuxt/ProductSheetPreset.test.ts +24 -24
- package/test/nuxt/RegisterConfirmPage.test.ts +26 -45
- package/test/nuxt/RegistrationForm.test.ts +57 -53
- package/test/nuxt/RegistrationPage.test.ts +37 -0
- package/test/nuxt/WishlistPage.test.ts +119 -43
- package/test/nuxt/WishlistSaveButton.test.ts +39 -12
- package/test/nuxt/accountSwitch.test.ts +106 -0
- package/test/nuxt/bffWrite.test.ts +41 -0
- package/test/nuxt/liveShopData.test.ts +36 -68
- package/test/nuxt/shopwareLayerOffline.test.ts +32 -0
- package/test/nuxt/useAddToCart.test.ts +142 -115
- package/test/nuxt/useCartMutations.test.ts +165 -113
- package/test/nuxt/useCartUpsell.test.ts +36 -63
- package/test/nuxt/useCategoryListing.test.ts +75 -118
- package/test/nuxt/useCheckoutMethodGuard.test.ts +54 -105
- package/test/nuxt/useCustomer.test.ts +127 -0
- package/test/nuxt/useDeliveryTime.test.ts +169 -157
- package/test/nuxt/useNavigation.test.ts +81 -0
- package/test/nuxt/useOpeningHoursData.test.ts +18 -18
- package/test/nuxt/useOrder.test.ts +38 -0
- package/test/nuxt/usePlaceOrder.test.ts +88 -0
- package/test/nuxt/useSearchTracking.test.ts +2 -2
- package/test/nuxt/useSectionRoute.test.ts +86 -0
- package/test/nuxt/useShippingLeadTime.test.ts +17 -17
- package/test/nuxt/useShippingMethodChoice.test.ts +22 -22
- package/test/nuxt/useShippingMethods.test.ts +71 -0
- package/test/nuxt/useShopConfig.test.ts +64 -0
- package/test/nuxt/useStoreStatus.test.ts +34 -50
- package/test/nuxt/useTopSellers.test.ts +6 -5
- package/test/nuxt/useTrackEvent.test.ts +68 -6
- package/test/nuxt/useWishlistEntries.test.ts +392 -128
- package/test/support/cart.ts +43 -0
- package/test/support/dishes.ts +116 -0
- package/test/support/navigation.ts +17 -0
- package/test/unit/accountMessages.spec.ts +53 -0
- package/test/unit/accountRoutes.spec.ts +637 -0
- package/test/unit/adapters/memoryCustomer.spec.ts +67 -0
- package/test/unit/adapters/memoryDemoMenu.spec.ts +174 -0
- package/test/unit/adapters/registry.spec.ts +100 -0
- package/test/unit/adapters/shopwareCart.spec.ts +636 -0
- package/test/unit/adapters/shopwareCatalog.spec.ts +486 -0
- package/test/unit/adapters/shopwareCheckout.spec.ts +197 -0
- package/test/unit/adapters/shopwareContact.spec.ts +296 -0
- package/test/unit/adapters/shopwareCustomer.spec.ts +256 -0
- package/test/unit/adapters/shopwareNavigation.spec.ts +594 -0
- package/test/unit/adapters/shopwareOrdering.spec.ts +620 -0
- package/test/unit/adapters/shopwareShop.spec.ts +259 -0
- package/test/unit/adapters/shopwareWishlist.spec.ts +306 -0
- package/test/unit/adapters/useBackend.spec.ts +41 -0
- package/test/unit/backoff.spec.ts +47 -0
- package/test/unit/boundedCache.spec.ts +59 -59
- package/test/unit/cacheKeys.spec.ts +44 -0
- package/test/unit/cachePurge.spec.ts +44 -19
- package/test/unit/cartRoutes.spec.ts +567 -0
- package/test/unit/catalogRoutes.spec.ts +287 -0
- package/test/unit/checkoutRoutes.spec.ts +545 -0
- package/test/unit/dish.spec.ts +128 -0
- package/test/unit/domain/discoverability.spec.ts +154 -0
- package/test/unit/domain/dishConfiguration.spec.ts +85 -0
- package/test/unit/domain/money.spec.ts +102 -0
- package/test/unit/domain/time.spec.ts +336 -0
- package/test/unit/domainHttp.spec.ts +74 -0
- package/test/unit/forwardedFor.spec.ts +24 -0
- package/test/unit/layoutCacheRoutes.spec.ts +47 -471
- package/test/unit/leadTime.spec.ts +28 -23
- package/test/unit/llmsTxt.spec.ts +120 -9
- package/test/unit/media.spec.ts +25 -26
- package/test/unit/menuGroups.spec.ts +31 -21
- package/test/unit/navigationRoutes.spec.ts +648 -0
- package/test/unit/nitroStubs.ts +6 -1
- package/test/unit/openingHours.spec.ts +57 -34
- package/test/unit/orderPlacement.spec.ts +362 -0
- package/test/unit/outageBreaker.spec.ts +213 -0
- package/test/unit/productUrl.spec.ts +10 -28
- package/test/unit/requestBody.spec.ts +56 -0
- package/test/unit/restaurantTime.spec.ts +295 -0
- package/test/unit/schema.spec.ts +58 -26
- package/test/unit/session/sameOrigin.spec.ts +76 -0
- package/test/unit/session/seal.spec.ts +128 -0
- package/test/unit/session/visitorSession.spec.ts +439 -0
- package/test/unit/shopRoutes.spec.ts +257 -0
- package/test/unit/sitemap.spec.ts +11 -47
- package/test/unit/storeApiForVisitor.spec.ts +109 -0
- package/test/unit/useCategorySeo.spec.ts +57 -31
- package/test/unit/wishlistContactRoutes.spec.ts +607 -0
- package/vitest.config.ts +5 -1
- package/app/components/SalesChannelSwitch.vue +0 -73
- package/app/composables/useBusinessHours.ts +0 -192
- package/app/composables/useCategoryById.ts +0 -10
- package/app/composables/useNavigationSearch.ts +0 -45
- package/app/composables/useProductConfigurator.ts +0 -70
- package/app/composables/useProductCrossSelling.ts +0 -42
- package/app/composables/useProductVariants.ts +0 -61
- package/app/composables/useProductVariantsZwei.ts +0 -62
- package/app/composables/useSeoUrlRoute.ts +0 -124
- package/app/composables/useShopBiteConfig.ts +0 -69
- package/app/composables/useSyncWishlist.ts +0 -119
- package/app/types/Association.d.ts +0 -14
- package/app/utils/product.ts +0 -139
- package/app/utils/seoPath.ts +0 -68
- package/app/utils/time.ts +0 -20
- package/server/api/breadcrumb/[categoryId].get.ts +0 -31
- package/server/api/category/[categoryId].get.ts +0 -37
- package/server/api/listing/[categoryId].get.ts +0 -102
- package/server/api/navigation/[type].get.ts +0 -97
- package/server/api/product/[productId]/cross-selling.get.ts +0 -26
- package/server/api/product/[productId].get.ts +0 -76
- package/server/api/product/variant.get.ts +0 -98
- package/server/api/seo-url/index.get.ts +0 -17
- package/server/api/seo-url/known.get.ts +0 -33
- package/server/api/shopbite/business-hours.get.ts +0 -22
- package/server/api/shopbite/config.get.ts +0 -6
- package/server/api/shopbite/holidays.get.ts +0 -20
- package/server/utils/menuRoot.ts +0 -31
- package/server/utils/seoPaths.ts +0 -130
- package/server/utils/seoUrlCache.ts +0 -98
- package/server/utils/shopBiteConfig.ts +0 -30
- package/test/nuxt/useBusinessHours.test.ts +0 -106
- package/test/nuxt/useProductConfigurator.test.ts +0 -87
- package/test/nuxt/useProductVariants.test.ts +0 -95
- package/test/nuxt/useProductVariantsZwei.test.ts +0 -52
- package/test/nuxt/useSeoUrlRoute.test.ts +0 -176
- package/test/nuxt/useShopBiteConfig.test.ts +0 -131
- package/test/nuxt/useSyncWishlist.test.ts +0 -85
- package/test/unit/product.spec.ts +0 -160
- package/test/unit/seoPath.spec.ts +0 -161
- package/test/unit/seoPaths.spec.ts +0 -117
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deepFreeze,
|
|
3
|
+
DomainError,
|
|
4
|
+
isDomainError,
|
|
5
|
+
moneyFromDecimal,
|
|
6
|
+
type CurrencyCode,
|
|
7
|
+
type Diet,
|
|
8
|
+
type Dish,
|
|
9
|
+
type DishDetail,
|
|
10
|
+
type ExtraGroup,
|
|
11
|
+
type FoodLabel,
|
|
12
|
+
type FoodLabels,
|
|
13
|
+
type Id,
|
|
14
|
+
type Ingredient,
|
|
15
|
+
type ListingFilter,
|
|
16
|
+
type ListingQuery,
|
|
17
|
+
type Media,
|
|
18
|
+
type MenuListing,
|
|
19
|
+
type MenuSection,
|
|
20
|
+
type Money,
|
|
21
|
+
type Variant,
|
|
22
|
+
type VariantGroup,
|
|
23
|
+
} from "../../../shared/domain";
|
|
24
|
+
import type { CatalogPort } from "../../ports";
|
|
25
|
+
import { menuRootReader } from "./menuRoot";
|
|
26
|
+
import { errorCodes, request } from "./request";
|
|
27
|
+
import { text, type AdapterLog } from "./shop";
|
|
28
|
+
import type { StoreApi } from "./storeApi";
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* What the adapter reads of the Store API answers: the fields the criteria
|
|
32
|
+
* below ask for, all optional (Shopware leaves out what is empty).
|
|
33
|
+
*/
|
|
34
|
+
export type Translated<T> = T & { translated?: Partial<T> | null };
|
|
35
|
+
type CustomFields = Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
type SwMedia = {
|
|
38
|
+
url?: string | null;
|
|
39
|
+
alt?: string | null;
|
|
40
|
+
translated?: { alt?: string | null } | null;
|
|
41
|
+
metaData?: { width?: number; height?: number } | null;
|
|
42
|
+
thumbnails?: { url?: string; width?: number }[] | null;
|
|
43
|
+
};
|
|
44
|
+
type SwOption = Translated<{
|
|
45
|
+
id: string;
|
|
46
|
+
name?: string | null;
|
|
47
|
+
customFields?: CustomFields | null;
|
|
48
|
+
}>;
|
|
49
|
+
type SwGroup = Translated<{
|
|
50
|
+
id: string;
|
|
51
|
+
name?: string | null;
|
|
52
|
+
options?: SwOption[] | null;
|
|
53
|
+
}>;
|
|
54
|
+
type SwPrice = {
|
|
55
|
+
unitPrice?: number;
|
|
56
|
+
totalPrice?: number;
|
|
57
|
+
listPrice?: { price?: number } | null;
|
|
58
|
+
};
|
|
59
|
+
type SwSeoUrl = { seoPathInfo?: string; isCanonical?: boolean | null };
|
|
60
|
+
export type SwProduct = Translated<{
|
|
61
|
+
id: string;
|
|
62
|
+
parentId?: string | null;
|
|
63
|
+
productNumber: string;
|
|
64
|
+
name?: string | null;
|
|
65
|
+
description?: string | null;
|
|
66
|
+
customFields?: CustomFields | null;
|
|
67
|
+
}> & {
|
|
68
|
+
childCount?: number | null;
|
|
69
|
+
available?: boolean;
|
|
70
|
+
calculatedPrice?: SwPrice;
|
|
71
|
+
calculatedCheapestPrice?: SwPrice | null;
|
|
72
|
+
cover?: { media?: SwMedia | null } | null;
|
|
73
|
+
sortedProperties?: SwGroup[] | null;
|
|
74
|
+
optionIds?: string[] | null;
|
|
75
|
+
categoryIds?: string[] | null;
|
|
76
|
+
seoUrls?: SwSeoUrl[] | null;
|
|
77
|
+
};
|
|
78
|
+
type SwCategory = Translated<{
|
|
79
|
+
id: string;
|
|
80
|
+
name?: string | null;
|
|
81
|
+
description?: string | null;
|
|
82
|
+
metaTitle?: string | null;
|
|
83
|
+
metaDescription?: string | null;
|
|
84
|
+
customFields?: CustomFields | null;
|
|
85
|
+
}> & {
|
|
86
|
+
type?: string;
|
|
87
|
+
active?: boolean;
|
|
88
|
+
seoUrl?: string | null;
|
|
89
|
+
media?: SwMedia | null;
|
|
90
|
+
children?: SwCategory[] | null;
|
|
91
|
+
};
|
|
92
|
+
type SwSorting = Translated<{ key: string; label?: string }>;
|
|
93
|
+
type SwListing = {
|
|
94
|
+
elements?: SwProduct[];
|
|
95
|
+
total?: number;
|
|
96
|
+
page?: number;
|
|
97
|
+
limit?: number;
|
|
98
|
+
sorting?: string | null;
|
|
99
|
+
availableSortings?: SwSorting[];
|
|
100
|
+
currentFilters?: { properties?: string[] | null } | null;
|
|
101
|
+
aggregations?: { properties?: { entities?: SwGroup[] } } | null;
|
|
102
|
+
};
|
|
103
|
+
type SwCrossSelling = {
|
|
104
|
+
crossSelling?: Translated<{ id: string; name?: string | null }>;
|
|
105
|
+
products?: SwProduct[];
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Property groups and custom fields of the ShopBite conventions
|
|
109
|
+
// (CLAUDE.md, product data model).
|
|
110
|
+
const MAIN_INGREDIENTS = "Hauptzutaten";
|
|
111
|
+
const KITCHEN = "Küche";
|
|
112
|
+
const ALLERGENS = "Allergene";
|
|
113
|
+
const ADDITIVES = "Zusatzstoffe";
|
|
114
|
+
const DIET_GROUPS: Readonly<Record<Diet, string>> = {
|
|
115
|
+
vegetarian: "Vegetarisch",
|
|
116
|
+
vegan: "Vegan",
|
|
117
|
+
};
|
|
118
|
+
const YES = "Ja";
|
|
119
|
+
const CODE_FIELD = "shopbite_code";
|
|
120
|
+
const CHECKED_FIELD = "shopbite_allergens_checked";
|
|
121
|
+
const UPSELL_FIELD = "shopbite_cart_upsell";
|
|
122
|
+
const ICON_FIELD = "shopbite_category_icon";
|
|
123
|
+
/** The query parameter of the dish sheet in a dish's link. */
|
|
124
|
+
const SHEET_PARAM = "produkt";
|
|
125
|
+
|
|
126
|
+
/** Store API maximum per request; no menu section has more. */
|
|
127
|
+
const PAGE_SIZE = 100;
|
|
128
|
+
const MAX_MENU_PAGES = 10;
|
|
129
|
+
|
|
130
|
+
const MEDIA = {
|
|
131
|
+
media: ["url", "alt", "translated", "thumbnails", "metaData"],
|
|
132
|
+
media_thumbnail: ["url", "width", "height"],
|
|
133
|
+
product_media: ["media"],
|
|
134
|
+
};
|
|
135
|
+
const PROPERTY_INCLUDES = {
|
|
136
|
+
// the entity is `property_group`: under `property` the groups came back
|
|
137
|
+
// with every field, nested once more in each option
|
|
138
|
+
property_group: ["id", "name", "translated", "options"],
|
|
139
|
+
// custom fields only come back when listed (`translated` too)
|
|
140
|
+
property_group_option: ["id", "name", "translated", "customFields"],
|
|
141
|
+
};
|
|
142
|
+
/** What a menu card needs of a product (dish or variant). */
|
|
143
|
+
const DISH_FIELDS = [
|
|
144
|
+
"id",
|
|
145
|
+
"parentId",
|
|
146
|
+
"productNumber",
|
|
147
|
+
"name",
|
|
148
|
+
"description",
|
|
149
|
+
"translated",
|
|
150
|
+
"customFields",
|
|
151
|
+
"calculatedPrice",
|
|
152
|
+
"calculatedCheapestPrice",
|
|
153
|
+
"available",
|
|
154
|
+
"childCount",
|
|
155
|
+
"cover",
|
|
156
|
+
// grouped properties (ingredients, diets, kitchen, food labels);
|
|
157
|
+
// `properties` would repeat every option with its group
|
|
158
|
+
"sortedProperties",
|
|
159
|
+
"optionIds",
|
|
160
|
+
"categoryIds",
|
|
161
|
+
"seoUrls",
|
|
162
|
+
];
|
|
163
|
+
const DISH_CRITERIA = {
|
|
164
|
+
includes: {
|
|
165
|
+
product: DISH_FIELDS,
|
|
166
|
+
calculated_price: ["unitPrice", "totalPrice", "listPrice"],
|
|
167
|
+
calculated_cheapest_price: ["unitPrice", "totalPrice"],
|
|
168
|
+
cart_list_price: ["price"],
|
|
169
|
+
seo_url: ["seoPathInfo", "isCanonical"],
|
|
170
|
+
...PROPERTY_INCLUDES,
|
|
171
|
+
...MEDIA,
|
|
172
|
+
},
|
|
173
|
+
associations: {
|
|
174
|
+
cover: { associations: { media: {} } },
|
|
175
|
+
properties: { associations: { group: {} } },
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
/** The dish's link is its SEO URL; variants inherit name, cover, properties. */
|
|
179
|
+
const DISH_HEADERS = {
|
|
180
|
+
"sw-include-seo-urls": "true",
|
|
181
|
+
"sw-inheritance": "true",
|
|
182
|
+
};
|
|
183
|
+
const CATEGORY_FIELDS = [
|
|
184
|
+
"id",
|
|
185
|
+
"name",
|
|
186
|
+
"description",
|
|
187
|
+
"metaTitle",
|
|
188
|
+
"metaDescription",
|
|
189
|
+
"translated",
|
|
190
|
+
"customFields",
|
|
191
|
+
"active",
|
|
192
|
+
"type",
|
|
193
|
+
"seoUrl",
|
|
194
|
+
"media",
|
|
195
|
+
"children",
|
|
196
|
+
];
|
|
197
|
+
const CATEGORY_INCLUDES = { category: CATEGORY_FIELDS, ...MEDIA };
|
|
198
|
+
|
|
199
|
+
/** Shopware's answer to a listing page after the last one. */
|
|
200
|
+
const PAGE_OUT_OF_RANGE = "PRODUCT__LISTING_PAGE_OUT_OF_RANGE";
|
|
201
|
+
|
|
202
|
+
export function translated<T extends object, K extends keyof T>(
|
|
203
|
+
entity: Translated<T> | null | undefined,
|
|
204
|
+
key: K,
|
|
205
|
+
): T[K] | undefined {
|
|
206
|
+
return (entity?.translated?.[key] ?? entity?.[key]) as T[K] | undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const customField = (
|
|
210
|
+
entity: Translated<{ customFields?: CustomFields | null }> | null | undefined,
|
|
211
|
+
name: string,
|
|
212
|
+
): unknown => translated(entity, "customFields")?.[name];
|
|
213
|
+
|
|
214
|
+
const nameOf = (entity: Translated<{ name?: string | null }>) =>
|
|
215
|
+
translated(entity, "name") ?? "";
|
|
216
|
+
|
|
217
|
+
export function toMedia(media: SwMedia | null | undefined): Media | null {
|
|
218
|
+
if (!media?.url) return null;
|
|
219
|
+
return {
|
|
220
|
+
url: media.url,
|
|
221
|
+
alt: text(media.translated?.alt ?? media.alt),
|
|
222
|
+
width: media.metaData?.width ?? null,
|
|
223
|
+
height: media.metaData?.height ?? null,
|
|
224
|
+
sources: (media.thumbnails ?? []).flatMap((thumbnail) =>
|
|
225
|
+
thumbnail.url && thumbnail.width
|
|
226
|
+
? [{ url: thumbnail.url, width: thumbnail.width }]
|
|
227
|
+
: [],
|
|
228
|
+
),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const groupNamed = (product: SwProduct, name: string) =>
|
|
233
|
+
product.sortedProperties?.find((group) => nameOf(group) === name);
|
|
234
|
+
|
|
235
|
+
const optionsOf = (product: SwProduct, groupName: string) =>
|
|
236
|
+
groupNamed(product, groupName)?.options ?? [];
|
|
237
|
+
|
|
238
|
+
export function toIngredients(product: SwProduct): Ingredient[] {
|
|
239
|
+
return optionsOf(product, MAIN_INGREDIENTS).map((option) => ({
|
|
240
|
+
id: option.id,
|
|
241
|
+
name: nameOf(option),
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function toDiets(product: SwProduct): Diet[] {
|
|
246
|
+
return (Object.keys(DIET_GROUPS) as Diet[]).filter((diet) =>
|
|
247
|
+
optionsOf(product, DIET_GROUPS[diet]).some(
|
|
248
|
+
(option) => nameOf(option) === YES,
|
|
249
|
+
),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function labelsOf(product: SwProduct, groupName: string): FoodLabel[] {
|
|
254
|
+
return optionsOf(product, groupName).map((option) => ({
|
|
255
|
+
code: String(customField(option, CODE_FIELD) ?? ""),
|
|
256
|
+
name: nameOf(option),
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function toFoodLabels(product: SwProduct): FoodLabels {
|
|
261
|
+
return {
|
|
262
|
+
allergens: labelsOf(product, ALLERGENS),
|
|
263
|
+
additives: labelsOf(product, ADDITIVES),
|
|
264
|
+
checked: customField(product, CHECKED_FIELD) === true,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The dish's link: its SEO URL when that opens the dish sheet over a
|
|
270
|
+
* section (the ShopBite plugin's template, `…/?produkt=21`); otherwise
|
|
271
|
+
* null and the storefront links the dish under its section.
|
|
272
|
+
*/
|
|
273
|
+
export function toDishPath(product: SwProduct): string | null {
|
|
274
|
+
const seoUrls = product.seoUrls ?? [];
|
|
275
|
+
const seoPath = (seoUrls.find((url) => url.isCanonical) ?? seoUrls[0])
|
|
276
|
+
?.seoPathInfo;
|
|
277
|
+
if (!seoPath) return null;
|
|
278
|
+
const query = seoPath.split("?")[1];
|
|
279
|
+
if (
|
|
280
|
+
query === undefined ||
|
|
281
|
+
new URLSearchParams(query).get(SHEET_PARAM) === null
|
|
282
|
+
) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
return seoPath.startsWith("/") ? seoPath : `/${seoPath}`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function priceOf(
|
|
289
|
+
price: SwPrice | null | undefined,
|
|
290
|
+
currency: CurrencyCode,
|
|
291
|
+
): Money {
|
|
292
|
+
return moneyFromDecimal(price?.unitPrice ?? price?.totalPrice ?? 0, currency);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function listPriceOf(
|
|
296
|
+
price: SwPrice | null | undefined,
|
|
297
|
+
currency: CurrencyCode,
|
|
298
|
+
): Money | null {
|
|
299
|
+
const listPrice = price?.listPrice?.price;
|
|
300
|
+
return typeof listPrice === "number"
|
|
301
|
+
? moneyFromDecimal(listPrice, currency)
|
|
302
|
+
: null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** A product as a menu card shows it. */
|
|
306
|
+
export function toDish(product: SwProduct, currency: CurrencyCode): Dish {
|
|
307
|
+
const needsChoice = (product.childCount ?? 0) > 0;
|
|
308
|
+
const kitchen = optionsOf(product, KITCHEN)[0];
|
|
309
|
+
return {
|
|
310
|
+
id: product.id,
|
|
311
|
+
number: product.productNumber,
|
|
312
|
+
name: nameOf(product),
|
|
313
|
+
description: text(translated(product, "description")),
|
|
314
|
+
// a parent with variants: the lowest price of its variants
|
|
315
|
+
price: priceOf(
|
|
316
|
+
needsChoice
|
|
317
|
+
? (product.calculatedCheapestPrice ?? product.calculatedPrice)
|
|
318
|
+
: product.calculatedPrice,
|
|
319
|
+
currency,
|
|
320
|
+
),
|
|
321
|
+
listPrice: listPriceOf(product.calculatedPrice, currency),
|
|
322
|
+
priceFrom: needsChoice,
|
|
323
|
+
media: toMedia(product.cover?.media),
|
|
324
|
+
ingredients: toIngredients(product),
|
|
325
|
+
diets: toDiets(product),
|
|
326
|
+
kitchen: kitchen ? text(nameOf(kitchen)) : null,
|
|
327
|
+
foodLabels: toFoodLabels(product),
|
|
328
|
+
available: product.available !== false,
|
|
329
|
+
needsChoice,
|
|
330
|
+
sectionIds: product.categoryIds ?? [],
|
|
331
|
+
path: toDishPath(product),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** A child product as a variant; what it does not have is the dish's. */
|
|
336
|
+
export function toVariant(
|
|
337
|
+
product: SwProduct,
|
|
338
|
+
dish: Dish | undefined,
|
|
339
|
+
currency: CurrencyCode,
|
|
340
|
+
): Variant {
|
|
341
|
+
const ingredients = toIngredients(product);
|
|
342
|
+
return {
|
|
343
|
+
id: product.id,
|
|
344
|
+
number: product.productNumber,
|
|
345
|
+
name: nameOf(product) || dish?.name || "",
|
|
346
|
+
optionIds: product.optionIds ?? [],
|
|
347
|
+
price: priceOf(product.calculatedPrice, currency),
|
|
348
|
+
listPrice: listPriceOf(product.calculatedPrice, currency),
|
|
349
|
+
available: product.available !== false,
|
|
350
|
+
media: toMedia(product.cover?.media) ?? dish?.media ?? null,
|
|
351
|
+
ingredients: ingredients.length ? ingredients : (dish?.ingredients ?? []),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function toVariantGroups(groups: SwGroup[] | undefined): VariantGroup[] {
|
|
356
|
+
return (groups ?? []).map((group) => ({
|
|
357
|
+
id: group.id,
|
|
358
|
+
name: nameOf(group),
|
|
359
|
+
options: (group.options ?? []).map((option) => ({
|
|
360
|
+
id: option.id,
|
|
361
|
+
name: nameOf(option),
|
|
362
|
+
})),
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** `productList` cross-sellings are the extra groups; empty ones are left out. */
|
|
367
|
+
export function toExtraGroups(
|
|
368
|
+
elements: SwCrossSelling[] | undefined,
|
|
369
|
+
currency: CurrencyCode,
|
|
370
|
+
): ExtraGroup[] {
|
|
371
|
+
return (elements ?? []).flatMap((element) => {
|
|
372
|
+
const group = element.crossSelling;
|
|
373
|
+
const extras = (element.products ?? []).map((product) => ({
|
|
374
|
+
id: product.id,
|
|
375
|
+
number: product.productNumber,
|
|
376
|
+
name: nameOf(product),
|
|
377
|
+
price: priceOf(product.calculatedPrice, currency),
|
|
378
|
+
available: product.available !== false,
|
|
379
|
+
}));
|
|
380
|
+
return group && extras.length
|
|
381
|
+
? [{ id: group.id, name: nameOf(group), extras }]
|
|
382
|
+
: [];
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Menu sections are categories of type `page`; links and folders are not. */
|
|
387
|
+
export function toSection(category: SwCategory): MenuSection {
|
|
388
|
+
return {
|
|
389
|
+
id: category.id,
|
|
390
|
+
name: nameOf(category),
|
|
391
|
+
description: text(translated(category, "description")),
|
|
392
|
+
icon: text(customField(category, ICON_FIELD)),
|
|
393
|
+
media: toMedia(category.media),
|
|
394
|
+
path: category.seoUrl || null,
|
|
395
|
+
seo: {
|
|
396
|
+
title: text(translated(category, "metaTitle")),
|
|
397
|
+
description: text(translated(category, "metaDescription")),
|
|
398
|
+
indexable: category.active !== false,
|
|
399
|
+
},
|
|
400
|
+
children: toSections(category.children),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function toSections(categories: SwCategory[] | null | undefined) {
|
|
405
|
+
return (categories ?? [])
|
|
406
|
+
.filter((category) => (category.type ?? "page") === "page")
|
|
407
|
+
.map(toSection);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function toListingFilters(listing: SwListing): ListingFilter[] {
|
|
411
|
+
return (listing.aggregations?.properties?.entities ?? []).map((group) => ({
|
|
412
|
+
id: group.id,
|
|
413
|
+
name: nameOf(group),
|
|
414
|
+
options: (group.options ?? []).map((option) => ({
|
|
415
|
+
id: option.id,
|
|
416
|
+
name: nameOf(option),
|
|
417
|
+
})),
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function toListing(
|
|
422
|
+
listing: SwListing,
|
|
423
|
+
currency: CurrencyCode,
|
|
424
|
+
): MenuListing {
|
|
425
|
+
return {
|
|
426
|
+
dishes: (listing.elements ?? []).map((product) =>
|
|
427
|
+
toDish(product, currency),
|
|
428
|
+
),
|
|
429
|
+
total: listing.total ?? listing.elements?.length ?? 0,
|
|
430
|
+
page: listing.page ?? 1,
|
|
431
|
+
limit: listing.limit ?? PAGE_SIZE,
|
|
432
|
+
filters: toListingFilters(listing),
|
|
433
|
+
sortings: (listing.availableSortings ?? []).map((sorting) => ({
|
|
434
|
+
key: sorting.key,
|
|
435
|
+
label: translated(sorting, "label") ?? sorting.key,
|
|
436
|
+
})),
|
|
437
|
+
sorting: listing.sorting ?? null,
|
|
438
|
+
filterOptionIds: listing.currentFilters?.properties ?? [],
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const EMPTY_LISTING: MenuListing = deepFreeze({
|
|
443
|
+
dishes: [],
|
|
444
|
+
total: 0,
|
|
445
|
+
page: 1,
|
|
446
|
+
limit: PAGE_SIZE,
|
|
447
|
+
filters: [],
|
|
448
|
+
sortings: [],
|
|
449
|
+
sorting: null,
|
|
450
|
+
filterOptionIds: [],
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
/** The criteria of a listing query; Shopware ignores an unknown sorting. */
|
|
454
|
+
function listingCriteria(query: ListingQuery) {
|
|
455
|
+
return {
|
|
456
|
+
...DISH_CRITERIA,
|
|
457
|
+
limit: PAGE_SIZE,
|
|
458
|
+
...(query.sorting && { order: query.sorting }),
|
|
459
|
+
...(query.filterOptionIds?.length && {
|
|
460
|
+
properties: [...new Set(query.filterOptionIds)].join("|"),
|
|
461
|
+
}),
|
|
462
|
+
...(query.page && query.page > 1 && { p: query.page }),
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Shopware falls back to its default for a sorting it does not offer. */
|
|
467
|
+
function checkSorting(listing: SwListing, query: ListingQuery): void {
|
|
468
|
+
if (
|
|
469
|
+
query.sorting &&
|
|
470
|
+
!(listing.availableSortings ?? []).some(
|
|
471
|
+
(sorting) => sorting.key === query.sorting,
|
|
472
|
+
)
|
|
473
|
+
) {
|
|
474
|
+
throw new DomainError(
|
|
475
|
+
"invalid_value",
|
|
476
|
+
`The listing does not offer the sorting ${query.sorting}.`,
|
|
477
|
+
{ sorting: query.sorting },
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export type ShopwareCatalogOptions = Readonly<{
|
|
483
|
+
/** `public.shopBite.menuCategoryId`: overrides the plugin's menu root. */
|
|
484
|
+
menuCategoryId?: string;
|
|
485
|
+
/** Where a part left out of an answer is reported. */
|
|
486
|
+
log?: AdapterLog;
|
|
487
|
+
/** How long the sales channel's currency is kept, in ms. */
|
|
488
|
+
currencyTtlMs?: number;
|
|
489
|
+
}>;
|
|
490
|
+
|
|
491
|
+
/** The sales channel's currency changes with its settings only. */
|
|
492
|
+
const CURRENCY_TTL_MS = 10 * 60_000;
|
|
493
|
+
|
|
494
|
+
/** The currency and locale of the sales channel's prices. */
|
|
495
|
+
export type PriceFormat = Readonly<{ currency: CurrencyCode; locale: string }>;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* The sales channel's price format from its context without a visitor
|
|
499
|
+
* (`/context`: currency, `languageInfo.localeCode`): one request per
|
|
500
|
+
* `ttlMs` instead of one per answer; a failure is not kept.
|
|
501
|
+
*/
|
|
502
|
+
export function priceFormatReader(
|
|
503
|
+
storeApi: StoreApi,
|
|
504
|
+
ttlMs: number = CURRENCY_TTL_MS,
|
|
505
|
+
): () => Promise<PriceFormat> {
|
|
506
|
+
let kept: { at: number; format: Promise<PriceFormat> } | undefined;
|
|
507
|
+
return () => {
|
|
508
|
+
if (!kept || Date.now() - kept.at > ttlMs) {
|
|
509
|
+
const entry = {
|
|
510
|
+
at: Date.now(),
|
|
511
|
+
format: request("the context", () =>
|
|
512
|
+
storeApi.get<{
|
|
513
|
+
currency?: { isoCode?: string };
|
|
514
|
+
languageInfo?: { localeCode?: string };
|
|
515
|
+
}>("/context"),
|
|
516
|
+
).then((context) => ({
|
|
517
|
+
currency: context?.currency?.isoCode || "EUR",
|
|
518
|
+
locale: context?.languageInfo?.localeCode || "de-DE",
|
|
519
|
+
})),
|
|
520
|
+
};
|
|
521
|
+
kept = entry;
|
|
522
|
+
entry.format.catch(() => {
|
|
523
|
+
if (kept === entry) kept = undefined;
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
return kept.format;
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** The sales channel's currency, in which every price is. */
|
|
531
|
+
export function currencyReader(
|
|
532
|
+
storeApi: StoreApi,
|
|
533
|
+
ttlMs: number = CURRENCY_TTL_MS,
|
|
534
|
+
): () => Promise<CurrencyCode> {
|
|
535
|
+
return currencyOf(priceFormatReader(storeApi, ttlMs));
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export const currencyOf =
|
|
539
|
+
(format: () => Promise<PriceFormat>): (() => Promise<CurrencyCode>) =>
|
|
540
|
+
async () =>
|
|
541
|
+
(await format()).currency;
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Variants in a fixed order, their ids (the order Shopware lists them in
|
|
545
|
+
* without a sorting), so a partial choice always finds the same variant.
|
|
546
|
+
*/
|
|
547
|
+
const VARIANT_ORDER = [{ field: "id", order: "ASC" }];
|
|
548
|
+
|
|
549
|
+
const EXTRAS_CRITERIA = {
|
|
550
|
+
includes: {
|
|
551
|
+
cross_selling_element: ["crossSelling", "products"],
|
|
552
|
+
cross_selling: ["id", "name", "translated"],
|
|
553
|
+
product: [
|
|
554
|
+
"id",
|
|
555
|
+
"productNumber",
|
|
556
|
+
"name",
|
|
557
|
+
"translated",
|
|
558
|
+
"calculatedPrice",
|
|
559
|
+
"available",
|
|
560
|
+
],
|
|
561
|
+
calculated_price: ["unitPrice", "totalPrice"],
|
|
562
|
+
},
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* CatalogPort over the Store API with the ShopBite conventions: property
|
|
567
|
+
* groups by name, `productList` cross-sellings as extras, child products
|
|
568
|
+
* as variants, custom fields of the ShopBite plugin. No caching of menu
|
|
569
|
+
* data here (ADR 0001); only the sales channel's currency, in which every
|
|
570
|
+
* price is, is kept for a while.
|
|
571
|
+
*/
|
|
572
|
+
export function createShopwareCatalog(
|
|
573
|
+
storeApi: StoreApi,
|
|
574
|
+
options: ShopwareCatalogOptions = {},
|
|
575
|
+
): CatalogPort {
|
|
576
|
+
const log: AdapterLog = options.log ?? (() => {});
|
|
577
|
+
const post = <T>(
|
|
578
|
+
what: string,
|
|
579
|
+
path: string,
|
|
580
|
+
body: Record<string, unknown>,
|
|
581
|
+
headers?: Record<string, string>,
|
|
582
|
+
) =>
|
|
583
|
+
request(what, () => storeApi.post<T>(path, body, headers && { headers }));
|
|
584
|
+
|
|
585
|
+
const currency = currencyReader(storeApi, options.currencyTtlMs);
|
|
586
|
+
|
|
587
|
+
const menuRoot = menuRootReader(storeApi, options.menuCategoryId);
|
|
588
|
+
|
|
589
|
+
const navigation = (root: string) =>
|
|
590
|
+
post<SwCategory[]>(
|
|
591
|
+
`the navigation of ${root}`,
|
|
592
|
+
`/navigation/${root}/${root}`,
|
|
593
|
+
{
|
|
594
|
+
depth: 5,
|
|
595
|
+
buildTree: true,
|
|
596
|
+
includes: CATEGORY_INCLUDES,
|
|
597
|
+
associations: { media: {} },
|
|
598
|
+
},
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
const searchProducts = (what: string, criteria: Record<string, unknown>) =>
|
|
602
|
+
post<{ elements?: SwProduct[] }>(
|
|
603
|
+
what,
|
|
604
|
+
"/product",
|
|
605
|
+
{ ...DISH_CRITERIA, ...criteria },
|
|
606
|
+
DISH_HEADERS,
|
|
607
|
+
).then((result) => result.elements ?? []);
|
|
608
|
+
|
|
609
|
+
/** A parent and its variants. */
|
|
610
|
+
const family = (parentId: string) =>
|
|
611
|
+
searchProducts(`the variants of ${parentId}`, {
|
|
612
|
+
filter: [
|
|
613
|
+
{
|
|
614
|
+
type: "multi",
|
|
615
|
+
operator: "or",
|
|
616
|
+
queries: [
|
|
617
|
+
{ type: "equals", field: "id", value: parentId },
|
|
618
|
+
{ type: "equals", field: "parentId", value: parentId },
|
|
619
|
+
],
|
|
620
|
+
},
|
|
621
|
+
],
|
|
622
|
+
sort: VARIANT_ORDER,
|
|
623
|
+
limit: PAGE_SIZE,
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
async function listing(
|
|
627
|
+
what: string,
|
|
628
|
+
path: string,
|
|
629
|
+
body: Record<string, unknown>,
|
|
630
|
+
query: ListingQuery,
|
|
631
|
+
): Promise<MenuListing> {
|
|
632
|
+
const page = query.page ?? 1;
|
|
633
|
+
const [result, code] = await Promise.all([
|
|
634
|
+
post<SwListing>(
|
|
635
|
+
what,
|
|
636
|
+
path,
|
|
637
|
+
{ ...listingCriteria(query), ...body },
|
|
638
|
+
{ "sw-include-seo-urls": "true" },
|
|
639
|
+
).catch((error: unknown) => {
|
|
640
|
+
// Shopware refuses a page after the last one; the port answers it
|
|
641
|
+
// empty
|
|
642
|
+
if (
|
|
643
|
+
page > 1 &&
|
|
644
|
+
isDomainError(error, "not_found") &&
|
|
645
|
+
errorCodes(error.cause).includes(PAGE_OUT_OF_RANGE)
|
|
646
|
+
) {
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
throw error;
|
|
650
|
+
}),
|
|
651
|
+
currency(),
|
|
652
|
+
]);
|
|
653
|
+
if (!result) {
|
|
654
|
+
return deepFreeze({
|
|
655
|
+
...EMPTY_LISTING,
|
|
656
|
+
page,
|
|
657
|
+
sorting: query.sorting ?? null,
|
|
658
|
+
filterOptionIds: [...new Set(query.filterOptionIds ?? [])],
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
checkSorting(result, query);
|
|
662
|
+
return deepFreeze(toListing(result, code));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* The dish sheet. A known parent (from the number search) lets its
|
|
667
|
+
* variants load together with the detail instead of after it.
|
|
668
|
+
*/
|
|
669
|
+
async function getDish(
|
|
670
|
+
dishId: Id,
|
|
671
|
+
knownParentId: string | null = null,
|
|
672
|
+
): Promise<DishDetail> {
|
|
673
|
+
const [detail, crossSellings, code, knownFamily] = await Promise.all([
|
|
674
|
+
post<{ product: SwProduct; configurator?: SwGroup[] }>(
|
|
675
|
+
`the dish ${dishId}`,
|
|
676
|
+
`/product/${dishId}`,
|
|
677
|
+
DISH_CRITERIA,
|
|
678
|
+
DISH_HEADERS,
|
|
679
|
+
),
|
|
680
|
+
post<SwCrossSelling[]>(
|
|
681
|
+
`the extras of ${dishId}`,
|
|
682
|
+
`/product/${dishId}/cross-selling`,
|
|
683
|
+
EXTRAS_CRITERIA,
|
|
684
|
+
).catch((error: unknown) => {
|
|
685
|
+
// the sheet opens without extras rather than not at all; a refusal
|
|
686
|
+
// or an unknown dish is an answer (the detail request reports it),
|
|
687
|
+
// only an outage is worth a log entry
|
|
688
|
+
if (
|
|
689
|
+
!isDomainError(error, "invalid_value") &&
|
|
690
|
+
!isDomainError(error, "not_found")
|
|
691
|
+
) {
|
|
692
|
+
log("Shopware: left out the extras of a dish that did not load.", {
|
|
693
|
+
dishId,
|
|
694
|
+
error,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
return [] as SwCrossSelling[];
|
|
698
|
+
}),
|
|
699
|
+
currency(),
|
|
700
|
+
knownParentId ? family(knownParentId) : undefined,
|
|
701
|
+
]);
|
|
702
|
+
const product = detail.product;
|
|
703
|
+
// the detail route answers a parent with its default variant
|
|
704
|
+
const parentId =
|
|
705
|
+
product.parentId ?? ((product.childCount ?? 0) > 0 ? product.id : null);
|
|
706
|
+
const members = !parentId
|
|
707
|
+
? []
|
|
708
|
+
: parentId === knownParentId && knownFamily
|
|
709
|
+
? knownFamily
|
|
710
|
+
: await family(parentId);
|
|
711
|
+
const parent =
|
|
712
|
+
members.find((candidate) => candidate.id === parentId) ?? product;
|
|
713
|
+
const dish = toDish(parent, code);
|
|
714
|
+
const variants = members
|
|
715
|
+
.filter((candidate) => candidate.parentId === parent.id)
|
|
716
|
+
.map((candidate) => toVariant(candidate, dish, code));
|
|
717
|
+
return deepFreeze({
|
|
718
|
+
...dish,
|
|
719
|
+
// a parent whose variants did not load is still a choice
|
|
720
|
+
needsChoice: dish.needsChoice || variants.length > 0,
|
|
721
|
+
priceFrom: dish.priceFrom || variants.length > 0,
|
|
722
|
+
variantGroups: toVariantGroups(detail.configurator),
|
|
723
|
+
variants,
|
|
724
|
+
selectedVariantId: product.parentId ? product.id : null,
|
|
725
|
+
extraGroups: toExtraGroups(crossSellings, code),
|
|
726
|
+
upsell: customField(parent, UPSELL_FIELD) === true,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return {
|
|
731
|
+
getMenu: async () =>
|
|
732
|
+
deepFreeze(toSections(await navigation(await menuRoot()))),
|
|
733
|
+
getSection: async (sectionId) => {
|
|
734
|
+
const [category, children] = await Promise.all([
|
|
735
|
+
post<SwCategory>(`the section ${sectionId}`, `/category/${sectionId}`, {
|
|
736
|
+
includes: CATEGORY_INCLUDES,
|
|
737
|
+
}),
|
|
738
|
+
navigation(sectionId),
|
|
739
|
+
]);
|
|
740
|
+
return deepFreeze({
|
|
741
|
+
...toSection(category),
|
|
742
|
+
children: toSections(children),
|
|
743
|
+
});
|
|
744
|
+
},
|
|
745
|
+
listDishes: (sectionId, query = {}) =>
|
|
746
|
+
listing(
|
|
747
|
+
`the dishes of ${sectionId}`,
|
|
748
|
+
`/product-listing/${sectionId}`,
|
|
749
|
+
{},
|
|
750
|
+
query,
|
|
751
|
+
),
|
|
752
|
+
searchDishes: async (searchText, query = {}) => {
|
|
753
|
+
const search = searchText.trim();
|
|
754
|
+
if (!search) return EMPTY_LISTING;
|
|
755
|
+
return listing("the search", "/search", { search }, query);
|
|
756
|
+
},
|
|
757
|
+
listMenuDishes: async () => {
|
|
758
|
+
const code = await currency();
|
|
759
|
+
const products: SwProduct[] = [];
|
|
760
|
+
for (let page = 1; page <= MAX_MENU_PAGES; page++) {
|
|
761
|
+
const elements = await searchProducts("the menu", {
|
|
762
|
+
// main products only; extras have no section
|
|
763
|
+
filter: [{ type: "equals", field: "parentId", value: null }],
|
|
764
|
+
limit: PAGE_SIZE,
|
|
765
|
+
page,
|
|
766
|
+
});
|
|
767
|
+
products.push(...elements);
|
|
768
|
+
if (elements.length < PAGE_SIZE) break;
|
|
769
|
+
}
|
|
770
|
+
return deepFreeze(
|
|
771
|
+
products
|
|
772
|
+
.filter((product) => (product.categoryIds ?? []).length > 0)
|
|
773
|
+
.map((product) => toDish(product, code)),
|
|
774
|
+
);
|
|
775
|
+
},
|
|
776
|
+
getDish: (dishId) => getDish(dishId),
|
|
777
|
+
findDishByNumber: async (number) => {
|
|
778
|
+
const [product] = await searchProducts(`the dish number ${number}`, {
|
|
779
|
+
filter: [{ type: "equals", field: "productNumber", value: number }],
|
|
780
|
+
limit: 1,
|
|
781
|
+
});
|
|
782
|
+
if (!product) return null;
|
|
783
|
+
const parentId =
|
|
784
|
+
product.parentId ?? ((product.childCount ?? 0) > 0 ? product.id : null);
|
|
785
|
+
return getDish(product.id, parentId);
|
|
786
|
+
},
|
|
787
|
+
findVariant: async (dishId, optionIds) => {
|
|
788
|
+
if (!optionIds.length) return null;
|
|
789
|
+
const [[variant], code] = await Promise.all([
|
|
790
|
+
searchProducts(`a variant of ${dishId}`, {
|
|
791
|
+
filter: [
|
|
792
|
+
{ type: "equals", field: "parentId", value: dishId },
|
|
793
|
+
...optionIds.map((id) => ({
|
|
794
|
+
type: "equals",
|
|
795
|
+
field: "optionIds",
|
|
796
|
+
value: id,
|
|
797
|
+
})),
|
|
798
|
+
],
|
|
799
|
+
sort: VARIANT_ORDER,
|
|
800
|
+
limit: 1,
|
|
801
|
+
}).catch((error: unknown) => {
|
|
802
|
+
// an id Shopware does not take has no variants
|
|
803
|
+
if (isDomainError(error, "invalid_value")) return [];
|
|
804
|
+
throw error;
|
|
805
|
+
}),
|
|
806
|
+
currency(),
|
|
807
|
+
]);
|
|
808
|
+
return variant ? deepFreeze(toVariant(variant, undefined, code)) : null;
|
|
809
|
+
},
|
|
810
|
+
listTopSellers: async (limit) => {
|
|
811
|
+
const [products, code] = await Promise.all([
|
|
812
|
+
searchProducts("the top sellers", {
|
|
813
|
+
// variants of a marked parent inherit the mark
|
|
814
|
+
filter: [{ type: "equals", field: "markAsTopseller", value: true }],
|
|
815
|
+
limit,
|
|
816
|
+
}),
|
|
817
|
+
currency(),
|
|
818
|
+
]);
|
|
819
|
+
return deepFreeze(products.map((product) => toDish(product, code)));
|
|
820
|
+
},
|
|
821
|
+
listUpsellDishes: async (limit) => {
|
|
822
|
+
const [products, code] = await Promise.all([
|
|
823
|
+
searchProducts("the upsell dishes", {
|
|
824
|
+
filter: [
|
|
825
|
+
// a mark on a parent applies to its variants (inherited)
|
|
826
|
+
{
|
|
827
|
+
type: "equals",
|
|
828
|
+
field: `customFields.${UPSELL_FIELD}`,
|
|
829
|
+
value: true,
|
|
830
|
+
},
|
|
831
|
+
// no parents: Shopware counts only the children of main
|
|
832
|
+
// products, so the child count of a variant is null, not 0
|
|
833
|
+
{
|
|
834
|
+
type: "multi",
|
|
835
|
+
operator: "or",
|
|
836
|
+
queries: [
|
|
837
|
+
{ type: "equals", field: "childCount", value: 0 },
|
|
838
|
+
{ type: "equals", field: "childCount", value: null },
|
|
839
|
+
],
|
|
840
|
+
},
|
|
841
|
+
],
|
|
842
|
+
sort: [{ field: "name", order: "ASC" }],
|
|
843
|
+
limit,
|
|
844
|
+
}),
|
|
845
|
+
currency(),
|
|
846
|
+
]);
|
|
847
|
+
return deepFreeze(products.map((product) => toDish(product, code)));
|
|
848
|
+
},
|
|
849
|
+
};
|
|
850
|
+
}
|