@shopware/composables 0.0.0-canary-20250116155626

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -0
  3. package/composables/index.ts +1 -0
  4. package/dist/index.d.mts +2239 -0
  5. package/dist/index.d.ts +2239 -0
  6. package/dist/index.mjs +2686 -0
  7. package/nuxt.config.ts +14 -0
  8. package/package.json +83 -0
  9. package/src/_test/index.ts +1 -0
  10. package/src/_test/useSetup.ts +43 -0
  11. package/src/cms/README.md +9 -0
  12. package/src/cms/cmsAssociations.ts +28 -0
  13. package/src/cms/index.ts +2 -0
  14. package/src/cms/useCmsElementConfig.test.ts +145 -0
  15. package/src/cms/useCmsElementConfig.ts +29 -0
  16. package/src/cms/useCmsElementImage.test.ts +179 -0
  17. package/src/cms/useCmsElementImage.ts +103 -0
  18. package/src/cms/useCmsElementProductBox.test.ts +15 -0
  19. package/src/cms/useCmsElementProductBox.ts +25 -0
  20. package/src/createShopwareContext.test.ts +23 -0
  21. package/src/createShopwareContext.ts +43 -0
  22. package/src/devtools/plugin.ts +201 -0
  23. package/src/helpers/ContextError.spec.ts +20 -0
  24. package/src/helpers/ContextError.ts +6 -0
  25. package/src/index.test.ts +54 -0
  26. package/src/index.ts +111 -0
  27. package/src/mocks/Cart.ts +774 -0
  28. package/src/mocks/CmsPage.ts +544 -0
  29. package/src/mocks/CmsProductBox.ts +377 -0
  30. package/src/mocks/Configurator.ts +123 -0
  31. package/src/mocks/Country.ts +184 -0
  32. package/src/mocks/CrossSellingResponse.ts +552 -0
  33. package/src/mocks/LandingPage.ts +62 -0
  34. package/src/mocks/Menu.ts +598 -0
  35. package/src/mocks/Order.ts +1151 -0
  36. package/src/mocks/Product.ts +473 -0
  37. package/src/mocks/ProductTierPrices.ts +771 -0
  38. package/src/mocks/Salutations.ts +51 -0
  39. package/src/mocks/Search.ts +518 -0
  40. package/src/types/cmsBlockTypes.ts +80 -0
  41. package/src/types/cmsElementTypes.ts +381 -0
  42. package/src/types/cmsSectionTypes.ts +15 -0
  43. package/src/types/index.ts +52 -0
  44. package/src/useAddToCart/useAddToCart.test.ts +39 -0
  45. package/src/useAddToCart/useAddToCart.ts +90 -0
  46. package/src/useAddress/useAddress.test.ts +134 -0
  47. package/src/useAddress/useAddress.ts +202 -0
  48. package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +137 -0
  49. package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +225 -0
  50. package/src/useBreadcrumbs/useBreadcrumbs.test.ts +71 -0
  51. package/src/useBreadcrumbs/useBreadcrumbs.ts +89 -0
  52. package/src/useCart/useCart.test.ts +251 -0
  53. package/src/useCart/useCart.ts +314 -0
  54. package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.test.ts +122 -0
  55. package/src/useCartErrorParamsResolver/useCartErrorParamsResolver.ts +80 -0
  56. package/src/useCartItem/useCartItem.test.ts +168 -0
  57. package/src/useCartItem/useCartItem.ts +157 -0
  58. package/src/useCartNotification/useCartNotification.test.ts +129 -0
  59. package/src/useCartNotification/useCartNotification.ts +63 -0
  60. package/src/useCategory/useCategory.test.ts +14 -0
  61. package/src/useCategory/useCategory.ts +32 -0
  62. package/src/useCategorySearch/useCategorySearch.test.ts +98 -0
  63. package/src/useCategorySearch/useCategorySearch.ts +81 -0
  64. package/src/useCheckout/useCheckout.test.ts +104 -0
  65. package/src/useCheckout/useCheckout.ts +163 -0
  66. package/src/useCmsBlock/useCmsBlock.test.ts +25 -0
  67. package/src/useCmsBlock/useCmsBlock.ts +36 -0
  68. package/src/useCmsMeta/useCmsMeta.test.ts +17 -0
  69. package/src/useCmsMeta/useCmsMeta.ts +46 -0
  70. package/src/useCmsSection/useCmsSection.test.ts +18 -0
  71. package/src/useCmsSection/useCmsSection.ts +39 -0
  72. package/src/useCmsTranslations/useCmsTranslations.test.ts +10 -0
  73. package/src/useCmsTranslations/useCmsTranslations.ts +9 -0
  74. package/src/useContext/useContext.ts +36 -0
  75. package/src/useCountries/useCountries.test.ts +64 -0
  76. package/src/useCountries/useCountries.ts +64 -0
  77. package/src/useCustomerOrders/useCustomerOrders.test.ts +47 -0
  78. package/src/useCustomerOrders/useCustomerOrders.ts +89 -0
  79. package/src/useCustomerPassword/useCustomerPassword.test.ts +164 -0
  80. package/src/useCustomerPassword/useCustomerPassword.ts +57 -0
  81. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +41 -0
  82. package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +45 -0
  83. package/src/useInternationalization/useInternationalization.test.ts +155 -0
  84. package/src/useInternationalization/useInternationalization.ts +159 -0
  85. package/src/useLandingSearch/useLandingSearch.test.ts +30 -0
  86. package/src/useLandingSearch/useLandingSearch.ts +58 -0
  87. package/src/useListing/useListing.test.ts +249 -0
  88. package/src/useListing/useListing.ts +592 -0
  89. package/src/useLocalWishlist/useLocalWishlist.test.ts +54 -0
  90. package/src/useLocalWishlist/useLocalWishlist.ts +95 -0
  91. package/src/useNavigation/useNavigation.test.ts +68 -0
  92. package/src/useNavigation/useNavigation.ts +83 -0
  93. package/src/useNavigationContext/useNavigationContext.test.ts +48 -0
  94. package/src/useNavigationContext/useNavigationContext.ts +39 -0
  95. package/src/useNavigationSearch/useNavigationSearch.test.ts +110 -0
  96. package/src/useNavigationSearch/useNavigationSearch.ts +60 -0
  97. package/src/useNewsletter/useNewsletter.test.ts +55 -0
  98. package/src/useNewsletter/useNewsletter.ts +109 -0
  99. package/src/useNotifications/useNotifications.test.ts +56 -0
  100. package/src/useNotifications/useNotifications.ts +119 -0
  101. package/src/useOrderDetails/useOrderDetails.test.ts +224 -0
  102. package/src/useOrderDetails/useOrderDetails.ts +329 -0
  103. package/src/useOrderPayment/useOrderPayment.test.ts +80 -0
  104. package/src/useOrderPayment/useOrderPayment.ts +119 -0
  105. package/src/usePrice/usePrice.test.ts +97 -0
  106. package/src/usePrice/usePrice.ts +106 -0
  107. package/src/useProduct/useProduct.test.ts +36 -0
  108. package/src/useProduct/useProduct.ts +56 -0
  109. package/src/useProductAssociations/useProductAssociations.spec.ts +105 -0
  110. package/src/useProductAssociations/useProductAssociations.ts +107 -0
  111. package/src/useProductConfigurator/useProductConfigurator.spec.ts +77 -0
  112. package/src/useProductConfigurator/useProductConfigurator.ts +134 -0
  113. package/src/useProductPrice/useProductPrice.test.ts +126 -0
  114. package/src/useProductPrice/useProductPrice.ts +131 -0
  115. package/src/useProductReviews/useProductReviews.test.ts +45 -0
  116. package/src/useProductReviews/useProductReviews.ts +80 -0
  117. package/src/useProductSearch/useProductSearch.test.ts +37 -0
  118. package/src/useProductSearch/useProductSearch.ts +58 -0
  119. package/src/useProductSearchSuggest/useProductSearchSuggest.test.ts +19 -0
  120. package/src/useProductSearchSuggest/useProductSearchSuggest.ts +67 -0
  121. package/src/useProductWishlist/useProductWishlist.test.ts +63 -0
  122. package/src/useProductWishlist/useProductWishlist.ts +74 -0
  123. package/src/useSalutations/useSalutations.spec.ts +37 -0
  124. package/src/useSalutations/useSalutations.ts +55 -0
  125. package/src/useSessionContext/useSessionContext.test.ts +221 -0
  126. package/src/useSessionContext/useSessionContext.ts +281 -0
  127. package/src/useShopwareContext/useShopwareContext.test.ts +8 -0
  128. package/src/useShopwareContext/useShopwareContext.ts +31 -0
  129. package/src/useSyncWishlist/useSyncWishlist.test.ts +117 -0
  130. package/src/useSyncWishlist/useSyncWishlist.ts +117 -0
  131. package/src/useUrlResolver/useUrlResolver.test.ts +25 -0
  132. package/src/useUrlResolver/useUrlResolver.ts +31 -0
  133. package/src/useUser/useUser.test.ts +290 -0
  134. package/src/useUser/useUser.ts +321 -0
  135. package/src/useWishlist/useWishlist.test.ts +178 -0
  136. package/src/useWishlist/useWishlist.ts +128 -0
  137. package/types/api-types.ts +11 -0
@@ -0,0 +1,202 @@
1
+ import { ApiClientError } from "@shopware/api-client";
2
+ import type { ApiError } from "@shopware/api-client";
3
+ import { computed, inject, provide, ref } from "vue";
4
+ import type { ComputedRef, Ref } from "vue";
5
+ import { useShopwareContext } from "#imports";
6
+ import type { Schemas } from "#shopware";
7
+
8
+ export type UseAddressReturn = {
9
+ /**
10
+ * List of customer addresses
11
+ */
12
+ customerAddresses: ComputedRef<Schemas["CustomerAddress"][]>;
13
+ /**
14
+ * Loads the addresses that are available under `customerAddresses` property
15
+ */
16
+ loadCustomerAddresses(): Promise<Schemas["CustomerAddress"][]>;
17
+ /**
18
+ * Allows to create new address for a current customer
19
+ */
20
+ createCustomerAddress(
21
+ customerAddress: Schemas["CustomerAddress"],
22
+ ): Promise<Schemas["CustomerAddress"]>;
23
+ /**
24
+ * Allows to update existing address for a current customer
25
+ */
26
+ updateCustomerAddress(
27
+ customerAddress: Schemas["CustomerAddress"],
28
+ ): Promise<Schemas["CustomerAddress"]>;
29
+ /**
30
+ * Allows to delete existing address for a current customer
31
+ */
32
+ deleteCustomerAddress(addressId: string): Promise<void>;
33
+ /**
34
+ * Sets the address for given ID as default billing address
35
+ */
36
+ setDefaultCustomerBillingAddress(addressId: string): Promise<string>;
37
+ /**
38
+ * Sets the address for given ID as default shipping address
39
+ */
40
+ setDefaultCustomerShippingAddress(addressId: string): Promise<string>;
41
+ /**
42
+ * Returns formatted error message
43
+ *
44
+ * @param {ShopwareError} error
45
+ */
46
+ errorMessageBuilder(error: ApiError): string | null;
47
+ };
48
+
49
+ /**
50
+ * Composable to manage customer addresses
51
+ *
52
+ * With this composable you can:
53
+ * - Fetch customer addresses
54
+ * - Return customer addresses
55
+ * - Create new customer address
56
+ * - Update existing customer address
57
+ * - Delete existing customer address
58
+ * - Set default billing address
59
+ * - Set default shipping address
60
+ * - Format error message
61
+ *
62
+ * @public
63
+ *
64
+ * @category Cart & Checkout
65
+ */
66
+ export function useAddress(): UseAddressReturn {
67
+ const { apiClient } = useShopwareContext();
68
+
69
+ const _storeCustomerAddresses: Ref<Schemas["CustomerAddress"][]> = inject(
70
+ "swCustomerAddresses",
71
+ ref([]),
72
+ );
73
+ provide("swCustomerAddresses", _storeCustomerAddresses);
74
+
75
+ /**
76
+ * Get customer address list
77
+ */
78
+ async function loadCustomerAddresses(
79
+ parameters: Schemas["Criteria"] = {},
80
+ ): Promise<Schemas["CustomerAddress"][]> {
81
+ try {
82
+ const result = await apiClient.invoke(
83
+ "listAddress post /account/list-address",
84
+ {
85
+ body: parameters,
86
+ },
87
+ );
88
+ _storeCustomerAddresses.value = result.data.elements;
89
+ } catch (error) {
90
+ if (error instanceof ApiClientError) {
91
+ if (error.status === 403) {
92
+ _storeCustomerAddresses.value = [];
93
+ }
94
+ }
95
+ throw error;
96
+ }
97
+ return _storeCustomerAddresses.value;
98
+ }
99
+
100
+ /**
101
+ * Add new customer address
102
+ */
103
+ async function createCustomerAddress(
104
+ customerAddress: Schemas["CustomerAddress"],
105
+ ): Promise<Schemas["CustomerAddress"]> {
106
+ const result = await apiClient.invoke(
107
+ "createCustomerAddress post /account/address",
108
+ {
109
+ body: customerAddress,
110
+ },
111
+ );
112
+ return result.data;
113
+ }
114
+
115
+ /**
116
+ * Update customer address
117
+ */
118
+ async function updateCustomerAddress(
119
+ customerAddress: Schemas["CustomerAddress"],
120
+ ): Promise<Schemas["CustomerAddress"]> {
121
+ // customerAddress.addressId = customerAddress.id;
122
+
123
+ const result = await apiClient.invoke(
124
+ "updateCustomerAddress patch /account/address/{addressId}",
125
+ {
126
+ pathParams: {
127
+ addressId: customerAddress.id,
128
+ },
129
+ body: customerAddress,
130
+ },
131
+ );
132
+ return result.data;
133
+ }
134
+
135
+ /**
136
+ * Delete customer address
137
+ */
138
+ async function deleteCustomerAddress(addressId: string): Promise<void> {
139
+ await apiClient.invoke(
140
+ "deleteCustomerAddress delete /account/address/{addressId}",
141
+ { pathParams: { addressId } },
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Set default customer billing address
147
+ */
148
+ async function setDefaultCustomerBillingAddress(
149
+ addressId: string,
150
+ ): Promise<string> {
151
+ const result = await apiClient.invoke(
152
+ "defaultBillingAddress patch /account/address/default-billing/{addressId}",
153
+ {
154
+ pathParams: {
155
+ addressId,
156
+ },
157
+ },
158
+ );
159
+ return result.data;
160
+ }
161
+
162
+ /**
163
+ * Set default customer shipping address
164
+ */
165
+ async function setDefaultCustomerShippingAddress(
166
+ addressId: string,
167
+ ): Promise<string> {
168
+ const result = await apiClient.invoke(
169
+ "defaultShippingAddress patch /account/address/default-shipping/{addressId}",
170
+ {
171
+ pathParams: { addressId },
172
+ },
173
+ );
174
+ return result.data;
175
+ }
176
+
177
+ /**
178
+ * Returns formatted error message
179
+ *
180
+ * @param {error} error
181
+ * @returns {string | null}
182
+ */
183
+ function errorMessageBuilder(error: ApiError): string | null {
184
+ switch (error.code) {
185
+ case "VIOLATION::IS_BLANK_ERROR":
186
+ return `${error?.source?.pointer?.slice(1)} - ${error.detail}`;
187
+ default:
188
+ return null;
189
+ }
190
+ }
191
+
192
+ return {
193
+ customerAddresses: computed(() => _storeCustomerAddresses.value || []),
194
+ loadCustomerAddresses,
195
+ createCustomerAddress,
196
+ updateCustomerAddress,
197
+ deleteCustomerAddress,
198
+ setDefaultCustomerBillingAddress,
199
+ setDefaultCustomerShippingAddress,
200
+ errorMessageBuilder,
201
+ };
202
+ }
@@ -0,0 +1,137 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { useSetup } from "../_test";
3
+ import { useB2bQuoteManagement } from "./useB2bQuoteManagement";
4
+ /**
5
+ * ToDo - How to mock api-client!!
6
+ */
7
+ describe("useB2bQuoteManagement", () => {
8
+ it("getQuoteList", async () => {
9
+ const { vm, injections } = useSetup(useB2bQuoteManagement);
10
+ injections.apiClient.invoke.mockResolvedValue({
11
+ data: { elements: [{ id: "test-1" }] },
12
+ });
13
+
14
+ await vm.getQuoteList();
15
+
16
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
17
+ expect.stringContaining("readQuotes"),
18
+ );
19
+ });
20
+
21
+ it("getQuoteList - no elements", async () => {
22
+ const { vm, injections } = useSetup(useB2bQuoteManagement);
23
+ injections.apiClient.invoke.mockResolvedValue({ data: {} });
24
+
25
+ expect(await vm.getQuoteList()).toStrictEqual([]);
26
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
27
+ expect.stringContaining("readQuotes"),
28
+ );
29
+ });
30
+
31
+ it("getQuote", async () => {
32
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
33
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
34
+ await vm.getQuote("test-12");
35
+
36
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
37
+ expect.stringContaining("readQuote"),
38
+ expect.objectContaining({
39
+ pathParams: { id: "test-12" },
40
+ body: {
41
+ associations: {
42
+ lineItems: {},
43
+ comments: {},
44
+ stateMachineState: {},
45
+ },
46
+ },
47
+ }),
48
+ );
49
+ });
50
+
51
+ it("declineQuote", async () => {
52
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
53
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
54
+ await vm.declineQuote("test-12", "test-comment");
55
+
56
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
57
+ expect.stringContaining("declineQuote"),
58
+ expect.objectContaining({
59
+ pathParams: { id: "test-12" },
60
+ body: { comment: "test-comment" },
61
+ }),
62
+ );
63
+ });
64
+
65
+ it("requestChangeQuote", async () => {
66
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
67
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
68
+ await vm.requestChangeQuote("test-12", "test-comment");
69
+
70
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
71
+ expect.stringContaining("requestChangeQuote"),
72
+ expect.objectContaining({
73
+ pathParams: { id: "test-12" },
74
+ body: {
75
+ comment: "test-comment",
76
+ },
77
+ }),
78
+ );
79
+ });
80
+
81
+ it("changeShippingMethod", async () => {
82
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
83
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
84
+ await vm.changeShippingMethod("test-12", "test-method");
85
+
86
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
87
+ expect.stringContaining("switchPaymentOrShippingMethod"),
88
+ expect.objectContaining({
89
+ pathParams: { id: "test-12" },
90
+ }),
91
+ );
92
+ });
93
+
94
+ it("changePaymentMethod", async () => {
95
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
96
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
97
+ await vm.changePaymentMethod("test-12", "test-method");
98
+
99
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
100
+
101
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
102
+ expect.stringContaining("switchPaymentOrShippingMethod"),
103
+ expect.objectContaining({
104
+ pathParams: { id: "test-12" },
105
+ }),
106
+ );
107
+ });
108
+
109
+ it("requestQuote", async () => {
110
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
111
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
112
+ await vm.requestQuote("comment");
113
+
114
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
115
+
116
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
117
+ expect.stringContaining("requestQuote"),
118
+ expect.objectContaining({
119
+ body: { comment: "comment" },
120
+ }),
121
+ );
122
+ });
123
+
124
+ it("createOrderFromQuote", async () => {
125
+ const { vm, injections } = useSetup(() => useB2bQuoteManagement());
126
+ injections.apiClient.invoke.mockResolvedValue({ data: null });
127
+ await vm.createOrderFromQuote("test-12", "test-comment");
128
+
129
+ expect(injections.apiClient.invoke).toHaveBeenCalledWith(
130
+ expect.stringContaining("createOrderFromQuote"),
131
+ expect.objectContaining({
132
+ pathParams: { id: "test-12" },
133
+ body: { customerComment: "test-comment" },
134
+ }),
135
+ );
136
+ });
137
+ });
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Commerce composable
3
+ */
4
+ import { useShopwareContext } from "#imports";
5
+ import type { Schemas } from "#shopware";
6
+
7
+ type UseB2bQuoteManagement = {
8
+ getQuoteList: () => Promise<Schemas["Quote"][]>;
9
+ getQuote: (quoteId: string) => Promise<Schemas["Quote"]>;
10
+ declineQuote: (quoteId: string, comment: string) => Promise<void>;
11
+ requestChangeQuote: (quoteId: string, comment: string) => Promise<void>;
12
+ requestQuote: (comment: string) => Promise<Schemas["Quote"]>;
13
+ createOrderFromQuote: (
14
+ quoteId: string,
15
+ comment: string,
16
+ ) => Promise<Schemas["Order"]>;
17
+ changeShippingMethod: (
18
+ quoteId: string,
19
+ shippingMethodId: string,
20
+ ) => Promise<void>;
21
+ changePaymentMethod: (
22
+ quoteId: string,
23
+ paymentMethodId: string,
24
+ ) => Promise<void>;
25
+ };
26
+
27
+ export type ChangePaymentShippingMethodParams = {
28
+ quoteId: string;
29
+ paymentMethodId?: string;
30
+ shippingMethodId?: string;
31
+ };
32
+
33
+ /**
34
+ * Composable to manage quotes in the B2BQuote module.
35
+ *
36
+ * With this composable you can:
37
+ * - Get list of quotes
38
+ * - Get quote details
39
+ * - Decline quote
40
+ * - Request change of the quote
41
+ * - Change shipping method
42
+ * - Change payment method
43
+ * - Create order from quote
44
+ * - Request quote
45
+ *
46
+ * @category B2B
47
+ * @returns {UseB2bQuoteManagement}
48
+ */
49
+ export function useB2bQuoteManagement(): UseB2bQuoteManagement {
50
+ const { apiClient } = useShopwareContext();
51
+
52
+ /**
53
+ * Get list of quotes
54
+ *
55
+ * @returns {Promise<Schemas["Quote"][]>}
56
+ */
57
+ const getQuoteList = async () => {
58
+ const response = await apiClient.invoke("readQuotes post /quotes");
59
+ return response.data.elements ?? [];
60
+ };
61
+
62
+ /**
63
+ * Get quote details
64
+ *
65
+ * @param {string} quoteId
66
+ * @returns {Promise<Schemas["Quote"]>}
67
+ */
68
+ const getQuote = async (quoteId: string) => {
69
+ const response = await apiClient.invoke(
70
+ "readQuote post /quote/detail/{id}",
71
+ {
72
+ pathParams: {
73
+ id: quoteId,
74
+ },
75
+ body: {
76
+ associations: {
77
+ lineItems: {},
78
+ comments: {},
79
+ stateMachineState: {},
80
+ },
81
+ },
82
+ },
83
+ );
84
+ return response.data;
85
+ };
86
+
87
+ /**
88
+ * Decline quote
89
+ *
90
+ * @param {string} quoteId
91
+ * @param {string} comment
92
+ * @returns {Promise<void>}
93
+ */
94
+ async function declineQuote(quoteId: string, comment: string) {
95
+ await apiClient.invoke("declineQuote post /quote/{id}/decline", {
96
+ pathParams: {
97
+ id: quoteId,
98
+ },
99
+ body: {
100
+ comment,
101
+ },
102
+ });
103
+ }
104
+
105
+ /**
106
+ * Request change of the quote
107
+ *
108
+ * @param {string} quoteId
109
+ * @param {string} comment
110
+ * @returns {Promise<void>}
111
+ */
112
+ async function requestChangeQuote(quoteId: string, comment: string) {
113
+ await apiClient.invoke(
114
+ "requestChangeQuote post /quote/{id}/request-change",
115
+ {
116
+ pathParams: {
117
+ id: quoteId,
118
+ },
119
+ body: { comment },
120
+ },
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Quote is built from the cart.
126
+ * If Cart is empty, the request will returns 400 Bad Request
127
+ *
128
+ * @param {string} comment
129
+ * @returns {Promise<Schemas["Quote"]>}
130
+ */
131
+ const requestQuote = async (comment: string) => {
132
+ const response = await apiClient.invoke(
133
+ "requestQuote post /quote/request",
134
+ { body: { comment } },
135
+ );
136
+ return response.data;
137
+ };
138
+
139
+ /**
140
+ * Change payment or shipping method
141
+ *
142
+ * @param {ChangePaymentShippingMethodParams} params
143
+ *
144
+ * @returns {Promise<void>}
145
+ */
146
+ const changePaymentShippingMethod = async (params: {
147
+ quoteId: string;
148
+ paymentMethodId?: string;
149
+ shippingMethodId?: string;
150
+ }) => {
151
+ const body: {
152
+ paymentMethodId?: string;
153
+ shippingMethodId?: string;
154
+ } = {};
155
+
156
+ if (params.paymentMethodId) body.paymentMethodId = params.paymentMethodId;
157
+
158
+ if (params.shippingMethodId)
159
+ body.shippingMethodId = params.shippingMethodId;
160
+
161
+ await apiClient.invoke(
162
+ "switchPaymentOrShippingMethod post /quote/{id}/configure",
163
+ {
164
+ pathParams: { id: params.quoteId },
165
+ body,
166
+ },
167
+ );
168
+ };
169
+
170
+ /**
171
+ * Proxy method to change shipping method
172
+ *
173
+ * @param quoteId
174
+ * @param shippingMethodId
175
+ * @returns {Promise<void>}
176
+ */
177
+ async function changeShippingMethod(
178
+ quoteId: string,
179
+ shippingMethodId: string,
180
+ ) {
181
+ await changePaymentShippingMethod({ quoteId, shippingMethodId });
182
+ }
183
+
184
+ /**
185
+ * Proxy method that changes payment method
186
+ *
187
+ * @param quoteId
188
+ * @param paymentMethodId
189
+ * @returns {Promise<void>}
190
+ */
191
+ async function changePaymentMethod(quoteId: string, paymentMethodId: string) {
192
+ await changePaymentShippingMethod({ quoteId, paymentMethodId });
193
+ }
194
+
195
+ /**
196
+ * Create order from quote
197
+ *
198
+ * @param quoteId
199
+ * @param comment
200
+ *
201
+ * @returns {Promise<Schemas["Order"]>}
202
+ */
203
+ const createOrderFromQuote = async (quoteId: string, comment: string) => {
204
+ const response = await apiClient.invoke(
205
+ "createOrderFromQuote post /quote/order/{id}",
206
+ {
207
+ pathParams: { id: quoteId },
208
+ body: { customerComment: comment },
209
+ },
210
+ );
211
+
212
+ return response.data;
213
+ };
214
+
215
+ return {
216
+ getQuoteList,
217
+ getQuote,
218
+ declineQuote,
219
+ requestChangeQuote,
220
+ changeShippingMethod,
221
+ changePaymentMethod,
222
+ requestQuote,
223
+ createOrderFromQuote,
224
+ };
225
+ }
@@ -0,0 +1,71 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import type { operations } from "#shopware";
3
+ import { useSetup } from "../_test";
4
+ import { useBreadcrumbs } from "./useBreadcrumbs";
5
+
6
+ describe("useBreadcrumbs", () => {
7
+ const consoleErrorSpy = vi.spyOn(console, "error");
8
+
9
+ beforeEach(() => {
10
+ consoleErrorSpy.mockImplementation(() => {});
11
+ });
12
+
13
+ it("should add breadcrumbs", async () => {
14
+ const { vm } = useSetup(() =>
15
+ useBreadcrumbs([
16
+ {
17
+ name: "Test",
18
+ path: "/",
19
+ },
20
+ ]),
21
+ );
22
+
23
+ expect(vm.breadcrumbs.length).toBe(1);
24
+ });
25
+
26
+ it("should clear breadcrumbs", async () => {
27
+ const { vm } = useSetup(() =>
28
+ useBreadcrumbs([
29
+ {
30
+ name: "Test",
31
+ path: "/",
32
+ },
33
+ ]),
34
+ );
35
+
36
+ vm.clearBreadcrumbs();
37
+ expect(vm.breadcrumbs.length).toBe(0);
38
+ });
39
+
40
+ it("should invoke buildDynamicBreadcrumbs", async () => {
41
+ const { vm, injections } = useSetup(() => useBreadcrumbs());
42
+ injections.apiClient.invoke.mockResolvedValue({
43
+ data: {
44
+ breadcrumbs: [
45
+ {
46
+ path: "test",
47
+ },
48
+ ],
49
+ },
50
+ });
51
+ await vm.buildDynamicBreadcrumbs({
52
+ breadcrumbs: [{ path: "test" }],
53
+ } as unknown as operations["readBreadcrumb get /breadcrumb/{id}"]["response"]);
54
+
55
+ expect(vm.breadcrumbs[0].path).toBe("/test");
56
+ });
57
+
58
+ it("should push breadcrumb", async () => {
59
+ const { vm } = useSetup(() => useBreadcrumbs());
60
+ vm.pushBreadcrumb({
61
+ name: "Test",
62
+ path: "/",
63
+ });
64
+ expect(vm.breadcrumbs.length).toBe(1);
65
+ vm.pushBreadcrumb({
66
+ name: "Test",
67
+ path: "/",
68
+ });
69
+ expect(vm.breadcrumbs.length).toBe(2);
70
+ });
71
+ });