@shopware/composables 1.11.0 → 1.11.1
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/README.md +11 -9
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +13 -4
- package/package.json +12 -11
- package/src/useNavigationSearch/useNavigationSearch.test.ts +95 -2
- package/src/useNavigationSearch/useNavigationSearch.ts +18 -8
- package/src/useNewsletter/useNewsletter.test.ts +4 -1
- package/src/useNewsletter/useNewsletter.ts +4 -1
package/README.md
CHANGED
|
@@ -165,18 +165,20 @@ All composable functions are fully typed with TypeScript and they are registed g
|
|
|
165
165
|
|
|
166
166
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/composables/CHANGELOG.md)
|
|
167
167
|
|
|
168
|
-
### Latest changes: 1.11.
|
|
168
|
+
### Latest changes: 1.11.1
|
|
169
169
|
|
|
170
|
-
###
|
|
170
|
+
### Patch Changes
|
|
171
171
|
|
|
172
|
-
- [#
|
|
172
|
+
- [#2372](https://github.com/shopware/frontends/pull/2372) [`22fc8a7`](https://github.com/shopware/frontends/commit/22fc8a7301f6a7d2612d907ab73555978b651c00) Thanks [@patzick](https://github.com/patzick)! - Improve technical URL resolution for SSR and CSR page rendering.
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
This adds helpers to detect and normalize technical Shopware paths and updates
|
|
175
|
+
`useNavigationSearch` to resolve `/navigation/*`, `/detail/*`, and
|
|
176
|
+
`/landingPage/*` routes more reliably, including fallback behavior when no SEO
|
|
177
|
+
mapping row is returned.
|
|
175
178
|
|
|
176
|
-
- [#
|
|
179
|
+
- [#2407](https://github.com/shopware/frontends/pull/2407) [`bea7f58`](https://github.com/shopware/frontends/commit/bea7f5882cb58c6d47c84a82db5c8ecaf9bcf8ef) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Correct `useNewsletter` `subscribeToNewsletter` return type: it now resolves to the Store API response type for `POST /newsletter/subscribe` instead of `void`.
|
|
177
180
|
|
|
178
|
-
- [#
|
|
181
|
+
- [#2435](https://github.com/shopware/frontends/pull/2435) [`b8c0091`](https://github.com/shopware/frontends/commit/b8c00913c3afb5e1e63de9565105f8f8e3bf299f) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Update `useNewsletter` so `newsletterStatus` is set from the subscribe API response, keeping `isNewsletterSubscriber` in sync without an extra status request.
|
|
179
182
|
|
|
180
|
-
- Updated dependencies [[`
|
|
181
|
-
- @shopware/
|
|
182
|
-
- @shopware/helpers@1.7.0
|
|
183
|
+
- Updated dependencies [[`22fc8a7`](https://github.com/shopware/frontends/commit/22fc8a7301f6a7d2612d907ab73555978b651c00)]:
|
|
184
|
+
- @shopware/helpers@1.7.1
|
package/dist/index.d.mts
CHANGED
|
@@ -1374,7 +1374,7 @@ type UseNewsletterReturn = {
|
|
|
1374
1374
|
* Subscribes the user to the newsletter
|
|
1375
1375
|
* @param params {@link operations['subscribeToNewsletter post /newsletter/subscribe']['body']}
|
|
1376
1376
|
*/
|
|
1377
|
-
newsletterSubscribe(params: Omit<operations["subscribeToNewsletter post /newsletter/subscribe"]["body"], "storefrontUrl">): Promise<
|
|
1377
|
+
newsletterSubscribe(params: Omit<operations["subscribeToNewsletter post /newsletter/subscribe"]["body"], "storefrontUrl">): Promise<operations["subscribeToNewsletter post /newsletter/subscribe"]["response"]>;
|
|
1378
1378
|
/**
|
|
1379
1379
|
* Removes the email from the newsletter
|
|
1380
1380
|
* @param email
|
|
@@ -2343,4 +2343,5 @@ declare function getDefaultApiParams(): {
|
|
|
2343
2343
|
[composableName: string]: unknown;
|
|
2344
2344
|
};
|
|
2345
2345
|
|
|
2346
|
-
export {
|
|
2346
|
+
export { createCategoryListingContext, createListingComposable, createShopwareContext, getDefaultApiParams, resolveCmsComponent, useAddToCart, useAddress, useB2bQuoteManagement, useBreadcrumbs, useCart, useCartErrorParamsResolver, useCartFunction, useCartItem, useCartNotification, useCategory, useCategoryListing, useCategorySearch, useCheckout, useCmsBlock, useCmsElementConfig, useCmsElementImage, useCmsMeta, useCmsSection, useCmsTranslations, useContext, useCountries, useCustomerOrders, useCustomerPassword, useDefaultOrderAssociations, useInternationalization, useLandingSearch, useListing, useLocalWishlist, useNavigation, useNavigationContext, useNavigationSearch, useNewsletter, useNotifications, useOrderDetails, useOrderPayment, usePrice, useProduct, useProductAssociations, useProductConfigurator, useProductPrice, useProductReviews, useProductSearch, useProductSearchListing, useProductSearchSuggest, useProductWishlist, useSalutations, useSessionContext, useShopwareContext, useSyncWishlist, useUrlResolver, useUser, useWishlist };
|
|
2347
|
+
export type { BoxLayout, Breadcrumb, ChangePaymentShippingMethodParams, CmsBlockCategoryNavigation, CmsBlockCenterText, CmsBlockCrossSelling, CmsBlockForm, CmsBlockGalleryBuybox, CmsBlockHtml, CmsBlockImage, CmsBlockImageBubbleRow, CmsBlockImageCover, CmsBlockImageFourColumn, CmsBlockImageGallery, CmsBlockImageGalleryBig, CmsBlockImageHighlightRow, CmsBlockImageSimpleGrid, CmsBlockImageSlider, CmsBlockImageText, CmsBlockImageTextBubble, CmsBlockImageTextCover, CmsBlockImageTextGallery, CmsBlockImageTextRow, CmsBlockImageThreeColumn, CmsBlockImageThreeCover, CmsBlockImageTwoColumn, CmsBlockProductDescriptionReviews, CmsBlockProductHeading, CmsBlockProductListing, CmsBlockProductSlider, CmsBlockProductThreeColumn, CmsBlockSidebarFilter, CmsBlockText, CmsBlockTextHero, CmsBlockTextOnImage, CmsBlockTextTeaser, CmsBlockTextTeaserSection, CmsBlockTextThreeColumn, CmsBlockTextTwoColumn, CmsBlockVimeoVideo, CmsBlockYoutubeVideo, CmsElementBuyBox, CmsElementCategoryNavigation, CmsElementCrossSelling, CmsElementForm, CmsElementHtml, CmsElementImage, CmsElementImageGallery, CmsElementImageSlider, CmsElementManufacturerLogo, CmsElementProductBox, CmsElementProductDescriptionReviews, CmsElementProductListing, CmsElementProductName, CmsElementProductSlider, CmsElementSidebarFilter, CmsElementText, CmsElementVimeoVideo, CmsElementYoutubeVideo, CmsSectionBlock, CmsSectionDefault, CmsSectionSidebar, DisplayMode, ElementConfig, ErrorObjectParam, ImageContainerAttrs, ListingType, Notification, NotificationOptions, Position, RouteObject, ShopwareContext, ShortcutFilterParam, SliderElementConfig, SourceType, UseAddToCartReturn, UseAddressReturn, UseBreadcrumbsReturn, UseCartErrorParamsResolver, UseCartItemReturn, UseCartReturn, UseCategoryReturn, UseCategorySearchReturn, UseCheckoutReturn, UseCmsBlockReturn, UseCmsElementImage, UseCmsMetaReturn, UseCountriesReturn, UseCustomerOrdersReturn, UseCustomerPasswordReturn, UseInternationalizationReturn, UseLandingSearchReturn, UseListingReturn, UseLocalWishlistReturn, UseNavigationContextReturn, UseNavigationReturn, UseNavigationSearchReturn, UseNewsletterReturn, UseNotificationsReturn, UseOrderDetailsReturn, UseOrderPaymentReturn, UsePriceReturn, UseProductAssociationsReturn, UseProductConfiguratorReturn, UseProductPriceReturn, UseProductReturn, UseProductReviewsReturn, UseProductSearchReturn, UseProductSearchSuggestReturn, UseProductWishlistReturn, UseSalutationsReturn, UseSessionContextReturn, UseSyncWishlistReturn, UseUserReturn, UseWishlistReturn, VerticalAlign, useCartNotificationReturn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1374,7 +1374,7 @@ type UseNewsletterReturn = {
|
|
|
1374
1374
|
* Subscribes the user to the newsletter
|
|
1375
1375
|
* @param params {@link operations['subscribeToNewsletter post /newsletter/subscribe']['body']}
|
|
1376
1376
|
*/
|
|
1377
|
-
newsletterSubscribe(params: Omit<operations["subscribeToNewsletter post /newsletter/subscribe"]["body"], "storefrontUrl">): Promise<
|
|
1377
|
+
newsletterSubscribe(params: Omit<operations["subscribeToNewsletter post /newsletter/subscribe"]["body"], "storefrontUrl">): Promise<operations["subscribeToNewsletter post /newsletter/subscribe"]["response"]>;
|
|
1378
1378
|
/**
|
|
1379
1379
|
* Removes the email from the newsletter
|
|
1380
1380
|
* @param email
|
|
@@ -2343,4 +2343,5 @@ declare function getDefaultApiParams(): {
|
|
|
2343
2343
|
[composableName: string]: unknown;
|
|
2344
2344
|
};
|
|
2345
2345
|
|
|
2346
|
-
export {
|
|
2346
|
+
export { createCategoryListingContext, createListingComposable, createShopwareContext, getDefaultApiParams, resolveCmsComponent, useAddToCart, useAddress, useB2bQuoteManagement, useBreadcrumbs, useCart, useCartErrorParamsResolver, useCartFunction, useCartItem, useCartNotification, useCategory, useCategoryListing, useCategorySearch, useCheckout, useCmsBlock, useCmsElementConfig, useCmsElementImage, useCmsMeta, useCmsSection, useCmsTranslations, useContext, useCountries, useCustomerOrders, useCustomerPassword, useDefaultOrderAssociations, useInternationalization, useLandingSearch, useListing, useLocalWishlist, useNavigation, useNavigationContext, useNavigationSearch, useNewsletter, useNotifications, useOrderDetails, useOrderPayment, usePrice, useProduct, useProductAssociations, useProductConfigurator, useProductPrice, useProductReviews, useProductSearch, useProductSearchListing, useProductSearchSuggest, useProductWishlist, useSalutations, useSessionContext, useShopwareContext, useSyncWishlist, useUrlResolver, useUser, useWishlist };
|
|
2347
|
+
export type { BoxLayout, Breadcrumb, ChangePaymentShippingMethodParams, CmsBlockCategoryNavigation, CmsBlockCenterText, CmsBlockCrossSelling, CmsBlockForm, CmsBlockGalleryBuybox, CmsBlockHtml, CmsBlockImage, CmsBlockImageBubbleRow, CmsBlockImageCover, CmsBlockImageFourColumn, CmsBlockImageGallery, CmsBlockImageGalleryBig, CmsBlockImageHighlightRow, CmsBlockImageSimpleGrid, CmsBlockImageSlider, CmsBlockImageText, CmsBlockImageTextBubble, CmsBlockImageTextCover, CmsBlockImageTextGallery, CmsBlockImageTextRow, CmsBlockImageThreeColumn, CmsBlockImageThreeCover, CmsBlockImageTwoColumn, CmsBlockProductDescriptionReviews, CmsBlockProductHeading, CmsBlockProductListing, CmsBlockProductSlider, CmsBlockProductThreeColumn, CmsBlockSidebarFilter, CmsBlockText, CmsBlockTextHero, CmsBlockTextOnImage, CmsBlockTextTeaser, CmsBlockTextTeaserSection, CmsBlockTextThreeColumn, CmsBlockTextTwoColumn, CmsBlockVimeoVideo, CmsBlockYoutubeVideo, CmsElementBuyBox, CmsElementCategoryNavigation, CmsElementCrossSelling, CmsElementForm, CmsElementHtml, CmsElementImage, CmsElementImageGallery, CmsElementImageSlider, CmsElementManufacturerLogo, CmsElementProductBox, CmsElementProductDescriptionReviews, CmsElementProductListing, CmsElementProductName, CmsElementProductSlider, CmsElementSidebarFilter, CmsElementText, CmsElementVimeoVideo, CmsElementYoutubeVideo, CmsSectionBlock, CmsSectionDefault, CmsSectionSidebar, DisplayMode, ElementConfig, ErrorObjectParam, ImageContainerAttrs, ListingType, Notification, NotificationOptions, Position, RouteObject, ShopwareContext, ShortcutFilterParam, SliderElementConfig, SourceType, UseAddToCartReturn, UseAddressReturn, UseBreadcrumbsReturn, UseCartErrorParamsResolver, UseCartItemReturn, UseCartReturn, UseCategoryReturn, UseCategorySearchReturn, UseCheckoutReturn, UseCmsBlockReturn, UseCmsElementImage, UseCmsMetaReturn, UseCountriesReturn, UseCustomerOrdersReturn, UseCustomerPasswordReturn, UseInternationalizationReturn, UseLandingSearchReturn, UseListingReturn, UseLocalWishlistReturn, UseNavigationContextReturn, UseNavigationReturn, UseNavigationSearchReturn, UseNewsletterReturn, UseNotificationsReturn, UseOrderDetailsReturn, UseOrderPaymentReturn, UsePriceReturn, UseProductAssociationsReturn, UseProductConfiguratorReturn, UseProductPriceReturn, UseProductReturn, UseProductReviewsReturn, UseProductSearchReturn, UseProductSearchSuggestReturn, UseProductWishlistReturn, UseSalutationsReturn, UseSessionContextReturn, UseSyncWishlistReturn, UseUserReturn, UseWishlistReturn, VerticalAlign, useCartNotificationReturn };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pascalCase } from 'scule';
|
|
2
2
|
import { computed, effectScope, reactive, markRaw, inject, ref, provide, unref, onMounted, watch, resolveComponent } from 'vue';
|
|
3
|
-
import { urlIsAbsolute, relativeUrlSlash, getSrcSetForMedia, getMainImageUrl, getTranslatedProperty, getListingFilters, getProductTierPrices, buildUrlPrefix } from '@shopware/helpers';
|
|
3
|
+
import { urlIsAbsolute, relativeUrlSlash, getSrcSetForMedia, getMainImageUrl, getTranslatedProperty, getListingFilters, isTechnicalPath, normalizePath, getRouteFromPathInfo, getProductTierPrices, buildUrlPrefix } from '@shopware/helpers';
|
|
4
4
|
import { ApiClientError } from '@shopware/api-client';
|
|
5
5
|
import { createSharedComposable, injectLocal, provideLocal, createInjectionState, syncRefs } from '@vueuse/core';
|
|
6
6
|
import { defu } from 'defu';
|
|
@@ -1320,8 +1320,8 @@ function useNavigationSearch() {
|
|
|
1320
1320
|
foreignKey: categoryId
|
|
1321
1321
|
};
|
|
1322
1322
|
}
|
|
1323
|
-
const isTechnicalUrl =
|
|
1324
|
-
const normalizedPath = isTechnicalUrl ?
|
|
1323
|
+
const isTechnicalUrl = isTechnicalPath(path);
|
|
1324
|
+
const normalizedPath = isTechnicalUrl ? normalizePath(path) : path.substring(1);
|
|
1325
1325
|
const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
1326
1326
|
body: {
|
|
1327
1327
|
filter: [
|
|
@@ -1333,7 +1333,15 @@ function useNavigationSearch() {
|
|
|
1333
1333
|
]
|
|
1334
1334
|
}
|
|
1335
1335
|
});
|
|
1336
|
-
|
|
1336
|
+
const element = seoResult.data.elements?.[0];
|
|
1337
|
+
if (element) {
|
|
1338
|
+
return element;
|
|
1339
|
+
}
|
|
1340
|
+
const fallback = getRouteFromPathInfo(path);
|
|
1341
|
+
if (fallback) {
|
|
1342
|
+
return fallback;
|
|
1343
|
+
}
|
|
1344
|
+
return null;
|
|
1337
1345
|
}
|
|
1338
1346
|
return {
|
|
1339
1347
|
resolvePath
|
|
@@ -1356,6 +1364,7 @@ function useNewsletter() {
|
|
|
1356
1364
|
}
|
|
1357
1365
|
}
|
|
1358
1366
|
);
|
|
1367
|
+
newsletterStatus.value = result.data.status;
|
|
1359
1368
|
return result.data;
|
|
1360
1369
|
}
|
|
1361
1370
|
async function newsletterUnsubscribe(email) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -48,26 +48,27 @@
|
|
|
48
48
|
"src",
|
|
49
49
|
"composables",
|
|
50
50
|
"nuxt.config.ts",
|
|
51
|
-
"types"
|
|
51
|
+
"types",
|
|
52
|
+
"app.config.ts"
|
|
52
53
|
],
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@vueuse/core": "14.1.0",
|
|
55
|
-
"defu": "6.1.
|
|
56
|
+
"defu": "6.1.7",
|
|
56
57
|
"scule": "1.3.0",
|
|
57
|
-
"@shopware/helpers": "1.7.
|
|
58
|
+
"@shopware/helpers": "1.7.1",
|
|
58
59
|
"@shopware/api-client": "1.5.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@biomejs/biome": "1.8.3",
|
|
62
|
-
"@nuxt/kit": "4.
|
|
63
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
64
|
-
"@vitest/coverage-v8": "4.
|
|
65
|
-
"@vue/test-utils": "2.4.
|
|
66
|
-
"happy-dom": "20.
|
|
63
|
+
"@nuxt/kit": "4.4.6",
|
|
64
|
+
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
65
|
+
"@vitest/coverage-v8": "4.1.6",
|
|
66
|
+
"@vue/test-utils": "2.4.10",
|
|
67
|
+
"happy-dom": "20.9.0",
|
|
67
68
|
"typescript": "5.9.3",
|
|
68
69
|
"unbuild": "2.0.0",
|
|
69
|
-
"vitest": "4.
|
|
70
|
-
"vue": "3.5.
|
|
70
|
+
"vitest": "4.1.6",
|
|
71
|
+
"vue": "3.5.34",
|
|
71
72
|
"tsconfig": "0.0.0"
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
@@ -59,7 +59,10 @@ describe("useNavigationSearch", () => {
|
|
|
59
59
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
60
60
|
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
61
61
|
|
|
62
|
-
await vm.resolvePath("/landingPage/test")
|
|
62
|
+
await expect(vm.resolvePath("/landingPage/test")).resolves.toMatchObject({
|
|
63
|
+
routeName: "frontend.landing.page",
|
|
64
|
+
foreignKey: "test",
|
|
65
|
+
});
|
|
63
66
|
|
|
64
67
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
65
68
|
expect.stringContaining("readSeoUrl"),
|
|
@@ -80,7 +83,10 @@ describe("useNavigationSearch", () => {
|
|
|
80
83
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
81
84
|
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
82
85
|
|
|
83
|
-
await vm.resolvePath("/detail/test/")
|
|
86
|
+
await expect(vm.resolvePath("/detail/test/")).resolves.toMatchObject({
|
|
87
|
+
routeName: "frontend.detail.page",
|
|
88
|
+
foreignKey: "test",
|
|
89
|
+
});
|
|
84
90
|
|
|
85
91
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
86
92
|
expect.stringContaining("readSeoUrl"),
|
|
@@ -97,6 +103,93 @@ describe("useNavigationSearch", () => {
|
|
|
97
103
|
}),
|
|
98
104
|
);
|
|
99
105
|
});
|
|
106
|
+
it("should resolve navigation technical url by pathInfo", async () => {
|
|
107
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
108
|
+
const navigationSeoResponse = {
|
|
109
|
+
...mockedResponse,
|
|
110
|
+
routeName: "frontend.navigation.page",
|
|
111
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
112
|
+
pathInfo: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
113
|
+
};
|
|
114
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
115
|
+
data: { elements: [navigationSeoResponse] },
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(
|
|
119
|
+
await vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
|
|
120
|
+
).toStrictEqual(navigationSeoResponse);
|
|
121
|
+
|
|
122
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
123
|
+
expect.stringContaining("readSeoUrl"),
|
|
124
|
+
expect.objectContaining({
|
|
125
|
+
body: {
|
|
126
|
+
filter: [
|
|
127
|
+
{
|
|
128
|
+
type: "equals",
|
|
129
|
+
field: "pathInfo",
|
|
130
|
+
value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should synthesize navigation route when API returns no seo mapping for technical url", async () => {
|
|
139
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
140
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
141
|
+
|
|
142
|
+
await expect(
|
|
143
|
+
vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
|
|
144
|
+
).resolves.toMatchObject({
|
|
145
|
+
routeName: "frontend.navigation.page",
|
|
146
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should normalize navigation technical url with trailing slash", async () => {
|
|
151
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
152
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
153
|
+
|
|
154
|
+
await expect(
|
|
155
|
+
vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225/"),
|
|
156
|
+
).resolves.toMatchObject({
|
|
157
|
+
routeName: "frontend.navigation.page",
|
|
158
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
162
|
+
expect.stringContaining("readSeoUrl"),
|
|
163
|
+
expect.objectContaining({
|
|
164
|
+
body: {
|
|
165
|
+
filter: [
|
|
166
|
+
{
|
|
167
|
+
type: "equals",
|
|
168
|
+
field: "pathInfo",
|
|
169
|
+
value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should return null for non-technical path when API returns no mapping", async () => {
|
|
178
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
179
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
180
|
+
|
|
181
|
+
expect(
|
|
182
|
+
await vm.resolvePath("/some-seo-path-that-does-not-exist"),
|
|
183
|
+
).toBeNull();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should return null when technical path has no seo row and does not match a resolvable segment", async () => {
|
|
187
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
188
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
189
|
+
|
|
190
|
+
expect(await vm.resolvePath("/navigation/cat/extra/segment")).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
|
|
100
193
|
it("should not invoke api call for / search ", async () => {
|
|
101
194
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
102
195
|
injections.apiClient.invoke.mockResolvedValue({
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRouteFromPathInfo,
|
|
3
|
+
isTechnicalPath,
|
|
4
|
+
normalizePath,
|
|
5
|
+
} from "@shopware/helpers";
|
|
1
6
|
import { useSessionContext, useShopwareContext } from "#imports";
|
|
2
7
|
import type { Schemas } from "#shopware";
|
|
3
8
|
|
|
@@ -30,16 +35,11 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
|
30
35
|
} as Schemas["SeoUrl"];
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
const isTechnicalUrl =
|
|
34
|
-
path.startsWith("/navigation/") ||
|
|
35
|
-
path.startsWith("/detail/") ||
|
|
36
|
-
path.startsWith("/landingPage/");
|
|
38
|
+
const isTechnicalUrl = isTechnicalPath(path);
|
|
37
39
|
|
|
38
40
|
// remove leading slash in case of seo url or remove trailing slash in case of technical url
|
|
39
41
|
const normalizedPath = isTechnicalUrl
|
|
40
|
-
? path
|
|
41
|
-
? path.slice(0, -1)
|
|
42
|
-
: path
|
|
42
|
+
? normalizePath(path)
|
|
43
43
|
: path.substring(1);
|
|
44
44
|
|
|
45
45
|
const seoResult = await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
@@ -54,7 +54,17 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
|
54
54
|
},
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
const element = seoResult.data.elements?.[0];
|
|
58
|
+
if (element) {
|
|
59
|
+
return element;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const fallback = getRouteFromPathInfo(path);
|
|
63
|
+
if (fallback) {
|
|
64
|
+
return fallback as Schemas["SeoUrl"];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
return {
|
|
@@ -5,7 +5,9 @@ import { useNewsletter } from "./useNewsletter";
|
|
|
5
5
|
describe("useNewsletter", () => {
|
|
6
6
|
it("newsletter subscribe", async () => {
|
|
7
7
|
const { vm, injections } = useSetup(useNewsletter);
|
|
8
|
-
injections.apiClient.invoke.mockResolvedValue({
|
|
8
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
9
|
+
data: { status: "direct" },
|
|
10
|
+
});
|
|
9
11
|
|
|
10
12
|
await vm.newsletterSubscribe({
|
|
11
13
|
email: "test@shopware.com",
|
|
@@ -16,6 +18,7 @@ describe("useNewsletter", () => {
|
|
|
16
18
|
expect.stringContaining("subscribeToNewsletter"),
|
|
17
19
|
expect.anything(),
|
|
18
20
|
);
|
|
21
|
+
expect(vm.newsletterStatus).toBe("direct");
|
|
19
22
|
});
|
|
20
23
|
|
|
21
24
|
it("newsletter unsubscribe", async () => {
|
|
@@ -13,7 +13,9 @@ export type UseNewsletterReturn = {
|
|
|
13
13
|
operations["subscribeToNewsletter post /newsletter/subscribe"]["body"],
|
|
14
14
|
"storefrontUrl"
|
|
15
15
|
>,
|
|
16
|
-
): Promise<
|
|
16
|
+
): Promise<
|
|
17
|
+
operations["subscribeToNewsletter post /newsletter/subscribe"]["response"]
|
|
18
|
+
>;
|
|
17
19
|
/**
|
|
18
20
|
* Removes the email from the newsletter
|
|
19
21
|
* @param email
|
|
@@ -76,6 +78,7 @@ export function useNewsletter(): UseNewsletterReturn {
|
|
|
76
78
|
},
|
|
77
79
|
},
|
|
78
80
|
);
|
|
81
|
+
newsletterStatus.value = result.data.status;
|
|
79
82
|
return result.data;
|
|
80
83
|
}
|
|
81
84
|
|