@scayle/storefront-product-listing 1.6.3 → 1.8.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/CHANGELOG.md +13 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/composables/useAppliedFilters.js +3 -0
- package/dist/runtime/composables/useProductListSort.d.ts +33 -1
- package/dist/runtime/composables/useProductListSort.js +39 -37
- package/dist/runtime/utils/filters.d.ts +10 -0
- package/dist/runtime/utils/filters.js +25 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scayle/storefront-product-listing
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Enhanced `useAppliedFilters` to support the `minReduction` and `maxReduction` filter names, enabling proper handling of the `max_savings_percentage` filter.
|
|
8
|
+
|
|
9
|
+
## 1.7.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Export `defaultSortingOptions` and `DEFAULT_SORTING_KEY` from the `useProductListSort` composable.
|
|
14
|
+
This change enhances consumer flexibility, allowing for more granular adjustments to custom sorting options.
|
|
15
|
+
|
|
3
16
|
## 1.6.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const PACKAGE_NAME = "@scayle/storefront-product-listing";
|
|
4
|
-
const PACKAGE_VERSION = "1.
|
|
4
|
+
const PACKAGE_VERSION = "1.8.0";
|
|
5
5
|
const module = defineNuxtModule({
|
|
6
6
|
meta: {
|
|
7
7
|
name: PACKAGE_NAME,
|
|
@@ -10,6 +10,9 @@ export function useAppliedFilters(route, { filtersPrefix } = { filtersPrefix: "f
|
|
|
10
10
|
if (appliedFilter.value.minPrice !== void 0 || appliedFilter.value.maxPrice !== void 0) {
|
|
11
11
|
count += 1;
|
|
12
12
|
}
|
|
13
|
+
if (appliedFilter.value.minReduction !== void 0 || appliedFilter.value.maxReduction !== void 0) {
|
|
14
|
+
count += 1;
|
|
15
|
+
}
|
|
13
16
|
return count;
|
|
14
17
|
});
|
|
15
18
|
const appliedAttributeValues = computed(
|
|
@@ -20,6 +20,38 @@ export interface ProductListSortOptions {
|
|
|
20
20
|
sortingOptions?: SelectedSort[];
|
|
21
21
|
defaultSortingKey?: string;
|
|
22
22
|
}
|
|
23
|
+
export declare const defaultSortingOptions: ({
|
|
24
|
+
key: string;
|
|
25
|
+
sortingKey: string;
|
|
26
|
+
direction: "desc";
|
|
27
|
+
label: string;
|
|
28
|
+
by?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
key: string;
|
|
31
|
+
by: "new";
|
|
32
|
+
direction: "desc";
|
|
33
|
+
label: string;
|
|
34
|
+
sortingKey?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
key: string;
|
|
37
|
+
by: "price";
|
|
38
|
+
direction: "desc";
|
|
39
|
+
label: string;
|
|
40
|
+
sortingKey?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
key: string;
|
|
43
|
+
by: "price";
|
|
44
|
+
direction: "asc";
|
|
45
|
+
label: string;
|
|
46
|
+
sortingKey?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
key: string;
|
|
49
|
+
by: "reduction";
|
|
50
|
+
direction: "desc";
|
|
51
|
+
label: string;
|
|
52
|
+
sortingKey?: undefined;
|
|
53
|
+
})[];
|
|
54
|
+
export declare const DEFAULT_SORTING_KEY = "top_seller";
|
|
23
55
|
/**
|
|
24
56
|
* Custom composable to handle product list sorting.
|
|
25
57
|
*
|
|
@@ -30,5 +62,5 @@ export interface ProductListSortOptions {
|
|
|
30
62
|
*
|
|
31
63
|
* @returns Computed properties and methods related to sorting
|
|
32
64
|
*/
|
|
33
|
-
export declare function useProductListSort(route: RouteLocationNormalizedLoadedGeneric, { sortingOptions, defaultSortingKey }?: ProductListSortOptions): UseProductListSortReturn;
|
|
65
|
+
export declare function useProductListSort(route: RouteLocationNormalizedLoadedGeneric, { sortingOptions, defaultSortingKey, }?: ProductListSortOptions): UseProductListSortReturn;
|
|
34
66
|
export {};
|
|
@@ -1,44 +1,46 @@
|
|
|
1
1
|
import { APISortOption, APISortOrder } from "@scayle/storefront-nuxt";
|
|
2
2
|
import { computed } from "vue";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
export const defaultSortingOptions = [
|
|
4
|
+
{
|
|
5
|
+
key: "top_seller",
|
|
6
|
+
sortingKey: "scayle:v1:recommended",
|
|
7
|
+
direction: APISortOrder.DESCENDING,
|
|
8
|
+
label: "sorting_select.top_seller"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
key: "date_newest",
|
|
12
|
+
by: APISortOption.DATE_ADDED,
|
|
13
|
+
direction: APISortOrder.DESCENDING,
|
|
14
|
+
label: "sorting_select.date_newest"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "price_desc",
|
|
18
|
+
by: APISortOption.PRICE,
|
|
19
|
+
direction: APISortOrder.DESCENDING,
|
|
20
|
+
label: "sorting_select.price_desc"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "price_asc",
|
|
24
|
+
by: APISortOption.PRICE,
|
|
25
|
+
direction: APISortOrder.ASCENDING,
|
|
26
|
+
label: "sorting_select.price_asc"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "reduction_desc",
|
|
30
|
+
by: APISortOption.REDUCTION,
|
|
31
|
+
direction: APISortOrder.DESCENDING,
|
|
32
|
+
label: "sorting_select.reduction_desc"
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
export const DEFAULT_SORTING_KEY = "top_seller";
|
|
36
|
+
export function useProductListSort(route, {
|
|
37
|
+
sortingOptions = defaultSortingOptions,
|
|
38
|
+
defaultSortingKey = DEFAULT_SORTING_KEY
|
|
39
|
+
} = {}) {
|
|
38
40
|
const selectedSort = computed(() => {
|
|
39
|
-
const sort =
|
|
41
|
+
const sort = sortingOptions.find(({ key }) => key === route.query.sort);
|
|
40
42
|
if (!sort) {
|
|
41
|
-
return sortingOptions?.find((
|
|
43
|
+
return sortingOptions?.find(({ key }) => key === defaultSortingKey);
|
|
42
44
|
}
|
|
43
45
|
return sort;
|
|
44
46
|
});
|
|
@@ -35,6 +35,16 @@ export declare const createNewAttributeQuery: (route: RouteLocationNormalizedLoa
|
|
|
35
35
|
* @returns {LocationQuery} A new query object with the updated price filter.
|
|
36
36
|
*/
|
|
37
37
|
export declare const createNewPriceQuery: (route: RouteLocationNormalizedLoadedGeneric, appliedFilter: ProductSearchQuery, prices: RangeTuple) => LocationQuery;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new reduction filter query object.
|
|
40
|
+
*
|
|
41
|
+
* @param route - The Vue Router route object.
|
|
42
|
+
* @param appliedFilter - The currently applied filter.
|
|
43
|
+
* @param reductions - The new reduction range.
|
|
44
|
+
*
|
|
45
|
+
* @returns A new query object with the updated reduction filter.
|
|
46
|
+
*/
|
|
47
|
+
export declare const createNewReductionQuery: (route: RouteLocationNormalizedLoadedGeneric, appliedFilter: ProductSearchQuery, reductions: RangeTuple) => LocationQuery;
|
|
38
48
|
/**
|
|
39
49
|
* Creates a new boolean attribute filter query object.
|
|
40
50
|
*
|
|
@@ -16,6 +16,8 @@ export const parseFilterDataFromRoute = (route, filtersPrefix) => {
|
|
|
16
16
|
switch (filterName) {
|
|
17
17
|
case "minPrice":
|
|
18
18
|
case "maxPrice":
|
|
19
|
+
case "minReduction":
|
|
20
|
+
case "maxReduction":
|
|
19
21
|
if (isNaN(Number(value))) {
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
@@ -85,6 +87,16 @@ export const createNewPriceQuery = (route, appliedFilter, prices) => {
|
|
|
85
87
|
}
|
|
86
88
|
return { ...query, ...priceFilterQuery };
|
|
87
89
|
};
|
|
90
|
+
export const createNewReductionQuery = (route, appliedFilter, reductions) => {
|
|
91
|
+
const priceFilterQuery = {};
|
|
92
|
+
if (appliedFilter.minReduction !== reductions[0]) {
|
|
93
|
+
priceFilterQuery["filters[minReduction]"] = reductions[0].toString();
|
|
94
|
+
}
|
|
95
|
+
if (appliedFilter.maxReduction !== reductions[1]) {
|
|
96
|
+
priceFilterQuery["filters[maxReduction]"] = reductions[1].toString();
|
|
97
|
+
}
|
|
98
|
+
return { ...route.query, ...priceFilterQuery };
|
|
99
|
+
};
|
|
88
100
|
export const createNewBoolAttributeQuery = (route, appliedFilter, { slug, value }) => {
|
|
89
101
|
const booleanFilterQuery = {};
|
|
90
102
|
const query = { ...route.query };
|
|
@@ -114,10 +126,23 @@ const getClearedPriceQuery = (route) => {
|
|
|
114
126
|
}
|
|
115
127
|
return query;
|
|
116
128
|
};
|
|
129
|
+
const getClearedReductionQuery = (route) => {
|
|
130
|
+
const query = { ...route.query };
|
|
131
|
+
if (query["filters[maxReduction]"]) {
|
|
132
|
+
delete query["filters[maxReduction]"];
|
|
133
|
+
}
|
|
134
|
+
if (query["filters[minReduction]"]) {
|
|
135
|
+
delete query["filters[minReduction]"];
|
|
136
|
+
}
|
|
137
|
+
return query;
|
|
138
|
+
};
|
|
117
139
|
export const getClearedFilterQueryByKey = (route, key) => {
|
|
118
140
|
if (key === "prices") {
|
|
119
141
|
return getClearedPriceQuery(route);
|
|
120
142
|
}
|
|
143
|
+
if (key === "reductions") {
|
|
144
|
+
return getClearedReductionQuery(route);
|
|
145
|
+
}
|
|
121
146
|
const query = { ...route.query };
|
|
122
147
|
const filterKey = `filters[${key}]`;
|
|
123
148
|
if (query[filterKey]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-product-listing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Collection of essential composables and utilities to work with product listing",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,16 +64,16 @@
|
|
|
64
64
|
"@nuxt/module-builder": "1.0.1",
|
|
65
65
|
"@nuxt/schema": "3.16.2",
|
|
66
66
|
"@nuxt/test-utils": "3.18.0",
|
|
67
|
-
"@scayle/eslint-config-storefront": "4.5.
|
|
68
|
-
"@scayle/storefront-api": "18.
|
|
69
|
-
"@scayle/storefront-nuxt": "8.
|
|
70
|
-
"@types/node": "22.15.
|
|
71
|
-
"@vitest/coverage-v8": "3.2.
|
|
67
|
+
"@scayle/eslint-config-storefront": "4.5.7",
|
|
68
|
+
"@scayle/storefront-api": "18.9.0",
|
|
69
|
+
"@scayle/storefront-nuxt": "8.30.1",
|
|
70
|
+
"@types/node": "22.15.32",
|
|
71
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
72
72
|
"@vue/test-utils": "2.4.6",
|
|
73
73
|
"@vueuse/core": "13.3.0",
|
|
74
74
|
"dprint": "0.50.0",
|
|
75
75
|
"eslint-formatter-gitlab": "6.0.1",
|
|
76
|
-
"eslint": "9.
|
|
76
|
+
"eslint": "9.29.0",
|
|
77
77
|
"fishery": "2.3.1",
|
|
78
78
|
"happy-dom": "18.0.1",
|
|
79
79
|
"nuxt": "3.16.2",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"schema-dts": "1.1.5",
|
|
82
82
|
"typescript": "5.8.3",
|
|
83
83
|
"unbuild": "3.5.0",
|
|
84
|
-
"vitest": "3.2.
|
|
84
|
+
"vitest": "3.2.4",
|
|
85
85
|
"vue-router": "4.5.1",
|
|
86
86
|
"vue-tsc": "2.2.10",
|
|
87
87
|
"vue": "3.5.16"
|