@shopware/composables 1.12.0 → 1.13.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.
@@ -7,7 +7,24 @@ import type { Schemas } from "#shopware";
7
7
  type UseB2bQuoteManagement = {
8
8
  getQuoteList: () => Promise<Schemas["Quote"][]>;
9
9
  getQuote: (quoteId: string) => Promise<Schemas["Quote"]>;
10
+ /**
11
+ * @deprecated use `declineQuoteWithComment` instead — it sends the
12
+ * `lineItemId` and `versionId` that `POST /quote/{id}/decline` expects.
13
+ * A `comment`-only body is still accepted at runtime on 6.7.12+: the API
14
+ * schema marks `lineItemId` and `versionId` as required, but the endpoint
15
+ * does not validate the request body, so existing callers keep working.
16
+ * Removed in v2.
17
+ */
10
18
  declineQuote: (quoteId: string, comment: string) => Promise<void>;
19
+ declineQuoteWithComment: (
20
+ quoteId: string,
21
+ params: DeclineQuoteParams,
22
+ ) => Promise<void>;
23
+ createDraftQuoteVersion: (quoteId: string) => Promise<string>;
24
+ deleteDraftQuoteVersion: (
25
+ quoteId: string,
26
+ versionId: string,
27
+ ) => Promise<void>;
11
28
  requestChangeQuote: (quoteId: string, comment: string) => Promise<void>;
12
29
  requestQuote: (comment: string) => Promise<Schemas["Quote"]>;
13
30
  createOrderFromQuote: (
@@ -24,6 +41,19 @@ type UseB2bQuoteManagement = {
24
41
  ) => Promise<void>;
25
42
  };
26
43
 
44
+ export type DeclineQuoteParams = {
45
+ /** Message content */
46
+ comment: string;
47
+ /** Identifier of the quote line item that owns the new comment */
48
+ lineItemId: string;
49
+ /**
50
+ * Draft version identifier of the quote currently shown in storefront,
51
+ * as returned by `createDraftQuoteVersion`. This is not the `versionId`
52
+ * property of the quote entity.
53
+ */
54
+ versionId: string;
55
+ };
56
+
27
57
  export type ChangePaymentShippingMethodParams = {
28
58
  quoteId: string;
29
59
  paymentMethodId?: string;
@@ -36,7 +66,8 @@ export type ChangePaymentShippingMethodParams = {
36
66
  * With this composable you can:
37
67
  * - Get list of quotes
38
68
  * - Get quote details
39
- * - Decline quote
69
+ * - Create and delete a storefront draft version of the quote
70
+ * - Decline quote, with or without a line item comment
40
71
  * - Request change of the quote
41
72
  * - Change shipping method
42
73
  * - Change payment method
@@ -66,26 +97,78 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
66
97
  * @returns {Promise<Schemas["Quote"]>}
67
98
  */
68
99
  const getQuote = async (quoteId: string) => {
100
+ const response = await apiClient.invoke("readQuote post /quote/{id}", {
101
+ pathParams: {
102
+ id: quoteId,
103
+ },
104
+ body: {
105
+ associations: {
106
+ lineItems: {},
107
+ comments: {},
108
+ stateMachineState: {},
109
+ },
110
+ },
111
+ });
112
+ return response.data;
113
+ };
114
+
115
+ /**
116
+ * Create a temporary draft version of the quote for storefront editing.
117
+ *
118
+ * The returned identifier is the `versionId` that quote write operations
119
+ * expect, for example {@link declineQuoteWithComment}. It is not the
120
+ * `versionId` property of the quote entity.
121
+ *
122
+ * @param {string} quoteId
123
+ * @returns {Promise<string>} draft version identifier
124
+ */
125
+ async function createDraftQuoteVersion(quoteId: string) {
69
126
  const response = await apiClient.invoke(
70
- "readQuote post /quote/detail/{id}",
127
+ "createDraftQuoteVersion post /quote/{id}/draft-version",
71
128
  {
72
129
  pathParams: {
73
130
  id: quoteId,
74
131
  },
75
- body: {
76
- associations: {
77
- lineItems: {},
78
- comments: {},
79
- stateMachineState: {},
80
- },
132
+ },
133
+ );
134
+
135
+ if (!response.data.versionId) {
136
+ throw new Error(
137
+ `Could not create a draft version for quote "${quoteId}": the API returned no versionId.`,
138
+ );
139
+ }
140
+
141
+ return response.data.versionId;
142
+ }
143
+
144
+ /**
145
+ * Delete the temporary draft version of the quote.
146
+ *
147
+ * @param {string} quoteId
148
+ * @param {string} versionId draft version identifier returned by {@link createDraftQuoteVersion}
149
+ * @returns {Promise<void>}
150
+ */
151
+ async function deleteDraftQuoteVersion(quoteId: string, versionId: string) {
152
+ await apiClient.invoke(
153
+ "deleteDraftQuoteVersion delete /quote/{id}/draft-version",
154
+ {
155
+ pathParams: {
156
+ id: quoteId,
81
157
  },
158
+ body: { versionId },
82
159
  },
83
160
  );
84
- return response.data;
85
- };
161
+ }
86
162
 
87
163
  /**
88
- * Decline quote
164
+ * Decline quote with a comment only.
165
+ *
166
+ * @deprecated use {@link declineQuoteWithComment} instead — it sends the
167
+ * `lineItemId` and `versionId` that `POST /quote/{id}/decline` expects.
168
+ * A `comment`-only body is still accepted at runtime on 6.7.12+: the API
169
+ * schema marks `lineItemId` and `versionId` as required, but the endpoint
170
+ * does not validate the request body, so existing callers keep working.
171
+ * Removed in v2.
89
172
  *
90
173
  * @param {string} quoteId
91
174
  * @param {string} comment
@@ -96,9 +179,30 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
96
179
  pathParams: {
97
180
  id: quoteId,
98
181
  },
99
- body: {
100
- comment,
182
+ // The 6.7.12 schema marks `lineItemId` and `versionId` as required, so a
183
+ // comment-only body no longer matches the generated type. Sent as-is to
184
+ // keep the pre-6.7.12 behaviour of this deprecated method unchanged.
185
+ body: { comment } as DeclineQuoteParams,
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Decline quote, attaching the comment to a quote line item in the current
191
+ * draft version.
192
+ *
193
+ * @param {string} quoteId
194
+ * @param {DeclineQuoteParams} params
195
+ * @returns {Promise<void>}
196
+ */
197
+ async function declineQuoteWithComment(
198
+ quoteId: string,
199
+ params: DeclineQuoteParams,
200
+ ) {
201
+ await apiClient.invoke("declineQuote post /quote/{id}/decline", {
202
+ pathParams: {
203
+ id: quoteId,
101
204
  },
205
+ body: params,
102
206
  });
103
207
  }
104
208
 
@@ -202,7 +306,7 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
202
306
  */
203
307
  const createOrderFromQuote = async (quoteId: string, comment: string) => {
204
308
  const response = await apiClient.invoke(
205
- "createOrderFromQuote post /quote/order/{id}",
309
+ "createOrderFromQuote post /quote/{id}/order",
206
310
  {
207
311
  pathParams: { id: quoteId },
208
312
  body: { customerComment: comment },
@@ -216,6 +320,9 @@ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
216
320
  getQuoteList,
217
321
  getQuote,
218
322
  declineQuote,
323
+ declineQuoteWithComment,
324
+ createDraftQuoteVersion,
325
+ deleteDraftQuoteVersion,
219
326
  requestChangeQuote,
220
327
  changeShippingMethod,
221
328
  changePaymentMethod,
@@ -44,7 +44,7 @@ export type UseBreadcrumbsReturn = {
44
44
 
45
45
  /**
46
46
  * Composable for breadcrumbs management.
47
- * Read the [guide](https://frontends.shopware.com/getting-started/page-elements/breadcrumbs.html#building-breadcrumbs-for-cms-pages).
47
+ * Read the [guide](https://developer.shopware.com/frontends/guides/page-elements/breadcrumbs.html#building-breadcrumbs-for-cms-pages).
48
48
  *
49
49
  * @public
50
50
  * @category CMS (Shopping Experiences)
@@ -280,6 +280,23 @@ describe("useCart", () => {
280
280
  expect(vm.isVirtualCart).toBe(true);
281
281
  });
282
282
 
283
+ it("handles cart items with optional quantity and states", async () => {
284
+ injections.apiClient.invoke.mockResolvedValue({
285
+ data: {
286
+ lineItems: [
287
+ {
288
+ type: "product",
289
+ good: true,
290
+ },
291
+ ],
292
+ },
293
+ });
294
+ await vm.refreshCart();
295
+
296
+ expect(vm.count).toBe(0);
297
+ expect(vm.isVirtualCart).toBe(false);
298
+ });
299
+
283
300
  it("consumeCartErrors returns null when no errors", async () => {
284
301
  await vm.refreshCart();
285
302
  expect(vm.consumeCartErrors()).toEqual(null);
@@ -100,7 +100,7 @@ export type UseCartReturn = {
100
100
  /**
101
101
  * Cart management logic.
102
102
  *
103
- * Used as [Shared](https://frontends.shopware.com/framework/composables/shared-composables.html) Composable `useCart`
103
+ * Used as [Shared](https://developer.shopware.com/frontends/concepts/composables/shared-composables.html) Composable `useCart`
104
104
  *
105
105
  * @category Cart & Checkout
106
106
  */
@@ -244,7 +244,9 @@ export function useCartFunction(): UseCartReturn {
244
244
  const count = computed(() => {
245
245
  return cartItems.value.reduce(
246
246
  (accumulator: number, lineItem: Schemas["LineItem"]) =>
247
- lineItem.good === true ? lineItem.quantity + accumulator : accumulator,
247
+ lineItem.good === true
248
+ ? (lineItem.quantity ?? 0) + accumulator
249
+ : accumulator,
248
250
  0,
249
251
  );
250
252
  });
@@ -276,7 +278,7 @@ export function useCartFunction(): UseCartReturn {
276
278
  cartItems.value.length > 0 &&
277
279
  cartItems.value
278
280
  .filter((element) => element.type !== "promotion")
279
- .every((item) => item.states.includes("is-download"))
281
+ .every((item) => item.states?.includes("is-download") ?? false)
280
282
  );
281
283
  });
282
284
 
@@ -88,6 +88,19 @@ describe("useCartItem", () => {
88
88
  expect(vm.itemOptions).toStrictEqual([]);
89
89
  });
90
90
 
91
+ it("should show default empty options and stock for non-product items", async () => {
92
+ const { vm } = useSetup(() =>
93
+ useCartItem(
94
+ ref({
95
+ type: "promotion",
96
+ } as Schemas["LineItem"]),
97
+ ),
98
+ );
99
+
100
+ expect(vm.itemOptions).toStrictEqual([]);
101
+ expect(vm.itemStock).toBeUndefined();
102
+ });
103
+
91
104
  it("should remove item from the cart", async () => {
92
105
  const { vm } = useSetup(() =>
93
106
  useCartItem(ref(lineItem) as unknown as Ref<Schemas["LineItem"]>),
@@ -5,6 +5,11 @@ import type { ComputedRef, Ref } from "vue";
5
5
  import { useCart } from "#imports";
6
6
  import type { Schemas } from "#shopware";
7
7
 
8
+ type LineItemOptions = Schemas["PropertyGroupOption"][];
9
+ type LineItemPayloadWithOptions = {
10
+ options?: LineItemOptions;
11
+ };
12
+
8
13
  export type UseCartItemReturn = {
9
14
  /**
10
15
  * Calculated price {number} for the current item
@@ -25,7 +30,7 @@ export type UseCartItemReturn = {
25
30
  /**
26
31
  * Options (of variation) for the current item
27
32
  */
28
- itemOptions: ComputedRef<Schemas["LineItem"]["payload"]["options"]>;
33
+ itemOptions: ComputedRef<LineItemOptions>;
29
34
  /**
30
35
  * Type of the current item: "product" or "promotion"
31
36
  */
@@ -99,14 +104,16 @@ export function useCartItem(
99
104
 
100
105
  const itemTotalPrice = computed(() => cartItem.value.price?.totalPrice);
101
106
 
102
- const itemOptions = computed(
103
- () =>
104
- (cartItem.value.type === "product" && cartItem.value.payload?.options) ||
105
- [],
106
- );
107
+ const itemOptions = computed(() => {
108
+ const payload = cartItem.value.payload as
109
+ | LineItemPayloadWithOptions
110
+ | undefined;
111
+
112
+ return cartItem.value.type === "product" ? (payload?.options ?? []) : [];
113
+ });
107
114
 
108
115
  const itemStock = computed<number | undefined>(
109
- () => cartItem.value.deliveryInformation.stock,
116
+ () => cartItem.value.deliveryInformation?.stock,
110
117
  );
111
118
 
112
119
  const isDigital = computed(
@@ -14,7 +14,7 @@ describe("useCategorySearch", () => {
14
14
  vm.search("categoryId");
15
15
 
16
16
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
17
- expect.stringContaining("readCategory"),
17
+ expect.stringContaining("readCategory post"),
18
18
  expect.objectContaining({
19
19
  pathParams: {
20
20
  navigationId: "categoryId",
@@ -36,7 +36,7 @@ describe("useCategorySearch", () => {
36
36
  });
37
37
 
38
38
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
39
- expect.stringContaining("readCategory"),
39
+ expect.stringContaining("readCategory post"),
40
40
  expect.objectContaining({
41
41
  pathParams: {
42
42
  navigationId: "categoryId",
@@ -51,6 +51,79 @@ describe("useCategorySearch", () => {
51
51
  );
52
52
  });
53
53
 
54
+ it("search uses the cacheable GET variant when cacheableReads is enabled", () => {
55
+ const { vm, injections } = useSetup(useCategorySearch, {
56
+ shopware: { cacheableReads: true },
57
+ });
58
+ injections.apiClient.invoke.mockResolvedValue({
59
+ data: {},
60
+ });
61
+
62
+ vm.search("categoryId", {
63
+ query: {
64
+ filter: [{ type: "equals", field: "active", value: true }],
65
+ limit: 1,
66
+ sort: [{ field: "name", order: "ASC" }],
67
+ },
68
+ withCmsAssociations: true,
69
+ });
70
+
71
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
72
+ expect.stringContaining("readCategoryGet get"),
73
+ expect.objectContaining({
74
+ pathParams: {
75
+ navigationId: "categoryId",
76
+ },
77
+ headers: {
78
+ "sw-include-seo-urls": true,
79
+ },
80
+ query: {
81
+ _criteria: encodeForQuery({
82
+ associations: cmsAssociations,
83
+ filter: [{ type: "equals", field: "active", value: true }],
84
+ limit: 1,
85
+ sort: [{ field: "name", order: "ASC" }],
86
+ }),
87
+ },
88
+ }),
89
+ );
90
+ });
91
+
92
+ it("search encodes Criteria body keys into cacheable GET _criteria", () => {
93
+ const { vm, injections } = useSetup(useCategorySearch, {
94
+ shopware: { cacheableReads: true },
95
+ });
96
+ injections.apiClient.invoke.mockResolvedValue({
97
+ data: {},
98
+ });
99
+
100
+ vm.search("categoryId", {
101
+ query: {
102
+ aggregations: [{ type: "count", field: "id", name: "count-id" }],
103
+ fields: ["name"],
104
+ grouping: ["translated.name"],
105
+ ids: ["categoryId"],
106
+ "post-filter": [{ type: "equals", field: "active", value: true }],
107
+ },
108
+ });
109
+
110
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
111
+ expect.stringContaining("readCategoryGet get"),
112
+ expect.objectContaining({
113
+ query: {
114
+ _criteria: encodeForQuery({
115
+ associations: {},
116
+ aggregations: [{ type: "count", field: "id", name: "count-id" }],
117
+ fields: ["name"],
118
+ grouping: ["translated.name"],
119
+ ids: ["categoryId"],
120
+ "post-filter": [{ type: "equals", field: "active", value: true }],
121
+ }),
122
+ },
123
+ }),
124
+ );
125
+ });
126
+
54
127
  it("advanced search method", () => {
55
128
  const { vm, injections } = useSetup(useCategorySearch);
56
129
  injections.apiClient.invoke.mockResolvedValue({
@@ -1,10 +1,14 @@
1
1
  import { encodeForQuery } from "@shopware/api-client/helpers";
2
2
 
3
3
  import { useShopwareContext } from "#imports";
4
- import type { Schemas } from "#shopware";
4
+ import type { Schemas, operations } from "#shopware";
5
5
 
6
6
  import { cmsAssociations } from "../cms/cmsAssociations";
7
7
 
8
+ type ReadCategoryGetQuery = NonNullable<
9
+ operations["readCategoryGet get /category/{navigationId}"]["query"]
10
+ > & { _criteria?: string };
11
+
8
12
  export type UseCategorySearchReturn = {
9
13
  /**
10
14
  * Search for category by ID
@@ -43,21 +47,31 @@ export function useCategorySearch(): UseCategorySearchReturn {
43
47
  },
44
48
  ) {
45
49
  const associations = options?.withCmsAssociations ? cmsAssociations : {};
46
- const result = await apiClient.invoke(
47
- "readCategory post /category/{navigationId}",
48
- {
49
- pathParams: {
50
- navigationId: categoryId,
51
- },
52
- headers: {
53
- "sw-include-seo-urls": true,
54
- },
55
- body: {
56
- associations,
57
- ...options?.query,
58
- },
59
- },
60
- );
50
+ const criteria = {
51
+ associations,
52
+ ...options?.query,
53
+ };
54
+ const result = cacheableReads
55
+ ? await apiClient.invoke("readCategoryGet get /category/{navigationId}", {
56
+ pathParams: {
57
+ navigationId: categoryId,
58
+ },
59
+ headers: {
60
+ "sw-include-seo-urls": true,
61
+ },
62
+ query: {
63
+ _criteria: encodeForQuery(criteria),
64
+ } as ReadCategoryGetQuery,
65
+ })
66
+ : await apiClient.invoke("readCategory post /category/{navigationId}", {
67
+ pathParams: {
68
+ navigationId: categoryId,
69
+ },
70
+ headers: {
71
+ "sw-include-seo-urls": true,
72
+ },
73
+ body: criteria,
74
+ });
61
75
  return result.data;
62
76
  }
63
77
 
@@ -2,13 +2,15 @@ import { encodeForQuery } from "@shopware/api-client/helpers";
2
2
  import { describe, expect, it, vi } from "vitest";
3
3
  import { ref } from "vue";
4
4
 
5
+ import type { Schemas } from "#shopware";
6
+
5
7
  import { useSetup } from "../_test";
6
8
  import CountryMock from "../mocks/Country";
7
9
  import { useCountries } from "./useCountries";
8
10
 
9
11
  describe("useCountries", () => {
10
12
  it("useCountries flow", async () => {
11
- const { vm, injections } = await useSetup(useCountries, {
13
+ const { vm, injections } = await useSetup(() => useCountries(), {
12
14
  apiClient: {
13
15
  invoke: vi.fn().mockResolvedValue({
14
16
  data: CountryMock,
@@ -30,7 +32,7 @@ describe("useCountries", () => {
30
32
  });
31
33
 
32
34
  it("useCountries flow - no states", async () => {
33
- const { vm } = await useSetup(useCountries, {
35
+ const { vm } = await useSetup(() => useCountries(), {
34
36
  apiClient: {
35
37
  invoke: vi.fn().mockResolvedValue({
36
38
  data: {
@@ -51,7 +53,7 @@ describe("useCountries", () => {
51
53
  });
52
54
 
53
55
  it("useCountries flow - empty", async () => {
54
- const { vm } = await useSetup(useCountries, {
56
+ const { vm } = await useSetup(() => useCountries(), {
55
57
  apiClient: {
56
58
  invoke: vi.fn().mockResolvedValue({
57
59
  data: {
@@ -66,7 +68,7 @@ describe("useCountries", () => {
66
68
  });
67
69
 
68
70
  it("useCountries flow - getCountriesOptions", async () => {
69
- const { vm } = await useSetup(useCountries, {
71
+ const { vm } = await useSetup(() => useCountries(), {
70
72
  apiClient: {
71
73
  invoke: vi.fn().mockResolvedValue({
72
74
  data: CountryMock,
@@ -93,7 +95,7 @@ describe("useCountries", () => {
93
95
  });
94
96
 
95
97
  it("useCountries flow - getCountriesOptions - empty array", async () => {
96
- const { vm } = await useSetup(useCountries, {
98
+ const { vm } = await useSetup(() => useCountries(), {
97
99
  apiClient: {
98
100
  invoke: vi.fn().mockResolvedValue({
99
101
  data: {
@@ -107,7 +109,7 @@ describe("useCountries", () => {
107
109
  });
108
110
 
109
111
  it("uses the cacheable GET variant when cacheableReads is enabled", async () => {
110
- const { vm, injections } = await useSetup(useCountries, {
112
+ const { vm, injections } = await useSetup(() => useCountries(), {
111
113
  shopware: { cacheableReads: true },
112
114
  apiClient: {
113
115
  invoke: vi.fn().mockResolvedValue({ data: CountryMock }),
@@ -123,9 +125,78 @@ describe("useCountries", () => {
123
125
  );
124
126
  });
125
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
+
126
197
  it("should not fetch when swCountries already populated", async () => {
127
198
  const preloadedCountries = ref(CountryMock.elements);
128
- const { vm, injections } = await useSetup(useCountries, {
199
+ const { vm, injections } = await useSetup(() => useCountries(), {
129
200
  apiClient: { invoke: vi.fn() },
130
201
  swCountries: preloadedCountries,
131
202
  } as Parameters<typeof useSetup>[1]);
@@ -1,4 +1,5 @@
1
1
  import { encodeForQuery } from "@shopware/api-client/helpers";
2
+ import { defu } from "defu";
2
3
  import { computed, inject, onMounted, provide, ref } from "vue";
3
4
  import type { ComputedRef } from "vue";
4
5
 
@@ -25,24 +26,27 @@ export type UseCountriesReturn = {
25
26
  * @public
26
27
  * @category Context & Language
27
28
  */
28
- export function useCountries(): UseCountriesReturn {
29
+ export function useCountries(
30
+ criteria?: Schemas["Criteria"],
31
+ ): UseCountriesReturn {
29
32
  const { apiClient, cacheableReads } = useShopwareContext();
30
33
 
31
34
  const _sharedCountries = inject("swCountries", ref());
32
35
  provide("swCountries", _sharedCountries);
36
+ const searchCriteria = ref(criteria ?? {});
33
37
 
34
38
  async function fetchCountries() {
35
- const criteria = {
39
+ const queryCriteria = defu(searchCriteria.value, {
36
40
  associations: {
37
41
  states: {},
38
42
  },
39
- };
43
+ } as Schemas["Criteria"]);
40
44
  const result = cacheableReads
41
45
  ? await apiClient.invoke("readCountryGet get /country", {
42
- query: { _criteria: encodeForQuery(criteria) },
46
+ query: { _criteria: encodeForQuery(queryCriteria) },
43
47
  })
44
48
  : await apiClient.invoke("readCountry post /country", {
45
- body: criteria,
49
+ body: queryCriteria,
46
50
  });
47
51
  _sharedCountries.value = result.data.elements;
48
52
  return result.data;
@@ -96,7 +96,9 @@ export type UseListingReturn = {
96
96
  * Available sorting orders
97
97
  */
98
98
  getSortingOrders: ComputedRef<
99
- Schemas["ProductSorting"][] | { key: string; label: string }[] | undefined
99
+ | Schemas["ProductListingResult"]["availableSortings"]
100
+ | { key: string; label: string }[]
101
+ | undefined
100
102
  >;
101
103
  /**
102
104
  * Current sorting order