@shopware/composables 1.9.1 → 1.10.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 +33 -5
- package/dist/index.d.mts +94 -28
- package/dist/index.d.ts +94 -28
- package/dist/index.mjs +95 -57
- package/package.json +10 -10
- package/src/cms/cmsAssociations.ts +5 -1
- package/src/cms/useCmsElementConfig.ts +1 -1
- package/src/types/cmsBlockTypes.ts +2 -0
- package/src/types/cmsElementTypes.ts +24 -18
- package/src/useCart/useCart.test.ts +12 -0
- package/src/useCart/useCart.ts +17 -0
- package/src/useCustomerOrders/useCustomerOrders.ts +1 -1
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.test.ts +19 -21
- package/src/useDefaultOrderAssociations/useDefaultOrderAssociations.ts +23 -30
- package/src/useLandingSearch/useLandingSearch.test.ts +1 -1
- package/src/useLandingSearch/useLandingSearch.ts +1 -1
- package/src/useListing/useListing.test.ts +73 -0
- package/src/useListing/useListing.ts +10 -3
- package/src/useNewsletter/useNewsletter.ts +13 -0
- package/src/useOrderDetails/useOrderDetails.ts +5 -11
- package/src/useOrderPayment/useOrderPayment.ts +1 -0
- package/src/useProductWishlist/useProductWishlist.ts +2 -2
- package/src/useSessionContext/useSessionContext.ts +1 -1
- package/src/useSyncWishlist/useSyncWishlist.test.ts +34 -17
- package/src/useSyncWishlist/useSyncWishlist.ts +27 -8
- package/src/useUser/useUser.test.ts +126 -3
- package/src/useUser/useUser.ts +6 -1
- package/src/useWishlist/useWishlist.test.ts +9 -0
- package/src/useWishlist/useWishlist.ts +22 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
@@ -51,22 +51,22 @@
|
|
|
51
51
|
"types"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@vueuse/core": "
|
|
54
|
+
"@vueuse/core": "14.0.0",
|
|
55
55
|
"defu": "6.1.4",
|
|
56
56
|
"scule": "1.3.0",
|
|
57
|
-
"@shopware/helpers": "1.
|
|
58
|
-
"@shopware/api-client": "1.
|
|
57
|
+
"@shopware/helpers": "1.6.0",
|
|
58
|
+
"@shopware/api-client": "1.4.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@biomejs/biome": "1.8.3",
|
|
62
|
-
"@nuxt/kit": "
|
|
63
|
-
"@vitest/coverage-v8": "3.2.
|
|
62
|
+
"@nuxt/kit": "4.2.1",
|
|
63
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
64
64
|
"@vue/test-utils": "2.4.6",
|
|
65
|
-
"happy-dom": "
|
|
66
|
-
"typescript": "5.
|
|
65
|
+
"happy-dom": "20.0.10",
|
|
66
|
+
"typescript": "5.9.3",
|
|
67
67
|
"unbuild": "2.0.0",
|
|
68
|
-
"vitest": "3.2.
|
|
69
|
-
"vue": "3.5.
|
|
68
|
+
"vitest": "3.2.4",
|
|
69
|
+
"vue": "3.5.24",
|
|
70
70
|
"tsconfig": "0.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
@@ -7,7 +7,7 @@ import type { ElementConfig } from "../types";
|
|
|
7
7
|
* @category CMS (Shopping Experiences)
|
|
8
8
|
*/
|
|
9
9
|
export function useCmsElementConfig<
|
|
10
|
-
T extends Schemas["CmsSlot"] & {
|
|
10
|
+
T extends Omit<Schemas["CmsSlot"], "config"> & {
|
|
11
11
|
config: T["config"] extends {
|
|
12
12
|
[key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
|
|
13
13
|
}
|
|
@@ -31,7 +31,7 @@ type ElementFieldConfig = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// Text
|
|
34
|
-
export type CmsElementText = Schemas["CmsSlot"] & {
|
|
34
|
+
export type CmsElementText = Omit<Schemas["CmsSlot"], "config"> & {
|
|
35
35
|
type: "text" | typeof String;
|
|
36
36
|
slot: typeof String;
|
|
37
37
|
config: TextElementConfig;
|
|
@@ -46,7 +46,7 @@ export type CmsElementText = Schemas["CmsSlot"] & {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// HTML
|
|
49
|
-
export type CmsElementHtml = Schemas["CmsSlot"] & {
|
|
49
|
+
export type CmsElementHtml = Omit<Schemas["CmsSlot"], "config"> & {
|
|
50
50
|
type: "html";
|
|
51
51
|
data: {
|
|
52
52
|
content: string;
|
|
@@ -68,7 +68,7 @@ type ImageElementConfig = {
|
|
|
68
68
|
horizontalAlign: ElementConfig<VerticalAlign>;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
export type CmsElementImage = Schemas["CmsSlot"] & {
|
|
71
|
+
export type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
|
|
72
72
|
type: "image";
|
|
73
73
|
config: ImageElementConfig;
|
|
74
74
|
data: {
|
|
@@ -102,7 +102,7 @@ type ImageSliderElementConfig = ImageElementConfig &
|
|
|
102
102
|
>;
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
export type CmsElementImageSlider = Schemas["CmsSlot"] & {
|
|
105
|
+
export type CmsElementImageSlider = Omit<Schemas["CmsSlot"], "config"> & {
|
|
106
106
|
type: "image-slider";
|
|
107
107
|
config: ImageSliderElementConfig;
|
|
108
108
|
data: {
|
|
@@ -128,7 +128,7 @@ type ImageGalleryElementConfig = ImageSliderElementConfig & {
|
|
|
128
128
|
zoom: ElementConfig<boolean>;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
export type CmsElementImageGallery = Schemas["CmsSlot"] & {
|
|
131
|
+
export type CmsElementImageGallery = Omit<Schemas["CmsSlot"], "config"> & {
|
|
132
132
|
type: "image-gallery";
|
|
133
133
|
config: ImageGalleryElementConfig;
|
|
134
134
|
data: {
|
|
@@ -161,7 +161,7 @@ type YouTubeVideoElementConfig = {
|
|
|
161
161
|
needsConfirmation: ElementConfig<boolean>;
|
|
162
162
|
advancedPrivacyMode: ElementConfig<boolean>;
|
|
163
163
|
};
|
|
164
|
-
export type CmsElementYoutubeVideo = Schemas["CmsSlot"] & {
|
|
164
|
+
export type CmsElementYoutubeVideo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
165
165
|
type: "youtube-video";
|
|
166
166
|
config: YouTubeVideoElementConfig;
|
|
167
167
|
data: {
|
|
@@ -189,7 +189,7 @@ type VimeoVideoElementConfig = {
|
|
|
189
189
|
needsConfirmation: ElementConfig<boolean>;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
export type CmsElementVimeoVideo = Schemas["CmsSlot"] & {
|
|
192
|
+
export type CmsElementVimeoVideo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
193
193
|
type: "vimeo-video";
|
|
194
194
|
config: VimeoVideoElementConfig;
|
|
195
195
|
data: {
|
|
@@ -208,7 +208,7 @@ type ProductBoxElementConfig = {
|
|
|
208
208
|
product: ElementConfig<string>;
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
export type CmsElementProductBox = Schemas["CmsSlot"] & {
|
|
211
|
+
export type CmsElementProductBox = Omit<Schemas["CmsSlot"], "config"> & {
|
|
212
212
|
type: "product-box";
|
|
213
213
|
config: ProductBoxElementConfig;
|
|
214
214
|
data: {
|
|
@@ -234,7 +234,7 @@ type ProductSliderElementConfig = {
|
|
|
234
234
|
productStreamSorting: ElementConfig<string>;
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
-
export type CmsElementProductSlider = Schemas["CmsSlot"] & {
|
|
237
|
+
export type CmsElementProductSlider = Omit<Schemas["CmsSlot"], "config"> & {
|
|
238
238
|
type: "product-slider";
|
|
239
239
|
config: ProductSliderElementConfig;
|
|
240
240
|
data: {
|
|
@@ -256,7 +256,7 @@ type CmsSidebarFilterElementConfig = {
|
|
|
256
256
|
verticalAlign: ElementConfig<VerticalAlign>;
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
export type CmsElementSidebarFilter = Schemas["CmsSlot"] & {
|
|
259
|
+
export type CmsElementSidebarFilter = Omit<Schemas["CmsSlot"], "config"> & {
|
|
260
260
|
type: "sidebar-filter";
|
|
261
261
|
config: CmsSidebarFilterElementConfig;
|
|
262
262
|
};
|
|
@@ -273,7 +273,7 @@ type CmsProductListingElementConfig = {
|
|
|
273
273
|
propertyWhitelist: ElementConfig<string[]>;
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
-
export type CmsElementProductListing = Schemas["CmsSlot"] & {
|
|
276
|
+
export type CmsElementProductListing = Omit<Schemas["CmsSlot"], "config"> & {
|
|
277
277
|
type: "product-listing";
|
|
278
278
|
config: CmsProductListingElementConfig;
|
|
279
279
|
data: {
|
|
@@ -286,7 +286,10 @@ export type CmsElementProductListing = Schemas["CmsSlot"] & {
|
|
|
286
286
|
|
|
287
287
|
type CategoryNavigationElementConfig = unknown;
|
|
288
288
|
|
|
289
|
-
export type CmsElementCategoryNavigation =
|
|
289
|
+
export type CmsElementCategoryNavigation = Omit<
|
|
290
|
+
Schemas["CmsSlot"],
|
|
291
|
+
"config"
|
|
292
|
+
> & {
|
|
290
293
|
type: "category-navigation";
|
|
291
294
|
config: CategoryNavigationElementConfig;
|
|
292
295
|
};
|
|
@@ -296,7 +299,10 @@ type ProductDescriptionReviewsElementConfig = {
|
|
|
296
299
|
alignment: ElementConfig<VerticalAlign>;
|
|
297
300
|
};
|
|
298
301
|
|
|
299
|
-
export type CmsElementProductDescriptionReviews =
|
|
302
|
+
export type CmsElementProductDescriptionReviews = Omit<
|
|
303
|
+
Schemas["CmsSlot"],
|
|
304
|
+
"config"
|
|
305
|
+
> & {
|
|
300
306
|
type: "product-description-reviews";
|
|
301
307
|
config: ProductDescriptionReviewsElementConfig;
|
|
302
308
|
data: {
|
|
@@ -314,7 +320,7 @@ export type CmsElementProductDescriptionReviews = Schemas["CmsSlot"] & {
|
|
|
314
320
|
|
|
315
321
|
type BuyBoxElementConfig = ProductDescriptionReviewsElementConfig;
|
|
316
322
|
// buy box has the same interface in data as product description reviews! unify later
|
|
317
|
-
export type CmsElementBuyBox = Schemas["CmsSlot"] & {
|
|
323
|
+
export type CmsElementBuyBox = Omit<Schemas["CmsSlot"], "config"> & {
|
|
318
324
|
type: "buy-box";
|
|
319
325
|
config: BuyBoxElementConfig;
|
|
320
326
|
data: {
|
|
@@ -337,7 +343,7 @@ type CrossSellingElementConfig = {
|
|
|
337
343
|
displayMode: ElementConfig<DisplayMode>;
|
|
338
344
|
};
|
|
339
345
|
|
|
340
|
-
export type CmsElementCrossSelling = Schemas["CmsSlot"] & {
|
|
346
|
+
export type CmsElementCrossSelling = Omit<Schemas["CmsSlot"], "config"> & {
|
|
341
347
|
type: "cross-selling";
|
|
342
348
|
config: CrossSellingElementConfig;
|
|
343
349
|
data: {
|
|
@@ -356,14 +362,14 @@ type FormElementConfig = {
|
|
|
356
362
|
defaultMailReceiver: ElementConfig<boolean>;
|
|
357
363
|
};
|
|
358
364
|
|
|
359
|
-
export type CmsElementForm = Schemas["CmsSlot"] & {
|
|
365
|
+
export type CmsElementForm = Omit<Schemas["CmsSlot"], "config"> & {
|
|
360
366
|
type: "form";
|
|
361
367
|
config: FormElementConfig;
|
|
362
368
|
data: Schemas["Salutation"][];
|
|
363
369
|
};
|
|
364
370
|
|
|
365
371
|
// Product Name
|
|
366
|
-
export type CmsElementProductName = Schemas["CmsSlot"] & {
|
|
372
|
+
export type CmsElementProductName = Omit<Schemas["CmsSlot"], "config"> & {
|
|
367
373
|
type: "product-name";
|
|
368
374
|
config: TextElementConfig;
|
|
369
375
|
fieldConfig: ElementFieldConfig[];
|
|
@@ -377,7 +383,7 @@ export type CmsElementProductName = Schemas["CmsSlot"] & {
|
|
|
377
383
|
};
|
|
378
384
|
|
|
379
385
|
// Manufacturer Logo
|
|
380
|
-
export type CmsElementManufacturerLogo = Schemas["CmsSlot"] & {
|
|
386
|
+
export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
381
387
|
type: "manufacturer-logo";
|
|
382
388
|
config: ImageElementConfig;
|
|
383
389
|
data: {
|
|
@@ -144,6 +144,18 @@ describe("useCart", () => {
|
|
|
144
144
|
);
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
it("remove item by id", async () => {
|
|
148
|
+
await vm.removeItemById("01893ed931d571718e8138e7df7d68d1");
|
|
149
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
150
|
+
expect.stringContaining("removeLineItem"),
|
|
151
|
+
expect.objectContaining({
|
|
152
|
+
body: {
|
|
153
|
+
ids: ["01893ed931d571718e8138e7df7d68d1"],
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
147
159
|
it("submitPromotionCode", async () => {
|
|
148
160
|
injections.apiClient.invoke.mockResolvedValue({
|
|
149
161
|
data: {
|
package/src/useCart/useCart.ts
CHANGED
|
@@ -60,6 +60,10 @@ export type UseCartReturn = {
|
|
|
60
60
|
* Removes the provided LineItem from the cart
|
|
61
61
|
*/
|
|
62
62
|
removeItem(lineItem: Schemas["LineItem"]): Promise<Schemas["Cart"]>;
|
|
63
|
+
/**
|
|
64
|
+
* Removes the item with the provided id from the cart
|
|
65
|
+
*/
|
|
66
|
+
removeItemById(id: string): Promise<Schemas["Cart"]>;
|
|
63
67
|
/**
|
|
64
68
|
* The total price of the cart (including calculated costs like shipping)
|
|
65
69
|
*/
|
|
@@ -168,6 +172,18 @@ export function useCartFunction(): UseCartReturn {
|
|
|
168
172
|
return data;
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
async function removeItemById(id: string) {
|
|
176
|
+
const { data } = await apiClient.invoke(
|
|
177
|
+
"removeLineItem post /checkout/cart/line-item/delete",
|
|
178
|
+
{
|
|
179
|
+
body: { ids: [id] },
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
_storeCart.value = data;
|
|
183
|
+
setCartErrors(data);
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
|
|
171
187
|
async function changeProductQuantity(params: {
|
|
172
188
|
id: string;
|
|
173
189
|
quantity: number;
|
|
@@ -301,6 +317,7 @@ export function useCartFunction(): UseCartReturn {
|
|
|
301
317
|
count,
|
|
302
318
|
refreshCart,
|
|
303
319
|
removeItem,
|
|
320
|
+
removeItemById,
|
|
304
321
|
totalPrice,
|
|
305
322
|
shippingTotal,
|
|
306
323
|
subtotal,
|
|
@@ -49,7 +49,7 @@ export function useCustomerOrders(): UseCustomerOrdersReturn {
|
|
|
49
49
|
|
|
50
50
|
const totalOrderItemsCount: Ref<number> = ref(0);
|
|
51
51
|
|
|
52
|
-
const currentParams = ref<
|
|
52
|
+
const currentParams = ref<operations["readOrder post /order"]["body"]>({});
|
|
53
53
|
|
|
54
54
|
const loadOrders = async (
|
|
55
55
|
parameters: operations["readOrder post /order"]["body"] = {},
|
|
@@ -8,31 +8,29 @@ describe("useDefaultOrderAssociations", () => {
|
|
|
8
8
|
|
|
9
9
|
expect(vm).toMatchInlineSnapshot(`
|
|
10
10
|
{
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"stateMachineState": {},
|
|
18
|
-
},
|
|
11
|
+
"addresses": {},
|
|
12
|
+
"deliveries": {
|
|
13
|
+
"associations": {
|
|
14
|
+
"shippingMethod": {},
|
|
15
|
+
"shippingOrderAddress": {},
|
|
16
|
+
"stateMachineState": {},
|
|
19
17
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
18
|
+
},
|
|
19
|
+
"lineItems": {
|
|
20
|
+
"associations": {
|
|
21
|
+
"cover": {},
|
|
22
|
+
"downloads": {
|
|
23
|
+
"associations": {
|
|
24
|
+
"media": {},
|
|
27
25
|
},
|
|
28
26
|
},
|
|
29
27
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
28
|
+
},
|
|
29
|
+
"stateMachineState": {},
|
|
30
|
+
"transactions": {
|
|
31
|
+
"associations": {
|
|
32
|
+
"paymentMethod": {},
|
|
33
|
+
"stateMachineState": {},
|
|
36
34
|
},
|
|
37
35
|
},
|
|
38
36
|
}
|
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
import type { Schemas } from "#shopware";
|
|
2
2
|
|
|
3
|
-
export type UseDefaultOrderAssociationsReturn = Schemas["Criteria"] & {
|
|
4
|
-
checkPromotion?: boolean;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
3
|
/**
|
|
8
4
|
* Returns default order associations. You can override this composable in your project.
|
|
9
5
|
* @public
|
|
10
6
|
* @category Order
|
|
11
7
|
*/
|
|
12
|
-
export function useDefaultOrderAssociations():
|
|
13
|
-
const orderAssociations
|
|
14
|
-
{
|
|
8
|
+
export function useDefaultOrderAssociations(): Schemas["Criteria"]["associations"] {
|
|
9
|
+
const orderAssociations = {
|
|
10
|
+
stateMachineState: {},
|
|
11
|
+
lineItems: {
|
|
15
12
|
associations: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
associations: {
|
|
19
|
-
cover: {},
|
|
20
|
-
downloads: {
|
|
21
|
-
associations: {
|
|
22
|
-
media: {},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
addresses: {},
|
|
28
|
-
deliveries: {
|
|
29
|
-
associations: {
|
|
30
|
-
shippingMethod: {},
|
|
31
|
-
shippingOrderAddress: {},
|
|
32
|
-
stateMachineState: {},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
transactions: {
|
|
13
|
+
cover: {},
|
|
14
|
+
downloads: {
|
|
36
15
|
associations: {
|
|
37
|
-
|
|
38
|
-
stateMachineState: {},
|
|
16
|
+
media: {},
|
|
39
17
|
},
|
|
40
18
|
},
|
|
41
19
|
},
|
|
42
|
-
}
|
|
20
|
+
},
|
|
21
|
+
addresses: {},
|
|
22
|
+
deliveries: {
|
|
23
|
+
associations: {
|
|
24
|
+
shippingMethod: {},
|
|
25
|
+
shippingOrderAddress: {},
|
|
26
|
+
stateMachineState: {},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
transactions: {
|
|
30
|
+
associations: {
|
|
31
|
+
paymentMethod: {},
|
|
32
|
+
stateMachineState: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
43
36
|
|
|
44
37
|
return orderAssociations;
|
|
45
38
|
}
|
|
@@ -23,7 +23,7 @@ describe("useLandingSearch", () => {
|
|
|
23
23
|
expect.stringContaining("readLandingPage"),
|
|
24
24
|
expect.objectContaining({
|
|
25
25
|
pathParams: { landingPageId: "test" },
|
|
26
|
-
body: { associations: cmsAssociations },
|
|
26
|
+
body: { associations: cmsAssociations.associations },
|
|
27
27
|
}),
|
|
28
28
|
);
|
|
29
29
|
});
|
|
@@ -37,7 +37,7 @@ export function useLandingSearch(): {
|
|
|
37
37
|
},
|
|
38
38
|
) => {
|
|
39
39
|
const associations: operations["readLandingPage post /landing-page/{landingPageId}"]["body"]["associations"] =
|
|
40
|
-
options?.withCmsAssociations ? cmsAssociations : {};
|
|
40
|
+
options?.withCmsAssociations ? cmsAssociations.associations : {};
|
|
41
41
|
const result = await apiClient.invoke(
|
|
42
42
|
"readLandingPage post /landing-page/{landingPageId}",
|
|
43
43
|
{
|
|
@@ -246,4 +246,77 @@ describe("useListing", () => {
|
|
|
246
246
|
);
|
|
247
247
|
expect(vm.getAvailableFilters).toEqual([]);
|
|
248
248
|
});
|
|
249
|
+
|
|
250
|
+
it("should accept initialListing parameter", async () => {
|
|
251
|
+
const mockListing = {
|
|
252
|
+
apiAlias: "product_listing",
|
|
253
|
+
elements: [
|
|
254
|
+
{
|
|
255
|
+
id: "product-1",
|
|
256
|
+
name: "Test Product",
|
|
257
|
+
} as Schemas["Product"],
|
|
258
|
+
],
|
|
259
|
+
page: 1,
|
|
260
|
+
limit: 10,
|
|
261
|
+
total: 25,
|
|
262
|
+
} as Schemas["ProductListingResult"];
|
|
263
|
+
|
|
264
|
+
const { vm } = await useSetup(() =>
|
|
265
|
+
useListing({
|
|
266
|
+
listingType: "productSearchListing",
|
|
267
|
+
initialListing: mockListing,
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
expect(vm.getInitialListing).toEqual(mockListing);
|
|
272
|
+
expect(vm.getCurrentListing).toEqual(mockListing);
|
|
273
|
+
expect(vm.getElements).toEqual(mockListing.elements);
|
|
274
|
+
expect(vm.getTotal).toBe(25);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("should handle null initialListing parameter", async () => {
|
|
278
|
+
const { vm } = await useSetup(() =>
|
|
279
|
+
useListing({
|
|
280
|
+
listingType: "productSearchListing",
|
|
281
|
+
initialListing: null,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
expect(vm.getInitialListing).toBeNull();
|
|
286
|
+
expect(vm.getCurrentListing).toBeNull();
|
|
287
|
+
expect(vm.getElements).toEqual([]);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should work without initialListing parameter (backward compatibility)", async () => {
|
|
291
|
+
const { vm } = await useSetup(() =>
|
|
292
|
+
useListing({
|
|
293
|
+
listingType: "productSearchListing",
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
expect(vm.getInitialListing).toBeNull();
|
|
298
|
+
expect(vm.getCurrentListing).toBeNull();
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("should initialize category listing with initialListing", async () => {
|
|
302
|
+
const mockListing = {
|
|
303
|
+
apiAlias: "product_listing",
|
|
304
|
+
elements: [{ id: "product-1" } as Schemas["Product"]],
|
|
305
|
+
page: 1,
|
|
306
|
+
limit: 10,
|
|
307
|
+
total: 1,
|
|
308
|
+
} as Schemas["ProductListingResult"];
|
|
309
|
+
|
|
310
|
+
const { vm } = await useSetup(() =>
|
|
311
|
+
useListing({
|
|
312
|
+
listingType: "categoryListing",
|
|
313
|
+
categoryId: "test-category",
|
|
314
|
+
initialListing: mockListing,
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
expect(vm.getInitialListing).toEqual(mockListing);
|
|
319
|
+
expect(vm.getElements).toHaveLength(1);
|
|
320
|
+
expect(vm.getTotal).toBe(1);
|
|
321
|
+
});
|
|
249
322
|
});
|
|
@@ -183,6 +183,7 @@ export function useListing(params?: {
|
|
|
183
183
|
listingType: ListingType;
|
|
184
184
|
categoryId?: string;
|
|
185
185
|
defaultSearchCriteria?: operations["searchPage post /search"]["body"];
|
|
186
|
+
initialListing?: Schemas["ProductListingResult"] | null;
|
|
186
187
|
}): UseListingReturn {
|
|
187
188
|
const listingType = params?.listingType || "categoryListing";
|
|
188
189
|
let categoryId = params?.categoryId || null;
|
|
@@ -241,13 +242,17 @@ export function useListing(params?: {
|
|
|
241
242
|
searchDefaults:
|
|
242
243
|
params?.defaultSearchCriteria ||
|
|
243
244
|
({} as operations["searchPage post /search"]["body"]), //getDefaults(),
|
|
245
|
+
initialListing: params?.initialListing,
|
|
244
246
|
});
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
const [_createCategoryListingContext, _categoryListingContext] =
|
|
248
250
|
createInjectionState(
|
|
249
|
-
() => {
|
|
250
|
-
return useListing({
|
|
251
|
+
(initialListing?: Schemas["ProductListingResult"] | null) => {
|
|
252
|
+
return useListing({
|
|
253
|
+
listingType: "categoryListing",
|
|
254
|
+
initialListing,
|
|
255
|
+
});
|
|
251
256
|
},
|
|
252
257
|
{
|
|
253
258
|
injectionKey: "categoryListing",
|
|
@@ -292,6 +297,7 @@ export function createListingComposable({
|
|
|
292
297
|
searchMethod,
|
|
293
298
|
searchDefaults,
|
|
294
299
|
listingKey,
|
|
300
|
+
initialListing,
|
|
295
301
|
}: {
|
|
296
302
|
searchMethod(
|
|
297
303
|
searchParams:
|
|
@@ -300,6 +306,7 @@ export function createListingComposable({
|
|
|
300
306
|
): Promise<Schemas["ProductListingResult"]>;
|
|
301
307
|
searchDefaults: operations["searchPage post /search"]["body"];
|
|
302
308
|
listingKey: string;
|
|
309
|
+
initialListing?: Schemas["ProductListingResult"] | null;
|
|
303
310
|
}): UseListingReturn {
|
|
304
311
|
// const COMPOSABLE_NAME = "createListingComposable";
|
|
305
312
|
// const contextName = COMPOSABLE_NAME;
|
|
@@ -319,7 +326,7 @@ export function createListingComposable({
|
|
|
319
326
|
// const { sharedRef } = useSharedState();
|
|
320
327
|
const _storeInitialListing = inject<
|
|
321
328
|
Ref<Schemas["ProductListingResult"] | null>
|
|
322
|
-
>(`useListingInitial-${listingKey}`, ref(null));
|
|
329
|
+
>(`useListingInitial-${listingKey}`, ref(initialListing ?? null));
|
|
323
330
|
provide(`useListingInitial-${listingKey}`, _storeInitialListing);
|
|
324
331
|
// const _storeInitialListing = sharedRef<Schemas["ProductListingResult"]>(
|
|
325
332
|
// `${cacheKey}-initialListing-${listingKey}`
|
|
@@ -37,6 +37,14 @@ export type UseNewsletterReturn = {
|
|
|
37
37
|
* Inform about newsletter confirmation
|
|
38
38
|
*/
|
|
39
39
|
confirmationNeeded: ComputedRef<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe key
|
|
42
|
+
*/
|
|
43
|
+
SUBSRIBE_KEY: string;
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe key
|
|
46
|
+
*/
|
|
47
|
+
UNSUBSCRIBE_KEY: string;
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
/**
|
|
@@ -45,6 +53,9 @@ export type UseNewsletterReturn = {
|
|
|
45
53
|
* @category Customer & Account
|
|
46
54
|
*/
|
|
47
55
|
export function useNewsletter(): UseNewsletterReturn {
|
|
56
|
+
const SUBSRIBE_KEY = "subscribe";
|
|
57
|
+
const UNSUBSCRIBE_KEY = "unsubscribe";
|
|
58
|
+
|
|
48
59
|
const { apiClient } = useShopwareContext();
|
|
49
60
|
const { getStorefrontUrl } = useInternationalization();
|
|
50
61
|
const newsletterStatus =
|
|
@@ -105,5 +116,7 @@ export function useNewsletter(): UseNewsletterReturn {
|
|
|
105
116
|
getNewsletterStatus,
|
|
106
117
|
newsletterStatus,
|
|
107
118
|
confirmationNeeded,
|
|
119
|
+
SUBSRIBE_KEY,
|
|
120
|
+
UNSUBSCRIBE_KEY,
|
|
108
121
|
};
|
|
109
122
|
}
|
|
@@ -2,7 +2,7 @@ import { defu } from "defu";
|
|
|
2
2
|
import { computed, inject, provide, ref } from "vue";
|
|
3
3
|
import type { ComputedRef, Ref } from "vue";
|
|
4
4
|
import { useDefaultOrderAssociations, useShopwareContext } from "#imports";
|
|
5
|
-
import type { Schemas } from "#shopware";
|
|
5
|
+
import type { Schemas, operations } from "#shopware";
|
|
6
6
|
|
|
7
7
|
export type UseOrderDetailsReturn = {
|
|
8
8
|
/**
|
|
@@ -182,17 +182,11 @@ export function useOrderDetails(
|
|
|
182
182
|
orderAssociations,
|
|
183
183
|
associations ? associations : {},
|
|
184
184
|
);
|
|
185
|
-
const params = {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
type: "equals",
|
|
189
|
-
field: "id",
|
|
190
|
-
value: orderId,
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
associations: mergedAssociations.associations,
|
|
185
|
+
const params: operations["readOrder post /order"]["body"] = {
|
|
186
|
+
ids: [orderId],
|
|
187
|
+
associations: mergedAssociations,
|
|
194
188
|
checkPromotion: true,
|
|
195
|
-
}
|
|
189
|
+
};
|
|
196
190
|
|
|
197
191
|
const orderDetailsResponse = await apiClient.invoke(
|
|
198
192
|
"readOrder post /order",
|
|
@@ -64,6 +64,7 @@ export function useOrderPayment(
|
|
|
64
64
|
const state = computed(() => activeTransaction.value?.stateMachineState);
|
|
65
65
|
const isAsynchronous = computed(
|
|
66
66
|
() =>
|
|
67
|
+
// @ts-expect-error TODO: [MAJOR] Removed since 6.7
|
|
67
68
|
activeTransaction.value?.paymentMethod?.asynchronous &&
|
|
68
69
|
activeTransaction.value?.paymentMethod?.afterOrderEnabled,
|
|
69
70
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComputedRef } from "vue";
|
|
3
3
|
import { useLocalWishlist, useSyncWishlist, useUser } from "#imports";
|
|
4
4
|
|
|
5
5
|
export type UseProductWishlistReturn = {
|
|
@@ -14,7 +14,7 @@ export type UseProductWishlistReturn = {
|
|
|
14
14
|
/**
|
|
15
15
|
* Indicates whether a product is in wishlist
|
|
16
16
|
*/
|
|
17
|
-
isInWishlist:
|
|
17
|
+
isInWishlist: ComputedRef<boolean>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|