@shopware/composables 1.11.1 → 1.12.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 +18 -13
- package/dist/index.d.mts +35 -5
- package/dist/index.d.ts +35 -5
- package/dist/index.mjs +167 -100
- package/nuxt.config.ts +10 -0
- package/package.json +14 -15
- 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 +2 -1
- package/src/useCart/useCart.test.ts +19 -0
- package/src/useCart/useCart.ts +6 -3
- package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
- package/src/useCartItem/useCartItem.test.ts +15 -0
- package/src/useCartItem/useCartItem.ts +15 -7
- 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 +104 -2
- package/src/useCategorySearch/useCategorySearch.ts +45 -23
- 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 +96 -6
- package/src/useCountries/useCountries.ts +19 -8
- 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 +30 -0
- package/src/useNavigationSearch/useNavigationSearch.ts +19 -12
- package/src/useNewsletter/useNewsletter.test.ts +1 -0
- package/src/useNewsletter/useNewsletter.ts +1 -0
- 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 +42 -2
- package/src/useProductReviews/useProductReviews.ts +18 -8
- 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 +84 -6
- package/src/useSessionContext/useSessionContext.ts +17 -2
- 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 +55 -2
- package/src/useUser/useUser.ts +34 -25
- package/src/useWishlist/useWishlist.test.ts +2 -0
- package/src/useWishlist/useWishlist.ts +1 -0
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { describe, expect, it, vi } from "vitest";
|
|
2
3
|
import { ref } from "vue";
|
|
4
|
+
|
|
5
|
+
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
3
7
|
import { useSetup } from "../_test";
|
|
4
8
|
import CountryMock from "../mocks/Country";
|
|
5
9
|
import { useCountries } from "./useCountries";
|
|
6
10
|
|
|
7
11
|
describe("useCountries", () => {
|
|
8
12
|
it("useCountries flow", async () => {
|
|
9
|
-
const { vm, injections } = await useSetup(useCountries, {
|
|
13
|
+
const { vm, injections } = await useSetup(() => useCountries(), {
|
|
10
14
|
apiClient: {
|
|
11
15
|
invoke: vi.fn().mockResolvedValue({
|
|
12
16
|
data: CountryMock,
|
|
@@ -28,7 +32,7 @@ describe("useCountries", () => {
|
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
it("useCountries flow - no states", async () => {
|
|
31
|
-
const { vm } = await useSetup(useCountries, {
|
|
35
|
+
const { vm } = await useSetup(() => useCountries(), {
|
|
32
36
|
apiClient: {
|
|
33
37
|
invoke: vi.fn().mockResolvedValue({
|
|
34
38
|
data: {
|
|
@@ -49,7 +53,7 @@ describe("useCountries", () => {
|
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
it("useCountries flow - empty", async () => {
|
|
52
|
-
const { vm } = await useSetup(useCountries, {
|
|
56
|
+
const { vm } = await useSetup(() => useCountries(), {
|
|
53
57
|
apiClient: {
|
|
54
58
|
invoke: vi.fn().mockResolvedValue({
|
|
55
59
|
data: {
|
|
@@ -64,7 +68,7 @@ describe("useCountries", () => {
|
|
|
64
68
|
});
|
|
65
69
|
|
|
66
70
|
it("useCountries flow - getCountriesOptions", async () => {
|
|
67
|
-
const { vm } = await useSetup(useCountries, {
|
|
71
|
+
const { vm } = await useSetup(() => useCountries(), {
|
|
68
72
|
apiClient: {
|
|
69
73
|
invoke: vi.fn().mockResolvedValue({
|
|
70
74
|
data: CountryMock,
|
|
@@ -91,7 +95,7 @@ describe("useCountries", () => {
|
|
|
91
95
|
});
|
|
92
96
|
|
|
93
97
|
it("useCountries flow - getCountriesOptions - empty array", async () => {
|
|
94
|
-
const { vm } = await useSetup(useCountries, {
|
|
98
|
+
const { vm } = await useSetup(() => useCountries(), {
|
|
95
99
|
apiClient: {
|
|
96
100
|
invoke: vi.fn().mockResolvedValue({
|
|
97
101
|
data: {
|
|
@@ -104,9 +108,95 @@ describe("useCountries", () => {
|
|
|
104
108
|
expect(vm.getCountriesOptions).toStrictEqual([]);
|
|
105
109
|
});
|
|
106
110
|
|
|
111
|
+
it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
112
|
+
const { vm, injections } = await useSetup(() => useCountries(), {
|
|
113
|
+
shopware: { cacheableReads: true },
|
|
114
|
+
apiClient: {
|
|
115
|
+
invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
|
|
116
|
+
},
|
|
117
|
+
} as Parameters<typeof useSetup>[1]);
|
|
118
|
+
await vm.fetchCountries();
|
|
119
|
+
|
|
120
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
121
|
+
expect.stringContaining("readCountryGet get"),
|
|
122
|
+
expect.objectContaining({
|
|
123
|
+
query: { _criteria: encodeForQuery({ associations: { states: {} } }) },
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("uses criteria passed to useCountries", async () => {
|
|
129
|
+
const criteria: Schemas["Criteria"] = { limit: 1 };
|
|
130
|
+
const { vm, injections } = await useSetup(() => useCountries(criteria), {
|
|
131
|
+
apiClient: {
|
|
132
|
+
invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
|
|
133
|
+
},
|
|
134
|
+
swCountries: ref([]),
|
|
135
|
+
} as Parameters<typeof useSetup>[1]);
|
|
136
|
+
|
|
137
|
+
await vm.fetchCountries();
|
|
138
|
+
|
|
139
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
140
|
+
expect.stringContaining("readCountry post"),
|
|
141
|
+
expect.objectContaining({
|
|
142
|
+
body: {
|
|
143
|
+
associations: { states: {} },
|
|
144
|
+
limit: 1,
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("uses criteria passed to useCountries for cacheable fetchCountries", async () => {
|
|
151
|
+
const criteria: Schemas["Criteria"] = { limit: 1 };
|
|
152
|
+
const { vm, injections } = await useSetup(() => useCountries(criteria), {
|
|
153
|
+
shopware: { cacheableReads: true },
|
|
154
|
+
apiClient: {
|
|
155
|
+
invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
|
|
156
|
+
},
|
|
157
|
+
swCountries: ref([]),
|
|
158
|
+
} as Parameters<typeof useSetup>[1]);
|
|
159
|
+
|
|
160
|
+
await vm.fetchCountries();
|
|
161
|
+
|
|
162
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
163
|
+
expect.stringContaining("readCountryGet get"),
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
query: {
|
|
166
|
+
_criteria: encodeForQuery({
|
|
167
|
+
associations: { states: {} },
|
|
168
|
+
limit: 1,
|
|
169
|
+
}),
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("uses criteria passed to useCountries on mountedCallback", async () => {
|
|
176
|
+
const criteria: Schemas["Criteria"] = { limit: 1 };
|
|
177
|
+
const { vm, injections } = await useSetup(() => useCountries(criteria), {
|
|
178
|
+
apiClient: {
|
|
179
|
+
invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
|
|
180
|
+
},
|
|
181
|
+
swCountries: ref(),
|
|
182
|
+
} as Parameters<typeof useSetup>[1]);
|
|
183
|
+
|
|
184
|
+
await vm.mountedCallback();
|
|
185
|
+
|
|
186
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
187
|
+
expect.stringContaining("readCountry post"),
|
|
188
|
+
expect.objectContaining({
|
|
189
|
+
body: {
|
|
190
|
+
associations: { states: {} },
|
|
191
|
+
limit: 1,
|
|
192
|
+
},
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
107
197
|
it("should not fetch when swCountries already populated", async () => {
|
|
108
198
|
const preloadedCountries = ref(CountryMock.elements);
|
|
109
|
-
const { vm, injections } = await useSetup(useCountries, {
|
|
199
|
+
const { vm, injections } = await useSetup(() => useCountries(), {
|
|
110
200
|
apiClient: { invoke: vi.fn() },
|
|
111
201
|
swCountries: preloadedCountries,
|
|
112
202
|
} as Parameters<typeof useSetup>[1]);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
2
|
+
import { defu } from "defu";
|
|
1
3
|
import { computed, inject, onMounted, provide, ref } from "vue";
|
|
2
4
|
import type { ComputedRef } from "vue";
|
|
5
|
+
|
|
3
6
|
import { useShopwareContext } from "#imports";
|
|
4
7
|
import type { Schemas, operations } from "#shopware";
|
|
5
8
|
|
|
@@ -23,20 +26,28 @@ export type UseCountriesReturn = {
|
|
|
23
26
|
* @public
|
|
24
27
|
* @category Context & Language
|
|
25
28
|
*/
|
|
26
|
-
export function useCountries(
|
|
27
|
-
|
|
29
|
+
export function useCountries(
|
|
30
|
+
criteria?: Schemas["Criteria"],
|
|
31
|
+
): UseCountriesReturn {
|
|
32
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
28
33
|
|
|
29
34
|
const _sharedCountries = inject("swCountries", ref());
|
|
30
35
|
provide("swCountries", _sharedCountries);
|
|
36
|
+
const searchCriteria = ref(criteria ?? {});
|
|
31
37
|
|
|
32
38
|
async function fetchCountries() {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
states: {},
|
|
37
|
-
},
|
|
39
|
+
const queryCriteria = defu(searchCriteria.value, {
|
|
40
|
+
associations: {
|
|
41
|
+
states: {},
|
|
38
42
|
},
|
|
39
|
-
});
|
|
43
|
+
} as Schemas["Criteria"]);
|
|
44
|
+
const result = cacheableReads
|
|
45
|
+
? await apiClient.invoke("readCountryGet get /country", {
|
|
46
|
+
query: { _criteria: encodeForQuery(queryCriteria) },
|
|
47
|
+
})
|
|
48
|
+
: await apiClient.invoke("readCountry post /country", {
|
|
49
|
+
body: queryCriteria,
|
|
50
|
+
});
|
|
40
51
|
_sharedCountries.value = result.data.elements;
|
|
41
52
|
return result.data;
|
|
42
53
|
}
|
|
@@ -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");
|
|
@@ -221,4 +224,31 @@ describe("useNavigationSearch", () => {
|
|
|
221
224
|
routeName: "frontend.navigation.page",
|
|
222
225
|
});
|
|
223
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
|
+
});
|
|
224
254
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import {
|
|
2
3
|
getRouteFromPathInfo,
|
|
3
4
|
isTechnicalPath,
|
|
4
5
|
normalizePath,
|
|
5
6
|
} from "@shopware/helpers";
|
|
7
|
+
|
|
6
8
|
import { useSessionContext, useShopwareContext } from "#imports";
|
|
7
9
|
import type { Schemas } from "#shopware";
|
|
8
10
|
|
|
@@ -20,7 +22,7 @@ export type UseNavigationSearchReturn = {
|
|
|
20
22
|
* @category Navigation & Routing
|
|
21
23
|
*/
|
|
22
24
|
export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
23
|
-
const { apiClient } = useShopwareContext();
|
|
25
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
24
26
|
const { sessionContext } = useSessionContext();
|
|
25
27
|
|
|
26
28
|
async function resolvePath(path: string): Promise<Schemas["SeoUrl"] | null> {
|
|
@@ -42,17 +44,22 @@ export function useNavigationSearch(): UseNavigationSearchReturn {
|
|
|
42
44
|
? normalizePath(path)
|
|
43
45
|
: path.substring(1);
|
|
44
46
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
});
|
|
56
63
|
|
|
57
64
|
const element = seoResult.data.elements?.[0];
|
|
58
65
|
if (element) {
|
|
@@ -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";
|