@shopware/composables 1.11.0 → 1.12.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/README.md +11 -8
- package/dist/index.d.mts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.mjs +138 -79
- package/package.json +16 -16
- package/src/cms/useCmsElementConfig.test.ts +1 -0
- package/src/cms/useCmsElementConfig.ts +1 -0
- package/src/cms/useCmsElementImage.test.ts +1 -0
- package/src/cms/useCmsElementImage.ts +2 -0
- package/src/cms/useCmsElementProductBox.test.ts +1 -0
- package/src/cms/useCmsElementProductBox.ts +2 -0
- package/src/createShopwareContext.test.ts +1 -0
- package/src/createShopwareContext.ts +8 -0
- package/src/devtools/plugin.ts +13 -13
- package/src/helpers/ContextError.spec.ts +1 -0
- package/src/index.test.ts +2 -0
- package/src/index.ts +1 -0
- package/src/types/cmsElementTypes.ts +1 -0
- package/src/useAddToCart/useAddToCart.test.ts +1 -0
- package/src/useAddToCart/useAddToCart.ts +1 -0
- package/src/useAddress/useAddress.test.ts +2 -0
- package/src/useAddress/useAddress.ts +1 -0
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +1 -0
- package/src/useBreadcrumbs/useBreadcrumbs.test.ts +2 -0
- package/src/useBreadcrumbs/useBreadcrumbs.ts +1 -0
- package/src/useCart/useCart.test.ts +2 -0
- package/src/useCart/useCart.ts +1 -0
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
- package/src/useCartItem/useCartItem.test.ts +2 -0
- package/src/useCartItem/useCartItem.ts +1 -0
- package/src/useCartNotification/useCartNotification.test.ts +2 -0
- package/src/useCategory/useCategory.test.ts +2 -0
- package/src/useCategory/useCategory.ts +2 -0
- package/src/useCategorySearch/useCategorySearch.test.ts +29 -0
- package/src/useCategorySearch/useCategorySearch.ts +15 -7
- package/src/useCheckout/useCheckout.test.ts +1 -0
- package/src/useCheckout/useCheckout.ts +1 -0
- package/src/useCmsBlock/useCmsBlock.test.ts +2 -0
- package/src/useCmsMeta/useCmsMeta.test.ts +2 -0
- package/src/useCmsMeta/useCmsMeta.ts +1 -0
- package/src/useCmsSection/useCmsSection.test.ts +2 -0
- package/src/useCmsTranslations/useCmsTranslations.test.ts +2 -0
- package/src/useCountries/useCountries.test.ts +19 -0
- package/src/useCountries/useCountries.ts +14 -7
- package/src/useCustomerOrders/useCustomerOrders.test.ts +1 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +1 -0
- package/src/useCustomerPassword/useCustomerPassword.test.ts +1 -0
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +1 -0
- package/src/useInternationalization/useInternationalization.test.ts +14 -1
- package/src/useInternationalization/useInternationalization.ts +5 -3
- package/src/useLandingSearch/useLandingSearch.test.ts +1 -0
- package/src/useLandingSearch/useLandingSearch.ts +1 -0
- package/src/useListing/useListing.test.ts +2 -0
- package/src/useListing/useListing.ts +3 -2
- package/src/useLocalWishlist/useLocalWishlist.test.ts +1 -0
- package/src/useNavigation/useNavigation.test.ts +24 -1
- package/src/useNavigation/useNavigation.ts +36 -14
- package/src/useNavigationContext/useNavigationContext.test.ts +1 -0
- package/src/useNavigationContext/useNavigationContext.ts +1 -0
- package/src/useNavigationSearch/useNavigationSearch.test.ts +125 -2
- package/src/useNavigationSearch/useNavigationSearch.ts +38 -21
- package/src/useNewsletter/useNewsletter.test.ts +5 -1
- package/src/useNewsletter/useNewsletter.ts +5 -1
- package/src/useNotifications/useNotifications.test.ts +1 -0
- package/src/useOrderDetails/useOrderDetails.test.ts +1 -0
- package/src/useOrderDetails/useOrderDetails.ts +1 -0
- package/src/useOrderPayment/useOrderPayment.test.ts +2 -0
- package/src/useOrderPayment/useOrderPayment.ts +1 -0
- package/src/usePrice/usePrice.test.ts +2 -0
- package/src/usePrice/usePrice.ts +1 -0
- package/src/useProduct/useProduct.test.ts +2 -0
- package/src/useProduct/useProduct.ts +2 -0
- package/src/useProductAssociations/useProductAssociations.spec.ts +48 -0
- package/src/useProductAssociations/useProductAssociations.ts +7 -3
- package/src/useProductConfigurator/useProductConfigurator.spec.ts +24 -0
- package/src/useProductConfigurator/useProductConfigurator.ts +20 -13
- package/src/useProductPrice/useProductPrice.test.ts +2 -0
- package/src/useProductPrice/useProductPrice.ts +1 -0
- package/src/useProductReviews/useProductReviews.test.ts +1 -0
- package/src/useProductReviews/useProductReviews.ts +1 -0
- package/src/useProductSearch/useProductSearch.test.ts +24 -1
- package/src/useProductSearch/useProductSearch.ts +24 -11
- package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +1 -0
- package/src/useProductSearchSuggest/useProductSearchSuggest.ts +1 -0
- package/src/useProductWishlist/useProductWishlist.test.ts +2 -0
- package/src/useProductWishlist/useProductWishlist.ts +1 -0
- package/src/useSalutations/useSalutations.spec.ts +15 -0
- package/src/useSalutations/useSalutations.ts +5 -2
- package/src/useSessionContext/useSessionContext.test.ts +18 -0
- package/src/useSessionContext/useSessionContext.ts +10 -0
- package/src/useShopwareContext/useShopwareContext.test.ts +1 -0
- package/src/useShopwareContext/useShopwareContext.ts +13 -0
- package/src/useSyncWishlist/useSyncWishlist.test.ts +1 -0
- package/src/useSyncWishlist/useSyncWishlist.ts +1 -0
- package/src/useUrlResolver/useUrlResolver.test.ts +1 -0
- package/src/useUser/useUser.test.ts +35 -2
- package/src/useUser/useUser.ts +34 -25
- package/src/useWishlist/useWishlist.test.ts +2 -0
- package/src/useWishlist/useWishlist.ts +1 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
2
3
|
import type { Schemas } from "#shopware";
|
|
4
|
+
|
|
3
5
|
import { useSetup } from "../_test";
|
|
4
6
|
import { useInternationalization } from "./useInternationalization";
|
|
5
7
|
import type { RouteObject } from "./useInternationalization";
|
|
@@ -28,7 +30,18 @@ describe("useInternationalization", () => {
|
|
|
28
30
|
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
29
31
|
vm.getAvailableLanguages();
|
|
30
32
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
31
|
-
expect.stringContaining("readLanguages"),
|
|
33
|
+
expect.stringContaining("readLanguages post"),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("getAvailableLanguages uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
38
|
+
const { vm, injections } = useSetup(useInternationalization, {
|
|
39
|
+
shopware: { cacheableReads: true },
|
|
40
|
+
} as Parameters<typeof useSetup>[1]);
|
|
41
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
42
|
+
await vm.getAvailableLanguages();
|
|
43
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
44
|
+
"readLanguagesGet get /language",
|
|
32
45
|
);
|
|
33
46
|
});
|
|
34
47
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { urlIsAbsolute } from "@shopware/helpers";
|
|
2
2
|
import type { Ref } from "vue";
|
|
3
|
+
|
|
3
4
|
import { useContext, useShopwareContext } from "#imports";
|
|
4
5
|
import type { Schemas, operations } from "#shopware";
|
|
5
6
|
|
|
@@ -80,8 +81,7 @@ export type RouteObject = {
|
|
|
80
81
|
export function useInternationalization(
|
|
81
82
|
pathResolver?: (path: string) => string,
|
|
82
83
|
): UseInternationalizationReturn {
|
|
83
|
-
const { devStorefrontUrl } = useShopwareContext();
|
|
84
|
-
const { apiClient } = useShopwareContext();
|
|
84
|
+
const { devStorefrontUrl, apiClient, cacheableReads } = useShopwareContext();
|
|
85
85
|
|
|
86
86
|
const _storeLanguages = useContext<Schemas["Language"][]>("swLanguages");
|
|
87
87
|
const _storeCurrentLanguage = useContext<string>(
|
|
@@ -94,7 +94,9 @@ export function useInternationalization(
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
async function getAvailableLanguages() {
|
|
97
|
-
const { data } =
|
|
97
|
+
const { data } = cacheableReads
|
|
98
|
+
? await apiClient.invoke("readLanguagesGet get /language")
|
|
99
|
+
: await apiClient.invoke("readLanguages post /language");
|
|
98
100
|
_storeLanguages.value = data.elements;
|
|
99
101
|
return data;
|
|
100
102
|
}
|
|
@@ -2,6 +2,7 @@ import { getListingFilters } from "@shopware/helpers";
|
|
|
2
2
|
import { createInjectionState, createSharedComposable } from "@vueuse/core";
|
|
3
3
|
import { computed, inject, provide, ref } from "vue";
|
|
4
4
|
import type { ComputedRef, Ref } from "vue";
|
|
5
|
+
|
|
5
6
|
import { useCategory, useShopwareContext } from "#imports";
|
|
6
7
|
import type { Schemas, operations } from "#shopware";
|
|
7
8
|
|
|
@@ -37,8 +38,8 @@ function merge<T extends { [key in keyof T]: unknown }>(
|
|
|
37
38
|
export type ListingType = "productSearchListing" | "categoryListing";
|
|
38
39
|
|
|
39
40
|
export type ShortcutFilterParam<
|
|
40
|
-
T extends
|
|
41
|
-
keyof Schemas["ProductListingCriteria"]
|
|
41
|
+
T extends keyof Schemas["ProductListingCriteria"] =
|
|
42
|
+
keyof Schemas["ProductListingCriteria"],
|
|
42
43
|
> = {
|
|
43
44
|
code: T;
|
|
44
45
|
value: Schemas["ProductListingCriteria"][T];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
2
4
|
import { useSetup } from "../_test";
|
|
3
5
|
import Menu from "../mocks/Menu";
|
|
4
6
|
import { useNavigation } from "./useNavigation";
|
|
@@ -59,10 +61,31 @@ describe("useNavigation", () => {
|
|
|
59
61
|
includes: { category: ["name"] },
|
|
60
62
|
});
|
|
61
63
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
62
|
-
expect.stringContaining("readNavigation"),
|
|
64
|
+
expect.stringContaining("readNavigation post"),
|
|
63
65
|
expect.objectContaining({
|
|
64
66
|
body: { depth: 2, includes: { category: ["name"] } },
|
|
65
67
|
}),
|
|
66
68
|
);
|
|
67
69
|
});
|
|
70
|
+
|
|
71
|
+
it("should use the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
72
|
+
const { vm, injections } = useSetup(useNavigation, {
|
|
73
|
+
shopware: { cacheableReads: true },
|
|
74
|
+
});
|
|
75
|
+
injections.apiClient.invoke.mockResolvedValue({ data: undefined });
|
|
76
|
+
|
|
77
|
+
await vm.loadNavigationElements({
|
|
78
|
+
depth: 2,
|
|
79
|
+
includes: { category: ["name"] },
|
|
80
|
+
});
|
|
81
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
82
|
+
expect.stringContaining("readNavigationGet get"),
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
query: {
|
|
85
|
+
_criteria: encodeForQuery({ includes: { category: ["name"] } }),
|
|
86
|
+
depth: 2,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
});
|
|
68
91
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { computed, inject, provide, ref } from "vue";
|
|
2
3
|
import type { ComputedRef, Ref } from "vue";
|
|
4
|
+
|
|
3
5
|
import { useShopwareContext } from "#imports";
|
|
4
6
|
import type { Schemas, operations } from "#shopware";
|
|
5
7
|
|
|
@@ -39,7 +41,7 @@ export function useNavigation(params?: {
|
|
|
39
41
|
}): UseNavigationReturn {
|
|
40
42
|
const type = params?.type || "main-navigation";
|
|
41
43
|
|
|
42
|
-
const { apiClient } = useShopwareContext();
|
|
44
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
43
45
|
|
|
44
46
|
const sharedElements: Ref<Schemas["NavigationRouteResponse"]> = inject(
|
|
45
47
|
`swNavigation-${type}`,
|
|
@@ -53,19 +55,39 @@ export function useNavigation(params?: {
|
|
|
53
55
|
params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"],
|
|
54
56
|
) {
|
|
55
57
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
// `buildTree`/`depth` are dedicated GET query params, not part of `_criteria`.
|
|
59
|
+
const { buildTree, depth, ...criteria } = params;
|
|
60
|
+
const navigationResponse = cacheableReads
|
|
61
|
+
? await apiClient.invoke(
|
|
62
|
+
"readNavigationGet get /navigation/{activeId}/{rootId}",
|
|
63
|
+
{
|
|
64
|
+
headers: {
|
|
65
|
+
"sw-include-seo-urls": true,
|
|
66
|
+
},
|
|
67
|
+
pathParams: {
|
|
68
|
+
activeId: type,
|
|
69
|
+
rootId: type,
|
|
70
|
+
},
|
|
71
|
+
query: {
|
|
72
|
+
_criteria: encodeForQuery(criteria),
|
|
73
|
+
buildTree,
|
|
74
|
+
depth,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
: await apiClient.invoke(
|
|
79
|
+
"readNavigation post /navigation/{activeId}/{rootId}",
|
|
80
|
+
{
|
|
81
|
+
headers: {
|
|
82
|
+
"sw-include-seo-urls": true,
|
|
83
|
+
},
|
|
84
|
+
pathParams: {
|
|
85
|
+
activeId: type,
|
|
86
|
+
rootId: type,
|
|
87
|
+
},
|
|
88
|
+
body: params,
|
|
89
|
+
},
|
|
90
|
+
);
|
|
69
91
|
|
|
70
92
|
sharedElements.value = navigationResponse.data || [];
|
|
71
93
|
return sharedElements.value;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { describe, expect, it, vi } from "vitest";
|
|
2
3
|
import { ref } from "vue";
|
|
4
|
+
|
|
3
5
|
import { useNavigationSearch, useSessionContext } from "#imports";
|
|
6
|
+
|
|
4
7
|
import { useSetup } from "../_test";
|
|
5
8
|
|
|
6
9
|
vi.mock("../useSessionContext/useSessionContext.ts");
|
|
@@ -59,7 +62,10 @@ describe("useNavigationSearch", () => {
|
|
|
59
62
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
60
63
|
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
61
64
|
|
|
62
|
-
await vm.resolvePath("/landingPage/test")
|
|
65
|
+
await expect(vm.resolvePath("/landingPage/test")).resolves.toMatchObject({
|
|
66
|
+
routeName: "frontend.landing.page",
|
|
67
|
+
foreignKey: "test",
|
|
68
|
+
});
|
|
63
69
|
|
|
64
70
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
65
71
|
expect.stringContaining("readSeoUrl"),
|
|
@@ -80,7 +86,10 @@ describe("useNavigationSearch", () => {
|
|
|
80
86
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
81
87
|
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
82
88
|
|
|
83
|
-
await vm.resolvePath("/detail/test/")
|
|
89
|
+
await expect(vm.resolvePath("/detail/test/")).resolves.toMatchObject({
|
|
90
|
+
routeName: "frontend.detail.page",
|
|
91
|
+
foreignKey: "test",
|
|
92
|
+
});
|
|
84
93
|
|
|
85
94
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
86
95
|
expect.stringContaining("readSeoUrl"),
|
|
@@ -97,6 +106,93 @@ describe("useNavigationSearch", () => {
|
|
|
97
106
|
}),
|
|
98
107
|
);
|
|
99
108
|
});
|
|
109
|
+
it("should resolve navigation technical url by pathInfo", async () => {
|
|
110
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
111
|
+
const navigationSeoResponse = {
|
|
112
|
+
...mockedResponse,
|
|
113
|
+
routeName: "frontend.navigation.page",
|
|
114
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
115
|
+
pathInfo: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
116
|
+
};
|
|
117
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
118
|
+
data: { elements: [navigationSeoResponse] },
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(
|
|
122
|
+
await vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
|
|
123
|
+
).toStrictEqual(navigationSeoResponse);
|
|
124
|
+
|
|
125
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
126
|
+
expect.stringContaining("readSeoUrl"),
|
|
127
|
+
expect.objectContaining({
|
|
128
|
+
body: {
|
|
129
|
+
filter: [
|
|
130
|
+
{
|
|
131
|
+
type: "equals",
|
|
132
|
+
field: "pathInfo",
|
|
133
|
+
value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should synthesize navigation route when API returns no seo mapping for technical url", async () => {
|
|
142
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
143
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
144
|
+
|
|
145
|
+
await expect(
|
|
146
|
+
vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225"),
|
|
147
|
+
).resolves.toMatchObject({
|
|
148
|
+
routeName: "frontend.navigation.page",
|
|
149
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should normalize navigation technical url with trailing slash", async () => {
|
|
154
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
155
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
156
|
+
|
|
157
|
+
await expect(
|
|
158
|
+
vm.resolvePath("/navigation/12b149be1e924fc45e4e43b5cdc49225/"),
|
|
159
|
+
).resolves.toMatchObject({
|
|
160
|
+
routeName: "frontend.navigation.page",
|
|
161
|
+
foreignKey: "12b149be1e924fc45e4e43b5cdc49225",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
165
|
+
expect.stringContaining("readSeoUrl"),
|
|
166
|
+
expect.objectContaining({
|
|
167
|
+
body: {
|
|
168
|
+
filter: [
|
|
169
|
+
{
|
|
170
|
+
type: "equals",
|
|
171
|
+
field: "pathInfo",
|
|
172
|
+
value: "/navigation/12b149be1e924fc45e4e43b5cdc49225",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("should return null for non-technical path when API returns no mapping", async () => {
|
|
181
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
182
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
183
|
+
|
|
184
|
+
expect(
|
|
185
|
+
await vm.resolvePath("/some-seo-path-that-does-not-exist"),
|
|
186
|
+
).toBeNull();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should return null when technical path has no seo row and does not match a resolvable segment", async () => {
|
|
190
|
+
const { vm, injections } = useSetup(useNavigationSearch);
|
|
191
|
+
injections.apiClient.invoke.mockResolvedValue({ data: { elements: [] } });
|
|
192
|
+
|
|
193
|
+
expect(await vm.resolvePath("/navigation/cat/extra/segment")).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
|
|
100
196
|
it("should not invoke api call for / search ", async () => {
|
|
101
197
|
const { vm, injections } = useSetup(useNavigationSearch);
|
|
102
198
|
injections.apiClient.invoke.mockResolvedValue({
|
|
@@ -128,4 +224,31 @@ describe("useNavigationSearch", () => {
|
|
|
128
224
|
routeName: "frontend.navigation.page",
|
|
129
225
|
});
|
|
130
226
|
});
|
|
227
|
+
|
|
228
|
+
it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
229
|
+
const { vm, injections } = useSetup(useNavigationSearch, {
|
|
230
|
+
shopware: { cacheableReads: true },
|
|
231
|
+
});
|
|
232
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
233
|
+
data: { elements: [mockedResponse] },
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(await vm.resolvePath("/test")).toStrictEqual(mockedResponse);
|
|
237
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
238
|
+
expect.stringContaining("readSeoUrlGet get"),
|
|
239
|
+
expect.objectContaining({
|
|
240
|
+
query: {
|
|
241
|
+
_criteria: encodeForQuery({
|
|
242
|
+
filter: [
|
|
243
|
+
{
|
|
244
|
+
type: "equals",
|
|
245
|
+
field: "seoPathInfo",
|
|
246
|
+
value: "test",
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
}),
|
|
250
|
+
},
|
|
251
|
+
}),
|
|
252
|
+
);
|
|
253
|
+
});
|
|
131
254
|
});
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
2
|
+
import {
|
|
3
|
+
getRouteFromPathInfo,
|
|
4
|
+
isTechnicalPath,
|
|
5
|
+
normalizePath,
|
|
6
|
+
} from "@shopware/helpers";
|
|
7
|
+
|
|
1
8
|
import { useSessionContext, useShopwareContext } from "#imports";
|
|
2
9
|
import type { Schemas } from "#shopware";
|
|
3
10
|
|
|
@@ -15,7 +22,7 @@ export type UseNavigationSearchReturn = {
|
|
|
15
22
|
* @category Navigation & Routing
|
|
16
23
|
*/
|
|
17
24
|
export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
18
|
-
const { apiClient } = useShopwareContext();
|
|
25
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
19
26
|
const { sessionContext } = useSessionContext();
|
|
20
27
|
|
|
21
28
|
async function resolvePath(path: string): Promise<Schemas["SeoUrl"] | null> {
|
|
@@ -30,31 +37,41 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
|
30
37
|
} as Schemas["SeoUrl"];
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
const isTechnicalUrl =
|
|
34
|
-
path.startsWith("/navigation/") ||
|
|
35
|
-
path.startsWith("/detail/") ||
|
|
36
|
-
path.startsWith("/landingPage/");
|
|
40
|
+
const isTechnicalUrl = isTechnicalPath(path);
|
|
37
41
|
|
|
38
42
|
// remove leading slash in case of seo url or remove trailing slash in case of technical url
|
|
39
43
|
const normalizedPath = isTechnicalUrl
|
|
40
|
-
? path
|
|
41
|
-
? path.slice(0, -1)
|
|
42
|
-
: path
|
|
44
|
+
? normalizePath(path)
|
|
43
45
|
: path.substring(1);
|
|
44
46
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
const criteria = {
|
|
48
|
+
filter: [
|
|
49
|
+
{
|
|
50
|
+
type: "equals" as const,
|
|
51
|
+
field: isTechnicalUrl ? "pathInfo" : "seoPathInfo",
|
|
52
|
+
value: normalizedPath,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
const seoResult = cacheableReads
|
|
57
|
+
? await apiClient.invoke("readSeoUrlGet get /seo-url", {
|
|
58
|
+
query: { _criteria: encodeForQuery(criteria) },
|
|
59
|
+
})
|
|
60
|
+
: await apiClient.invoke("readSeoUrl post /seo-url", {
|
|
61
|
+
body: criteria,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const element = seoResult.data.elements?.[0];
|
|
65
|
+
if (element) {
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const fallback = getRouteFromPathInfo(path);
|
|
70
|
+
if (fallback) {
|
|
71
|
+
return fallback as Schemas["SeoUrl"];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return null;
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
return {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
2
3
|
import { useSetup } from "../_test";
|
|
3
4
|
import { useNewsletter } from "./useNewsletter";
|
|
4
5
|
|
|
5
6
|
describe("useNewsletter", () => {
|
|
6
7
|
it("newsletter subscribe", async () => {
|
|
7
8
|
const { vm, injections } = useSetup(useNewsletter);
|
|
8
|
-
injections.apiClient.invoke.mockResolvedValue({
|
|
9
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
10
|
+
data: { status: "direct" },
|
|
11
|
+
});
|
|
9
12
|
|
|
10
13
|
await vm.newsletterSubscribe({
|
|
11
14
|
email: "test@shopware.com",
|
|
@@ -16,6 +19,7 @@ describe("useNewsletter", () => {
|
|
|
16
19
|
expect.stringContaining("subscribeToNewsletter"),
|
|
17
20
|
expect.anything(),
|
|
18
21
|
);
|
|
22
|
+
expect(vm.newsletterStatus).toBe("direct");
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
it("newsletter unsubscribe", async () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, ref } from "vue";
|
|
2
2
|
import type { ComputedRef, Ref } from "vue";
|
|
3
|
+
|
|
3
4
|
import { useInternationalization, useShopwareContext } from "#imports";
|
|
4
5
|
import type { Schemas, operations } from "#shopware";
|
|
5
6
|
|
|
@@ -13,7 +14,9 @@ export type UseNewsletterReturn = {
|
|
|
13
14
|
operations["subscribeToNewsletter post /newsletter/subscribe"]["body"],
|
|
14
15
|
"storefrontUrl"
|
|
15
16
|
>,
|
|
16
|
-
): Promise<
|
|
17
|
+
): Promise<
|
|
18
|
+
operations["subscribeToNewsletter post /newsletter/subscribe"]["response"]
|
|
19
|
+
>;
|
|
17
20
|
/**
|
|
18
21
|
* Removes the email from the newsletter
|
|
19
22
|
* @param email
|
|
@@ -76,6 +79,7 @@ export function useNewsletter(): UseNewsletterReturn {
|
|
|
76
79
|
},
|
|
77
80
|
},
|
|
78
81
|
);
|
|
82
|
+
newsletterStatus.value = result.data.status;
|
|
79
83
|
return result.data;
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
2
|
import { computed, inject, provide, ref } from "vue";
|
|
3
3
|
import type { ComputedRef, Ref } from "vue";
|
|
4
|
+
|
|
4
5
|
import { useDefaultOrderAssociations, useShopwareContext } from "#imports";
|
|
5
6
|
import type { Schemas, operations } from "#shopware";
|
|
6
7
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import type { ComputedRef } from "vue";
|
|
4
|
+
|
|
4
5
|
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
5
7
|
import { useSetup } from "../_test";
|
|
6
8
|
import Order from "../mocks/Order";
|
|
7
9
|
import { useOrderPayment } from "./useOrderPayment";
|
package/src/usePrice/usePrice.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
+
|
|
3
4
|
import type { Schemas } from "#shopware";
|
|
5
|
+
|
|
4
6
|
import { useSetup } from "../_test";
|
|
5
7
|
import mockedConfigurator from "../mocks/Configurator";
|
|
6
8
|
import mockedProduct from "../mocks/Product";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { computed, ref } from "vue";
|
|
3
|
+
|
|
3
4
|
import { useSetup } from "../_test";
|
|
4
5
|
import mockedCrossSelling from "../mocks/CrossSellingResponse";
|
|
5
6
|
import mockedProduct from "../mocks/Product";
|
|
@@ -90,6 +91,53 @@ describe("useProductAssociations", () => {
|
|
|
90
91
|
expect(vm.productAssociations).toStrictEqual(mockedCrossSelling);
|
|
91
92
|
});
|
|
92
93
|
|
|
94
|
+
it("sends sw-include-seo-urls header when includeSeoUrls is true", async () => {
|
|
95
|
+
const { vm, injections } = useSetup(() =>
|
|
96
|
+
useProductAssociations(
|
|
97
|
+
computed(() => mockedProduct),
|
|
98
|
+
{
|
|
99
|
+
associationContext: "cross-selling",
|
|
100
|
+
includeSeoUrls: true,
|
|
101
|
+
},
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
injections.apiClient.invoke.mockResolvedValue({ data: mockedCrossSelling });
|
|
105
|
+
|
|
106
|
+
await vm.loadAssociations({
|
|
107
|
+
method: "post",
|
|
108
|
+
searchParams: {},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
112
|
+
expect.stringContaining("readProductCrossSellings"),
|
|
113
|
+
expect.objectContaining({
|
|
114
|
+
headers: {
|
|
115
|
+
"sw-include-seo-urls": true,
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("omits sw-include-seo-urls header when includeSeoUrls is not set", async () => {
|
|
122
|
+
const { vm, injections } = useSetup(() =>
|
|
123
|
+
useProductAssociations(
|
|
124
|
+
computed(() => mockedProduct),
|
|
125
|
+
{
|
|
126
|
+
associationContext: "cross-selling",
|
|
127
|
+
},
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
injections.apiClient.invoke.mockResolvedValue({ data: mockedCrossSelling });
|
|
131
|
+
|
|
132
|
+
await vm.loadAssociations({
|
|
133
|
+
method: "post",
|
|
134
|
+
searchParams: {},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const invokeOptions = injections.apiClient.invoke.mock.calls[0]?.[1];
|
|
138
|
+
expect(invokeOptions).not.toHaveProperty("headers");
|
|
139
|
+
});
|
|
140
|
+
|
|
93
141
|
it("init without product should throw an error", () => {
|
|
94
142
|
expect(() =>
|
|
95
143
|
useSetup(() =>
|