@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.
Files changed (100) hide show
  1. package/README.md +18 -13
  2. package/dist/index.d.mts +35 -5
  3. package/dist/index.d.ts +35 -5
  4. package/dist/index.mjs +167 -100
  5. package/nuxt.config.ts +10 -0
  6. package/package.json +14 -15
  7. package/src/cms/useCmsElementConfig.test.ts +1 -0
  8. package/src/cms/useCmsElementConfig.ts +1 -0
  9. package/src/cms/useCmsElementImage.test.ts +1 -0
  10. package/src/cms/useCmsElementImage.ts +2 -0
  11. package/src/cms/useCmsElementProductBox.test.ts +1 -0
  12. package/src/cms/useCmsElementProductBox.ts +2 -0
  13. package/src/createShopwareContext.test.ts +1 -0
  14. package/src/createShopwareContext.ts +8 -0
  15. package/src/devtools/plugin.ts +13 -13
  16. package/src/helpers/ContextError.spec.ts +1 -0
  17. package/src/index.test.ts +2 -0
  18. package/src/index.ts +1 -0
  19. package/src/types/cmsElementTypes.ts +1 -0
  20. package/src/useAddToCart/useAddToCart.test.ts +1 -0
  21. package/src/useAddToCart/useAddToCart.ts +1 -0
  22. package/src/useAddress/useAddress.test.ts +2 -0
  23. package/src/useAddress/useAddress.ts +1 -0
  24. package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +1 -0
  25. package/src/useBreadcrumbs/useBreadcrumbs.test.ts +2 -0
  26. package/src/useBreadcrumbs/useBreadcrumbs.ts +2 -1
  27. package/src/useCart/useCart.test.ts +19 -0
  28. package/src/useCart/useCart.ts +6 -3
  29. package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +1 -0
  30. package/src/useCartItem/useCartItem.test.ts +15 -0
  31. package/src/useCartItem/useCartItem.ts +15 -7
  32. package/src/useCartNotification/useCartNotification.test.ts +2 -0
  33. package/src/useCategory/useCategory.test.ts +2 -0
  34. package/src/useCategory/useCategory.ts +2 -0
  35. package/src/useCategorySearch/useCategorySearch.test.ts +104 -2
  36. package/src/useCategorySearch/useCategorySearch.ts +45 -23
  37. package/src/useCheckout/useCheckout.test.ts +1 -0
  38. package/src/useCheckout/useCheckout.ts +1 -0
  39. package/src/useCmsBlock/useCmsBlock.test.ts +2 -0
  40. package/src/useCmsMeta/useCmsMeta.test.ts +2 -0
  41. package/src/useCmsMeta/useCmsMeta.ts +1 -0
  42. package/src/useCmsSection/useCmsSection.test.ts +2 -0
  43. package/src/useCmsTranslations/useCmsTranslations.test.ts +2 -0
  44. package/src/useCountries/useCountries.test.ts +96 -6
  45. package/src/useCountries/useCountries.ts +19 -8
  46. package/src/useCustomerOrders/useCustomerOrders.test.ts +1 -0
  47. package/src/useCustomerOrders/useCustomerOrders.ts +1 -0
  48. package/src/useCustomerPassword/useCustomerPassword.test.ts +1 -0
  49. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +1 -0
  50. package/src/useInternationalization/useInternationalization.test.ts +14 -1
  51. package/src/useInternationalization/useInternationalization.ts +5 -3
  52. package/src/useLandingSearch/useLandingSearch.test.ts +1 -0
  53. package/src/useLandingSearch/useLandingSearch.ts +1 -0
  54. package/src/useListing/useListing.test.ts +2 -0
  55. package/src/useListing/useListing.ts +3 -2
  56. package/src/useLocalWishlist/useLocalWishlist.test.ts +1 -0
  57. package/src/useNavigation/useNavigation.test.ts +24 -1
  58. package/src/useNavigation/useNavigation.ts +36 -14
  59. package/src/useNavigationContext/useNavigationContext.test.ts +1 -0
  60. package/src/useNavigationContext/useNavigationContext.ts +1 -0
  61. package/src/useNavigationSearch/useNavigationSearch.test.ts +30 -0
  62. package/src/useNavigationSearch/useNavigationSearch.ts +19 -12
  63. package/src/useNewsletter/useNewsletter.test.ts +1 -0
  64. package/src/useNewsletter/useNewsletter.ts +1 -0
  65. package/src/useNotifications/useNotifications.test.ts +1 -0
  66. package/src/useOrderDetails/useOrderDetails.test.ts +1 -0
  67. package/src/useOrderDetails/useOrderDetails.ts +1 -0
  68. package/src/useOrderPayment/useOrderPayment.test.ts +2 -0
  69. package/src/useOrderPayment/useOrderPayment.ts +1 -0
  70. package/src/usePrice/usePrice.test.ts +2 -0
  71. package/src/usePrice/usePrice.ts +1 -0
  72. package/src/useProduct/useProduct.test.ts +2 -0
  73. package/src/useProduct/useProduct.ts +2 -0
  74. package/src/useProductAssociations/useProductAssociations.spec.ts +48 -0
  75. package/src/useProductAssociations/useProductAssociations.ts +7 -3
  76. package/src/useProductConfigurator/useProductConfigurator.spec.ts +24 -0
  77. package/src/useProductConfigurator/useProductConfigurator.ts +20 -13
  78. package/src/useProductPrice/useProductPrice.test.ts +2 -0
  79. package/src/useProductPrice/useProductPrice.ts +1 -0
  80. package/src/useProductReviews/useProductReviews.test.ts +42 -2
  81. package/src/useProductReviews/useProductReviews.ts +18 -8
  82. package/src/useProductSearch/useProductSearch.test.ts +24 -1
  83. package/src/useProductSearch/useProductSearch.ts +24 -11
  84. package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +1 -0
  85. package/src/useProductSearchSuggest/useProductSearchSuggest.ts +1 -0
  86. package/src/useProductWishlist/useProductWishlist.test.ts +2 -0
  87. package/src/useProductWishlist/useProductWishlist.ts +1 -0
  88. package/src/useSalutations/useSalutations.spec.ts +15 -0
  89. package/src/useSalutations/useSalutations.ts +5 -2
  90. package/src/useSessionContext/useSessionContext.test.ts +84 -6
  91. package/src/useSessionContext/useSessionContext.ts +17 -2
  92. package/src/useShopwareContext/useShopwareContext.test.ts +1 -0
  93. package/src/useShopwareContext/useShopwareContext.ts +13 -0
  94. package/src/useSyncWishlist/useSyncWishlist.test.ts +1 -0
  95. package/src/useSyncWishlist/useSyncWishlist.ts +1 -0
  96. package/src/useUrlResolver/useUrlResolver.test.ts +1 -0
  97. package/src/useUser/useUser.test.ts +55 -2
  98. package/src/useUser/useUser.ts +34 -25
  99. package/src/useWishlist/useWishlist.test.ts +2 -0
  100. package/src/useWishlist/useWishlist.ts +1 -0
@@ -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
- // biome-ignore lint: not used plugin for now, ignoring type errors
13
+ // TODO: Improve devtools typing.
14
14
  shopwarePluginInstance: any,
15
15
  ) {
16
- // biome-ignore lint: not used plugin for now, ignoring type errors
16
+ // TODO: Improve devtools typing.
17
17
  let devtoolsApi: any;
18
18
  let trackId = 0;
19
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
71
+ // TODO: Improve devtools typing.
72
72
  function displayState(state: any) {
73
73
  if (!state) return null;
74
- // biome-ignore lint: not used plugin for now, ignoring type errors
74
+ // TODO: Improve devtools typing.
75
75
  const res: any = {};
76
- // biome-ignore lint/complexity/noForEach: ignore for now
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
119
+ // TODO: Improve devtools typing.
120
120
  trackEvent: (label: string, params: any) => {
121
121
  const groupId = `track${trackId++}`;
122
122
 
123
123
  // Start
124
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
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
- // biome-ignore lint: not used plugin for now, ignoring type errors
191
+ // TODO: Improve devtools typing.
192
192
  updateSharedState: (state: any) => {
193
193
  currentSharedState = state;
194
194
  devtoolsApi.sendInspectorState(INSPECTOR_ID);
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import ContextError from "./ContextError";
3
4
 
4
5
  describe("contextError", () => {
package/src/index.test.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import * as vue from "vue";
3
+
3
4
  import type { Schemas } from "#shopware";
5
+
4
6
  import { getDefaultApiParams, resolveCmsComponent } from "./index";
5
7
  import CmsPage from "./mocks/CmsPage";
6
8
 
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { pascalCase } from "scule";
2
2
  import { resolveComponent } from "vue";
3
+
3
4
  import type { Schemas } from "#shopware";
4
5
 
5
6
  /**
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties } from "vue";
2
+
2
3
  import type { Schemas } from "#shopware";
3
4
 
4
5
  export type SourceType = "static" | "mapped";
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useSetup } from "../_test";
4
5
  import ProductMocked from "../mocks/Product";
5
6
  import { useAddToCart } from "./useAddToCart";
@@ -1,5 +1,6 @@
1
1
  import { computed, ref, unref } from "vue";
2
2
  import type { ComputedRef, Ref } from "vue";
3
+
3
4
  import { useCart } from "#imports";
4
5
  import type { Schemas } from "#shopware";
5
6
  export type UseAddToCartReturn = {
@@ -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
 
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import { useSetup } from "../_test";
3
4
  import { useB2bQuoteManagement } from "./useB2bQuoteManagement";
4
5
  /**
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import { useBreadcrumbs } from "./useBreadcrumbs";
5
7
 
@@ -1,5 +1,6 @@
1
1
  import { computed } from "vue";
2
2
  import type { ComputedRef } from "vue";
3
+
3
4
  import { useContext } from "#imports";
4
5
  import type { Schemas, operations } from "#shopware";
5
6
 
@@ -43,7 +44,7 @@ export type UseBreadcrumbsReturn = {
43
44
 
44
45
  /**
45
46
  * Composable for breadcrumbs management.
46
- * 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).
47
48
  *
48
49
  * @public
49
50
  * @category CMS (Shopping Experiences)
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import type { Schemas, operations } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import Cart from "../mocks/Cart";
5
7
  import { useCart } from "./useCart";
@@ -278,6 +280,23 @@ describe("useCart", () => {
278
280
  expect(vm.isVirtualCart).toBe(true);
279
281
  });
280
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
+
281
300
  it("consumeCartErrors returns null when no errors", async () => {
282
301
  await vm.refreshCart();
283
302
  expect(vm.consumeCartErrors()).toEqual(null);
@@ -1,6 +1,7 @@
1
1
  import { createSharedComposable } from "@vueuse/core";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import { useContext, useShopwareContext } from "#imports";
5
6
  import type { Schemas, operations } from "#shopware";
6
7
 
@@ -99,7 +100,7 @@ export type UseCartReturn = {
99
100
  /**
100
101
  * Cart management logic.
101
102
  *
102
- * 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`
103
104
  *
104
105
  * @category Cart & Checkout
105
106
  */
@@ -243,7 +244,9 @@ export function useCartFunction(): UseCartReturn {
243
244
  const count = computed(() => {
244
245
  return cartItems.value.reduce(
245
246
  (accumulator: number, lineItem: Schemas["LineItem"]) =>
246
- lineItem.good === true ? lineItem.quantity + accumulator : accumulator,
247
+ lineItem.good === true
248
+ ? (lineItem.quantity ?? 0) + accumulator
249
+ : accumulator,
247
250
  0,
248
251
  );
249
252
  });
@@ -275,7 +278,7 @@ export function useCartFunction(): UseCartReturn {
275
278
  cartItems.value.length > 0 &&
276
279
  cartItems.value
277
280
  .filter((element) => element.type !== "promotion")
278
- .every((item) => item.states.includes("is-download"))
281
+ .every((item) => item.states?.includes("is-download") ?? false)
279
282
  );
280
283
  });
281
284
 
@@ -1,5 +1,6 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useCart, useCartErrorParamsResolver } from "#imports";
4
5
 
5
6
  vi.mock("../useCart/useCart.ts");
@@ -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";
@@ -86,6 +88,19 @@ describe("useCartItem", () => {
86
88
  expect(vm.itemOptions).toStrictEqual([]);
87
89
  });
88
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
+
89
104
  it("should remove item from the cart", async () => {
90
105
  const { vm } = useSetup(() =>
91
106
  useCartItem(ref(lineItem) as unknown as Ref<Schemas["LineItem"]>),
@@ -1,9 +1,15 @@
1
1
  import { getMainImageUrl } from "@shopware/helpers";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef, Ref } from "vue";
4
+
4
5
  import { useCart } from "#imports";
5
6
  import type { Schemas } from "#shopware";
6
7
 
8
+ type LineItemOptions = Schemas["PropertyGroupOption"][];
9
+ type LineItemPayloadWithOptions = {
10
+ options?: LineItemOptions;
11
+ };
12
+
7
13
  export type UseCartItemReturn = {
8
14
  /**
9
15
  * Calculated price {number} for the current item
@@ -24,7 +30,7 @@ export type UseCartItemReturn = {
24
30
  /**
25
31
  * Options (of variation) for the current item
26
32
  */
27
- itemOptions: ComputedRef<Schemas["LineItem"]["payload"]["options"]>;
33
+ itemOptions: ComputedRef<LineItemOptions>;
28
34
  /**
29
35
  * Type of the current item: "product" or "promotion"
30
36
  */
@@ -98,14 +104,16 @@ export function useCartItem(
98
104
 
99
105
  const itemTotalPrice = computed(() => cartItem.value.price?.totalPrice);
100
106
 
101
- const itemOptions = computed(
102
- () =>
103
- (cartItem.value.type === "product" && cartItem.value.payload?.options) ||
104
- [],
105
- );
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
+ });
106
114
 
107
115
  const itemStock = computed<number | undefined>(
108
- () => cartItem.value.deliveryInformation.stock,
116
+ () => cartItem.value.deliveryInformation?.stock,
109
117
  );
110
118
 
111
119
  const isDigital = computed(
@@ -1,5 +1,7 @@
1
1
  import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
2
3
  import { useCart, useCartNotification } from "#imports";
4
+
3
5
  import { useSetup } from "../_test";
4
6
 
5
7
  const pushErrorSpy = vi.fn();
@@ -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 { useCategory } from "./useCategory";
6
8
 
@@ -1,7 +1,9 @@
1
1
  import { computed } from "vue";
2
2
  import type { ComputedRef, Ref } from "vue";
3
+
3
4
  import { useContext } from "#imports";
4
5
  import type { Schemas } from "#shopware";
6
+
5
7
  import ContextError from "../helpers/ContextError";
6
8
 
7
9
  export type UseCategoryReturn = {
@@ -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";
@@ -12,7 +14,7 @@ describe("useCategorySearch", () => {
12
14
  vm.search("categoryId");
13
15
 
14
16
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
15
- expect.stringContaining("readCategory"),
17
+ expect.stringContaining("readCategory post"),
16
18
  expect.objectContaining({
17
19
  pathParams: {
18
20
  navigationId: "categoryId",
@@ -34,7 +36,7 @@ describe("useCategorySearch", () => {
34
36
  });
35
37
 
36
38
  expect(injections.apiClient.invoke).toHaveBeenCalledWith(
37
- expect.stringContaining("readCategory"),
39
+ expect.stringContaining("readCategory post"),
38
40
  expect.objectContaining({
39
41
  pathParams: {
40
42
  navigationId: "categoryId",
@@ -49,6 +51,79 @@ describe("useCategorySearch", () => {
49
51
  );
50
52
  });
51
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
+
52
127
  it("advanced search method", () => {
53
128
  const { vm, injections } = useSetup(useCategorySearch);
54
129
  injections.apiClient.invoke.mockResolvedValue({
@@ -95,4 +170,31 @@ describe("useCategorySearch", () => {
95
170
  }),
96
171
  );
97
172
  });
173
+
174
+ it("advancedSearch uses the cacheable GET variant when cacheableReads is enabled", () => {
175
+ const { vm, injections } = useSetup(useCategorySearch, {
176
+ shopware: { cacheableReads: true },
177
+ });
178
+ injections.apiClient.invoke.mockResolvedValue({
179
+ data: {},
180
+ });
181
+
182
+ vm.advancedSearch({
183
+ query: {
184
+ limit: 10,
185
+ },
186
+ });
187
+
188
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
189
+ expect.stringContaining("readCategoryListGet get"),
190
+ expect.objectContaining({
191
+ query: {
192
+ _criteria: encodeForQuery({
193
+ associations: {},
194
+ limit: 10,
195
+ }),
196
+ },
197
+ }),
198
+ );
199
+ });
98
200
  });
@@ -1,7 +1,14 @@
1
+ import { encodeForQuery } from "@shopware/api-client/helpers";
2
+
1
3
  import { useShopwareContext } from "#imports";
2
- import type { Schemas } from "#shopware";
4
+ import type { Schemas, operations } from "#shopware";
5
+
3
6
  import { cmsAssociations } from "../cms/cmsAssociations";
4
7
 
8
+ type ReadCategoryGetQuery = NonNullable<
9
+ operations["readCategoryGet get /category/{navigationId}"]["query"]
10
+ > & { _criteria?: string };
11
+
5
12
  export type UseCategorySearchReturn = {
6
13
  /**
7
14
  * Search for category by ID
@@ -30,7 +37,7 @@ export type UseCategorySearchReturn = {
30
37
  * @category Navigation & Routing
31
38
  */
32
39
  export function useCategorySearch(): UseCategorySearchReturn {
33
- const { apiClient } = useShopwareContext();
40
+ const { apiClient, cacheableReads } = useShopwareContext();
34
41
 
35
42
  async function search(
36
43
  categoryId: string,
@@ -40,21 +47,31 @@ export function useCategorySearch(): UseCategorySearchReturn {
40
47
  },
41
48
  ) {
42
49
  const associations = options?.withCmsAssociations ? cmsAssociations : {};
43
- const result = await apiClient.invoke(
44
- "readCategory post /category/{navigationId}",
45
- {
46
- pathParams: {
47
- navigationId: categoryId,
48
- },
49
- headers: {
50
- "sw-include-seo-urls": true,
51
- },
52
- body: {
53
- associations,
54
- ...options?.query,
55
- },
56
- },
57
- );
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
+ });
58
75
  return result.data;
59
76
  }
60
77
 
@@ -65,12 +82,17 @@ export function useCategorySearch(): UseCategorySearchReturn {
65
82
  const associations = options?.withCmsAssociations
66
83
  ? cmsAssociations.associations
67
84
  : {};
68
- const result = await apiClient.invoke("readCategoryList post /category", {
69
- body: {
70
- associations,
71
- ...options?.query,
72
- },
73
- });
85
+ const criteria = {
86
+ associations,
87
+ ...options?.query,
88
+ };
89
+ const result = cacheableReads
90
+ ? await apiClient.invoke("readCategoryListGet get /category", {
91
+ query: { _criteria: encodeForQuery(criteria) },
92
+ })
93
+ : await apiClient.invoke("readCategoryList post /category", {
94
+ body: criteria,
95
+ });
74
96
  return result.data.elements ?? [];
75
97
  }
76
98
 
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { ref } from "vue";
3
+
3
4
  import { useSetup } from "../_test";
4
5
  import { useCheckout } from "./useCheckout";
5
6
 
@@ -1,6 +1,7 @@
1
1
  import { defu } from "defu";
2
2
  import { computed, inject, provide, ref } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import { useSessionContext, useShopwareContext } from "#imports";
5
6
  import type { Schemas, operations } from "#shopware";
6
7
 
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import { useCmsBlock } from "./useCmsBlock";
5
7
 
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import LandingPageMock from "../mocks/LandingPage";
5
7
  import { useCmsMeta } from "./useCmsMeta";
@@ -1,6 +1,7 @@
1
1
  import { getTranslatedProperty } from "@shopware/helpers";
2
2
  import { computed } from "vue";
3
3
  import type { ComputedRef } from "vue";
4
+
4
5
  import type { Schemas } from "#shopware";
5
6
 
6
7
  export type UseCmsMetaReturn = {
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
+
2
3
  import type { Schemas } from "#shopware";
4
+
3
5
  import { useSetup } from "../_test";
4
6
  import CmsPage from "../mocks/CmsPage";
5
7
  import { useCmsSection } from "./useCmsSection";