@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -48,34 +48,34 @@
|
|
|
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
|
-
"@vueuse/core": "14.
|
|
55
|
-
"defu": "6.1.
|
|
55
|
+
"@vueuse/core": "14.3.0",
|
|
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
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"
|
|
66
|
-
"happy-dom": "20.8.9",
|
|
62
|
+
"@nuxt/kit": "4.4.8",
|
|
63
|
+
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
64
|
+
"@vitest/coverage-v8": "4.1.9",
|
|
65
|
+
"@vue/test-utils": "2.4.11",
|
|
66
|
+
"happy-dom": "20.10.6",
|
|
67
67
|
"typescript": "5.9.3",
|
|
68
|
-
"unbuild": "
|
|
69
|
-
"vitest": "4.
|
|
70
|
-
"vue": "3.5.
|
|
68
|
+
"unbuild": "3.6.1",
|
|
69
|
+
"vitest": "4.1.9",
|
|
70
|
+
"vue": "3.5.38",
|
|
71
71
|
"tsconfig": "0.0.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "unbuild && pnpm build:types",
|
|
75
75
|
"build:types": "tsgo",
|
|
76
76
|
"dev": "unbuild --stub",
|
|
77
|
-
"lint": "
|
|
78
|
-
"lint:fix": "
|
|
77
|
+
"lint": "oxlint . && oxfmt --check .",
|
|
78
|
+
"lint:fix": "oxlint --fix . && oxfmt --write . && pnpm run typecheck",
|
|
79
79
|
"typecheck": "tsgo --noEmit",
|
|
80
80
|
"test": "vitest run",
|
|
81
81
|
"coverage": "vitest run --coverage",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { inject } from "vue";
|
|
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 { useCmsElementConfig } from "../index";
|
|
6
8
|
import type { BoxLayout, CmsElementProductBox } from "../types";
|
|
7
9
|
|
|
@@ -14,6 +14,13 @@ export function createShopwareContext(
|
|
|
14
14
|
devStorefrontUrl?: string | null;
|
|
15
15
|
enableDevtools?: boolean;
|
|
16
16
|
browserLocale?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Opt in to reading data via cacheable GET Store API routes instead of
|
|
19
|
+
* POST. Surfaced on the Shopware context as `cacheableReads`.
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
cacheableReads?: boolean;
|
|
17
24
|
},
|
|
18
25
|
) {
|
|
19
26
|
const scope: EffectScope = effectScope(true);
|
|
@@ -36,6 +43,7 @@ export function createShopwareContext(
|
|
|
36
43
|
devStorefrontUrl: options.devStorefrontUrl,
|
|
37
44
|
state,
|
|
38
45
|
browserLocale: options.browserLocale || "en-US",
|
|
46
|
+
cacheableReads: options.cacheableReads ?? false,
|
|
39
47
|
});
|
|
40
48
|
|
|
41
49
|
if (options?.enableDevtools && typeof window !== "undefined") {
|
package/src/devtools/plugin.ts
CHANGED
|
@@ -10,13 +10,13 @@ export const shopwareSymbol = Symbol("shopware") as InjectionKey<string>;
|
|
|
10
10
|
/* istanbul ignore next */
|
|
11
11
|
export function registerShopwareDevtools(
|
|
12
12
|
app: App,
|
|
13
|
-
//
|
|
13
|
+
// TODO: Improve devtools typing.
|
|
14
14
|
shopwarePluginInstance: any,
|
|
15
15
|
) {
|
|
16
|
-
//
|
|
16
|
+
// TODO: Improve devtools typing.
|
|
17
17
|
let devtoolsApi: any;
|
|
18
18
|
let trackId = 0;
|
|
19
|
-
//
|
|
19
|
+
// TODO: Improve devtools typing.
|
|
20
20
|
let currentSharedState: any = null;
|
|
21
21
|
|
|
22
22
|
setupDevtoolsPlugin(
|
|
@@ -26,7 +26,7 @@ export function registerShopwareDevtools(
|
|
|
26
26
|
logo: "https://shopware.com/media/unknown/2d/80/8c/shopware_signet_blue.svg",
|
|
27
27
|
packageName: "shopware-frontends",
|
|
28
28
|
homepage: "shopware.com",
|
|
29
|
-
//
|
|
29
|
+
// TODO: Improve devtools typing.
|
|
30
30
|
app: app as any,
|
|
31
31
|
enableEarlyProxy: true,
|
|
32
32
|
},
|
|
@@ -68,12 +68,12 @@ export function registerShopwareDevtools(
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// TODO: Improve devtools typing.
|
|
72
72
|
function displayState(state: any) {
|
|
73
73
|
if (!state) return null;
|
|
74
|
-
//
|
|
74
|
+
// TODO: Improve devtools typing.
|
|
75
75
|
const res: any = {};
|
|
76
|
-
//
|
|
76
|
+
// TODO: Keep iteration behavior while devtools typing is improved.
|
|
77
77
|
Object.keys(state).forEach((refKey) => {
|
|
78
78
|
res[refKey] = unref(currentSharedState[refKey]);
|
|
79
79
|
});
|
|
@@ -116,12 +116,12 @@ export function registerShopwareDevtools(
|
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
const devtools = {
|
|
119
|
-
//
|
|
119
|
+
// TODO: Improve devtools typing.
|
|
120
120
|
trackEvent: (label: string, params: any) => {
|
|
121
121
|
const groupId = `track${trackId++}`;
|
|
122
122
|
|
|
123
123
|
// Start
|
|
124
|
-
//
|
|
124
|
+
// TODO: Improve devtools typing.
|
|
125
125
|
const log = (label: string, params: any) => {
|
|
126
126
|
devtoolsApi.addTimelineEvent({
|
|
127
127
|
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
@@ -143,7 +143,7 @@ export function registerShopwareDevtools(
|
|
|
143
143
|
log,
|
|
144
144
|
};
|
|
145
145
|
},
|
|
146
|
-
//
|
|
146
|
+
// TODO: Improve devtools typing.
|
|
147
147
|
log: (label: string, params: any) => {
|
|
148
148
|
devtoolsApi.addTimelineEvent({
|
|
149
149
|
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
@@ -157,7 +157,7 @@ export function registerShopwareDevtools(
|
|
|
157
157
|
},
|
|
158
158
|
});
|
|
159
159
|
},
|
|
160
|
-
//
|
|
160
|
+
// TODO: Improve devtools typing.
|
|
161
161
|
warning: (label: string, params: any) => {
|
|
162
162
|
devtoolsApi.addTimelineEvent({
|
|
163
163
|
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
@@ -172,7 +172,7 @@ export function registerShopwareDevtools(
|
|
|
172
172
|
},
|
|
173
173
|
});
|
|
174
174
|
},
|
|
175
|
-
//
|
|
175
|
+
// TODO: Improve devtools typing.
|
|
176
176
|
error: (label: string, params: any) => {
|
|
177
177
|
devtoolsApi.addTimelineEvent({
|
|
178
178
|
layerId: TIMELINE_EVENT_LAYER_ID,
|
|
@@ -188,7 +188,7 @@ export function registerShopwareDevtools(
|
|
|
188
188
|
});
|
|
189
189
|
},
|
|
190
190
|
_internal: {
|
|
191
|
-
//
|
|
191
|
+
// TODO: Improve devtools typing.
|
|
192
192
|
updateSharedState: (state: any) => {
|
|
193
193
|
currentSharedState = state;
|
|
194
194
|
devtoolsApi.sendInspectorState(INSPECTOR_ID);
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ApiClientError } from "@shopware/api-client";
|
|
2
2
|
import type { FetchResponse } from "ofetch";
|
|
3
3
|
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
4
5
|
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
5
7
|
import { useSetup } from "../_test";
|
|
6
8
|
import { useAddress } from "./useAddress";
|
|
7
9
|
|
|
@@ -2,6 +2,7 @@ import { ApiClientError } from "@shopware/api-client";
|
|
|
2
2
|
import type { ApiError } from "@shopware/api-client";
|
|
3
3
|
import { computed, inject, provide, ref } from "vue";
|
|
4
4
|
import type { ComputedRef, Ref } from "vue";
|
|
5
|
+
|
|
5
6
|
import { useShopwareContext } from "#imports";
|
|
6
7
|
import type { Schemas } from "#shopware";
|
|
7
8
|
|
package/src/useCart/useCart.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { ref } from "vue";
|
|
3
3
|
import type { Ref } from "vue";
|
|
4
|
+
|
|
4
5
|
import type { Schemas } from "#shopware";
|
|
6
|
+
|
|
5
7
|
import { useSetup } from "../_test";
|
|
6
8
|
import Cart from "../mocks/Cart";
|
|
7
9
|
import { useCartItem } from "./useCartItem";
|
|
@@ -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 { useCategorySearch } from "./useCategorySearch";
|
|
@@ -95,4 +97,31 @@ describe("useCategorySearch", () => {
|
|
|
95
97
|
}),
|
|
96
98
|
);
|
|
97
99
|
});
|
|
100
|
+
|
|
101
|
+
it("advancedSearch uses the cacheable GET variant when cacheableReads is enabled", () => {
|
|
102
|
+
const { vm, injections } = useSetup(useCategorySearch, {
|
|
103
|
+
shopware: { cacheableReads: true },
|
|
104
|
+
});
|
|
105
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
106
|
+
data: {},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
vm.advancedSearch({
|
|
110
|
+
query: {
|
|
111
|
+
limit: 10,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
116
|
+
expect.stringContaining("readCategoryListGet get"),
|
|
117
|
+
expect.objectContaining({
|
|
118
|
+
query: {
|
|
119
|
+
_criteria: encodeForQuery({
|
|
120
|
+
associations: {},
|
|
121
|
+
limit: 10,
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
});
|
|
98
127
|
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
2
|
+
|
|
1
3
|
import { useShopwareContext } from "#imports";
|
|
2
4
|
import type { Schemas } from "#shopware";
|
|
5
|
+
|
|
3
6
|
import { cmsAssociations } from "../cms/cmsAssociations";
|
|
4
7
|
|
|
5
8
|
export type UseCategorySearchReturn = {
|
|
@@ -30,7 +33,7 @@ export type UseCategorySearchReturn = {
|
|
|
30
33
|
* @category Navigation & Routing
|
|
31
34
|
*/
|
|
32
35
|
export function useCategorySearch(): UseCategorySearchReturn {
|
|
33
|
-
const { apiClient } = useShopwareContext();
|
|
36
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
34
37
|
|
|
35
38
|
async function search(
|
|
36
39
|
categoryId: string,
|
|
@@ -65,12 +68,17 @@ export function useCategorySearch(): UseCategorySearchReturn {
|
|
|
65
68
|
const associations = options?.withCmsAssociations
|
|
66
69
|
? cmsAssociations.associations
|
|
67
70
|
: {};
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const criteria = {
|
|
72
|
+
associations,
|
|
73
|
+
...options?.query,
|
|
74
|
+
};
|
|
75
|
+
const result = cacheableReads
|
|
76
|
+
? await apiClient.invoke("readCategoryListGet get /category", {
|
|
77
|
+
query: { _criteria: encodeForQuery(criteria) },
|
|
78
|
+
})
|
|
79
|
+
: await apiClient.invoke("readCategoryList post /category", {
|
|
80
|
+
body: criteria,
|
|
81
|
+
});
|
|
74
82
|
return result.data.elements ?? [];
|
|
75
83
|
}
|
|
76
84
|
|
|
@@ -1,5 +1,7 @@
|
|
|
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 { useSetup } from "../_test";
|
|
4
6
|
import CountryMock from "../mocks/Country";
|
|
5
7
|
import { useCountries } from "./useCountries";
|
|
@@ -104,6 +106,23 @@ describe("useCountries", () => {
|
|
|
104
106
|
expect(vm.getCountriesOptions).toStrictEqual([]);
|
|
105
107
|
});
|
|
106
108
|
|
|
109
|
+
it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
|
|
110
|
+
const { vm, injections } = await useSetup(useCountries, {
|
|
111
|
+
shopware: { cacheableReads: true },
|
|
112
|
+
apiClient: {
|
|
113
|
+
invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
|
|
114
|
+
},
|
|
115
|
+
} as Parameters<typeof useSetup>[1]);
|
|
116
|
+
await vm.fetchCountries();
|
|
117
|
+
|
|
118
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
119
|
+
expect.stringContaining("readCountryGet get"),
|
|
120
|
+
expect.objectContaining({
|
|
121
|
+
query: { _criteria: encodeForQuery({ associations: { states: {} } }) },
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
107
126
|
it("should not fetch when swCountries already populated", async () => {
|
|
108
127
|
const preloadedCountries = ref(CountryMock.elements);
|
|
109
128
|
const { vm, injections } = await useSetup(useCountries, {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
1
2
|
import { computed, inject, onMounted, provide, ref } from "vue";
|
|
2
3
|
import type { ComputedRef } from "vue";
|
|
4
|
+
|
|
3
5
|
import { useShopwareContext } from "#imports";
|
|
4
6
|
import type { Schemas, operations } from "#shopware";
|
|
5
7
|
|
|
@@ -24,19 +26,24 @@ export type UseCountriesReturn = {
|
|
|
24
26
|
* @category Context & Language
|
|
25
27
|
*/
|
|
26
28
|
export function useCountries(): UseCountriesReturn {
|
|
27
|
-
const { apiClient } = useShopwareContext();
|
|
29
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
28
30
|
|
|
29
31
|
const _sharedCountries = inject("swCountries", ref());
|
|
30
32
|
provide("swCountries", _sharedCountries);
|
|
31
33
|
|
|
32
34
|
async function fetchCountries() {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
states: {},
|
|
37
|
-
},
|
|
35
|
+
const criteria = {
|
|
36
|
+
associations: {
|
|
37
|
+
states: {},
|
|
38
38
|
},
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
|
+
const result = cacheableReads
|
|
41
|
+
? await apiClient.invoke("readCountryGet get /country", {
|
|
42
|
+
query: { _criteria: encodeForQuery(criteria) },
|
|
43
|
+
})
|
|
44
|
+
: await apiClient.invoke("readCountry post /country", {
|
|
45
|
+
body: criteria,
|
|
46
|
+
});
|
|
40
47
|
_sharedCountries.value = result.data.elements;
|
|
41
48
|
return result.data;
|
|
42
49
|
}
|