@scayle/storefront-product-listing 0.4.0 → 0.4.2
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.
|
@@ -10,14 +10,14 @@ export type UseProductsByCategoryReturn = Pick<Awaited<ReturnType<typeof useProd
|
|
|
10
10
|
paginationOffset: ComputedRef<number>;
|
|
11
11
|
};
|
|
12
12
|
export interface ProductsByCategoryOptions {
|
|
13
|
-
params
|
|
14
|
-
fetchingOptions
|
|
13
|
+
params?: Omit<Partial<FetchProductsByCategoryParams>, 'category' | 'categoryId'>;
|
|
14
|
+
fetchingOptions?: Partial<{
|
|
15
15
|
lazy: boolean;
|
|
16
16
|
immediate: boolean;
|
|
17
17
|
}>;
|
|
18
|
-
productsPerPage
|
|
19
|
-
fetchProductsCacheTtl
|
|
20
|
-
cacheKeyPrefix
|
|
18
|
+
productsPerPage?: number;
|
|
19
|
+
fetchProductsCacheTtl?: number;
|
|
20
|
+
cacheKeyPrefix?: string;
|
|
21
21
|
fetchingKey?: string;
|
|
22
22
|
withParams?: ProductWith;
|
|
23
23
|
}
|
|
@@ -9,24 +9,18 @@ const PRODUCTS_PER_PAGE = 24;
|
|
|
9
9
|
const DEFAULT_CACHE_TTL = 1e3;
|
|
10
10
|
const DEFAULT_CACHE_KEY_PREFIX = "PLP";
|
|
11
11
|
export function useProductsByCategory(categoryId, route, {
|
|
12
|
-
params
|
|
13
|
-
withParams,
|
|
14
|
-
cacheKeyPrefix,
|
|
15
|
-
fetchingKey,
|
|
16
|
-
fetchingOptions,
|
|
17
|
-
fetchProductsCacheTtl,
|
|
18
|
-
productsPerPage
|
|
19
|
-
} = {
|
|
20
|
-
params: {
|
|
12
|
+
params = {
|
|
21
13
|
includeSoldOut: false,
|
|
22
14
|
includeSellableForFree: false,
|
|
23
15
|
pricePromotionKey: ""
|
|
24
16
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
withParams,
|
|
18
|
+
cacheKeyPrefix = DEFAULT_CACHE_KEY_PREFIX,
|
|
19
|
+
fetchingKey,
|
|
20
|
+
fetchingOptions = {},
|
|
21
|
+
fetchProductsCacheTtl = DEFAULT_CACHE_TTL,
|
|
22
|
+
productsPerPage = PRODUCTS_PER_PAGE
|
|
23
|
+
} = {}) {
|
|
30
24
|
const { selectedSort } = useProductListSort(route);
|
|
31
25
|
const { appliedFilter } = useAppliedFilters(route);
|
|
32
26
|
const productsData = useProducts({
|
|
@@ -45,6 +39,11 @@ export function useProductsByCategory(categoryId, route, {
|
|
|
45
39
|
cacheKeyPrefix: cacheKeyPrefix || `PLP:${toValue(categoryId)}`
|
|
46
40
|
},
|
|
47
41
|
where: appliedFilter.value,
|
|
42
|
+
// NOTE: We don't want to include trackSearchAnalyticsEvent parameter when paginating,
|
|
43
|
+
// as this logs the search term on every page request.
|
|
44
|
+
// Instead, we log the term only once, when the search is first performed.
|
|
45
|
+
// See: https://scayle.dev/en/developer-guide/products/search#scayle-search-analytics
|
|
46
|
+
trackSearchAnalyticsEvent: !!(params?.page === 1 && appliedFilter.value.term),
|
|
48
47
|
...params
|
|
49
48
|
}),
|
|
50
49
|
key: fetchingKey || `${toValue(categoryId)}-products`,
|
|
@@ -57,7 +56,7 @@ export function useProductsByCategory(categoryId, route, {
|
|
|
57
56
|
return productsData.data.value?.pagination;
|
|
58
57
|
});
|
|
59
58
|
const totalProductsCount = computed(() => {
|
|
60
|
-
return productsData.data.value?.pagination
|
|
59
|
+
return productsData.data.value?.pagination?.total ?? 0;
|
|
61
60
|
});
|
|
62
61
|
const paginationOffset = computed(() => {
|
|
63
62
|
const page = pagination.value?.page ?? 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-product-listing",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Collection of essential composables and utilities to work with product listing",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
"@nuxt/schema": "3.13.2",
|
|
58
58
|
"@nuxt/test-utils": "3.14.4",
|
|
59
59
|
"@scayle/eslint-config-storefront": "4.3.2",
|
|
60
|
-
"@scayle/storefront-nuxt": "7.95.
|
|
61
|
-
"@types/node": "22.9.
|
|
60
|
+
"@scayle/storefront-nuxt": "7.95.1",
|
|
61
|
+
"@types/node": "22.9.1",
|
|
62
62
|
"@vue/test-utils": "2.4.6",
|
|
63
63
|
"@vueuse/core": "11.2.0",
|
|
64
64
|
"dprint": "0.47.5",
|
|
65
|
-
"eslint": "9.
|
|
65
|
+
"eslint": "9.15.0",
|
|
66
66
|
"happy-dom": "15.11.6",
|
|
67
67
|
"eslint-formatter-gitlab": "5.1.0",
|
|
68
68
|
"nuxt": "3.13.2",
|