@shopware/composables 1.11.1 → 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 +12 -11
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +125 -75
- package/package.json +11 -12
- 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 +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 +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,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";
|
|
@@ -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(() =>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, ref } from "vue";
|
|
2
2
|
import type { ComputedRef } from "vue";
|
|
3
|
+
|
|
3
4
|
import { useShopwareContext } from "#imports";
|
|
4
5
|
import type { Schemas } from "#shopware";
|
|
5
6
|
|
|
@@ -31,14 +32,12 @@ export function useProductAssociations(
|
|
|
31
32
|
product: ComputedRef<Schemas["Product"]>,
|
|
32
33
|
options: {
|
|
33
34
|
associationContext: "cross-selling" | "reviews";
|
|
35
|
+
includeSeoUrls?: boolean;
|
|
34
36
|
},
|
|
35
37
|
): UseProductAssociationsReturn {
|
|
36
38
|
if (!product.value)
|
|
37
39
|
throw new Error("[useProductAssociations]: Product is not provided.");
|
|
38
40
|
|
|
39
|
-
// @ts-ignore: temporary until fixed or removed
|
|
40
|
-
const association = options.associationContext;
|
|
41
|
-
|
|
42
41
|
const { apiClient } = useShopwareContext();
|
|
43
42
|
const isLoading = ref(false);
|
|
44
43
|
const associations = ref<Schemas["CrossSellingElementCollection"]>([]);
|
|
@@ -84,6 +83,11 @@ export function useProductAssociations(
|
|
|
84
83
|
const response = await apiClient.invoke(
|
|
85
84
|
"readProductCrossSellings post /product/{productId}/cross-selling",
|
|
86
85
|
{
|
|
86
|
+
...(options.includeSeoUrls && {
|
|
87
|
+
headers: {
|
|
88
|
+
"sw-include-seo-urls": true,
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
87
91
|
pathParams: { productId: product.value.id },
|
|
88
92
|
},
|
|
89
93
|
);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
+
|
|
3
4
|
import { useProduct, useProductConfigurator } from "#imports";
|
|
5
|
+
|
|
4
6
|
import { useSetup } from "../_test";
|
|
5
7
|
import mockedConfigurator from "../mocks/Configurator";
|
|
6
8
|
import mockedProduct from "../mocks/Product";
|
|
@@ -40,6 +42,28 @@ describe("useProductConfigurator", () => {
|
|
|
40
42
|
);
|
|
41
43
|
});
|
|
42
44
|
|
|
45
|
+
it("findVariantForSelectedOptions uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
46
|
+
vi.mocked(useProduct).mockReturnValue({
|
|
47
|
+
configurator: ref(mockedConfigurator),
|
|
48
|
+
product: ref(mockedProduct),
|
|
49
|
+
} as unknown as ReturnType<typeof useProduct>);
|
|
50
|
+
const { vm, injections } = useSetup(useProductConfigurator, {
|
|
51
|
+
shopware: { cacheableReads: true },
|
|
52
|
+
} as Parameters<typeof useSetup>[1]);
|
|
53
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
54
|
+
data: { elements: [mockedProduct] },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await vm.findVariantForSelectedOptions({ test: "test" });
|
|
58
|
+
|
|
59
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
60
|
+
"readProductGet get /product",
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
query: expect.objectContaining({ _criteria: expect.any(String) }),
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
43
67
|
it("findVariantForSelectedOptions - error", async () => {
|
|
44
68
|
console.error = vi.fn();
|
|
45
69
|
const { vm, injections } = useSetup(useProductConfigurator);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { getTranslatedProperty } from "@shopware/helpers";
|
|
2
3
|
import { computed, ref } from "vue";
|
|
3
4
|
import type { ComputedRef, Ref } from "vue";
|
|
5
|
+
|
|
4
6
|
import { useProduct, useShopwareContext } from "#imports";
|
|
5
7
|
import type { Schemas } from "#shopware";
|
|
6
8
|
|
|
@@ -40,7 +42,7 @@ export type UseProductConfiguratorReturn = {
|
|
|
40
42
|
* @category Product
|
|
41
43
|
*/
|
|
42
44
|
export function useProductConfigurator(): UseProductConfiguratorReturn {
|
|
43
|
-
const { apiClient } = useShopwareContext();
|
|
45
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
44
46
|
|
|
45
47
|
const { configurator, product } = useProduct();
|
|
46
48
|
|
|
@@ -91,19 +93,24 @@ export function useProductConfigurator(): UseProductConfiguratorReturn {
|
|
|
91
93
|
),
|
|
92
94
|
];
|
|
93
95
|
try {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
seo_url: ["seoPathInfo"],
|
|
101
|
-
},
|
|
102
|
-
associations: {
|
|
103
|
-
seoUrls: {},
|
|
104
|
-
},
|
|
96
|
+
const criteria = {
|
|
97
|
+
filter,
|
|
98
|
+
limit: 1,
|
|
99
|
+
includes: {
|
|
100
|
+
product: ["id", "translated", "productNumber", "seoUrls"],
|
|
101
|
+
seo_url: ["seoPathInfo"],
|
|
105
102
|
},
|
|
106
|
-
|
|
103
|
+
associations: {
|
|
104
|
+
seoUrls: {},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const response = cacheableReads
|
|
108
|
+
? await apiClient.invoke("readProductGet get /product", {
|
|
109
|
+
query: { _criteria: encodeForQuery(criteria) },
|
|
110
|
+
})
|
|
111
|
+
: await apiClient.invoke("readProduct post /product", {
|
|
112
|
+
body: criteria,
|
|
113
|
+
});
|
|
107
114
|
return response.data.elements?.[0]; // return first matching product
|
|
108
115
|
} catch (e) {
|
|
109
116
|
console.error("SwProductDetails:findVariantForSelectedOptions", e);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } 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 mockedProduct from "../mocks/Product";
|
|
6
8
|
import productTierPrices from "../mocks/ProductTierPrices";
|
|
@@ -2,6 +2,7 @@ import { getProductTierPrices } from "@shopware/helpers";
|
|
|
2
2
|
import type { TierPrice } from "@shopware/helpers";
|
|
3
3
|
import { computed } from "vue";
|
|
4
4
|
import type { ComputedRef, Ref } from "vue";
|
|
5
|
+
|
|
5
6
|
import type { Schemas } from "#shopware";
|
|
6
7
|
|
|
7
8
|
export type UseProductPriceReturn = {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
2
4
|
import { useSetup } from "../_test";
|
|
3
5
|
import { cmsAssociations } from "../cms/cmsAssociations";
|
|
4
6
|
import { useProductSearch } from "./useProductSearch";
|
|
@@ -25,7 +27,7 @@ describe("useProductSearch", () => {
|
|
|
25
27
|
withCmsAssociations: true,
|
|
26
28
|
});
|
|
27
29
|
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
28
|
-
expect.stringContaining("readProductDetail"),
|
|
30
|
+
expect.stringContaining("readProductDetail post"),
|
|
29
31
|
expect.objectContaining({
|
|
30
32
|
body: cmsAssociations,
|
|
31
33
|
pathParams: {
|
|
@@ -34,4 +36,25 @@ describe("useProductSearch", () => {
|
|
|
34
36
|
}),
|
|
35
37
|
);
|
|
36
38
|
});
|
|
39
|
+
|
|
40
|
+
it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
41
|
+
const { vm, injections } = useSetup(() => useProductSearch(), {
|
|
42
|
+
shopware: { cacheableReads: true },
|
|
43
|
+
});
|
|
44
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
45
|
+
await vm.search("test", {
|
|
46
|
+
withCmsAssociations: true,
|
|
47
|
+
});
|
|
48
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
49
|
+
expect.stringContaining("readProductDetailGet get"),
|
|
50
|
+
expect.objectContaining({
|
|
51
|
+
query: {
|
|
52
|
+
_criteria: encodeForQuery(cmsAssociations),
|
|
53
|
+
},
|
|
54
|
+
pathParams: {
|
|
55
|
+
productId: "test",
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
37
60
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { defu } from "defu";
|
|
3
|
+
|
|
2
4
|
import { useShopwareContext } from "#imports";
|
|
3
5
|
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
4
7
|
import { cmsAssociations } from "../cms/cmsAssociations";
|
|
5
8
|
|
|
6
9
|
type UseProductSearchReturnOptions = {
|
|
@@ -28,7 +31,7 @@ export type UseProductSearchReturn = {
|
|
|
28
31
|
* @category Navigation & Routing
|
|
29
32
|
*/
|
|
30
33
|
export function useProductSearch(): UseProductSearchReturn {
|
|
31
|
-
const { apiClient } = useShopwareContext();
|
|
34
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
32
35
|
|
|
33
36
|
const search = async (
|
|
34
37
|
productId: string,
|
|
@@ -39,16 +42,26 @@ export function useProductSearch(): UseProductSearchReturn {
|
|
|
39
42
|
options?.criteria,
|
|
40
43
|
{ associations: options?.associations ?? {} },
|
|
41
44
|
);
|
|
42
|
-
const result =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const result = cacheableReads
|
|
46
|
+
? await apiClient.invoke(
|
|
47
|
+
"readProductDetailGet get /product/{productId}",
|
|
48
|
+
{
|
|
49
|
+
headers: {
|
|
50
|
+
"sw-include-seo-urls": true,
|
|
51
|
+
},
|
|
52
|
+
pathParams: { productId },
|
|
53
|
+
query: {
|
|
54
|
+
_criteria: encodeForQuery(associations),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
: await apiClient.invoke("readProductDetail post /product/{productId}", {
|
|
59
|
+
headers: {
|
|
60
|
+
"sw-include-seo-urls": true,
|
|
61
|
+
},
|
|
62
|
+
pathParams: { productId },
|
|
63
|
+
body: associations,
|
|
64
|
+
});
|
|
52
65
|
return result.data;
|
|
53
66
|
};
|
|
54
67
|
|