@scayle/storefront-product-listing 0.3.0 → 0.4.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.
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { type ProductSortConfig } from '@scayle/storefront-nuxt';
|
|
2
2
|
import { type ComputedRef } from 'vue';
|
|
3
|
-
import type { RouteLocationNormalizedLoadedGeneric } from 'vue-router';
|
|
3
|
+
import type { RouteLocationNormalizedLoadedGeneric, RouteLocationRaw } from 'vue-router';
|
|
4
4
|
type SelectedSort = ProductSortConfig & {
|
|
5
5
|
key: string;
|
|
6
6
|
label: string;
|
|
7
7
|
};
|
|
8
|
+
type SortLink = SelectedSort & {
|
|
9
|
+
to: RouteLocationRaw;
|
|
10
|
+
};
|
|
8
11
|
export interface UseProductListSortReturn {
|
|
9
12
|
selectedSort: ComputedRef<SelectedSort | undefined>;
|
|
10
|
-
sortLinks: ComputedRef<
|
|
13
|
+
sortLinks: ComputedRef<SortLink[]>;
|
|
11
14
|
isDefaultSortSelected: ComputedRef<boolean>;
|
|
12
15
|
}
|
|
13
16
|
export interface ProductListSortOptions {
|
|
@@ -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({
|
|
@@ -57,7 +51,7 @@ export function useProductsByCategory(categoryId, route, {
|
|
|
57
51
|
return productsData.data.value?.pagination;
|
|
58
52
|
});
|
|
59
53
|
const totalProductsCount = computed(() => {
|
|
60
|
-
return productsData.data.value?.pagination
|
|
54
|
+
return productsData.data.value?.pagination?.total ?? 0;
|
|
61
55
|
});
|
|
62
56
|
const paginationOffset = computed(() => {
|
|
63
57
|
const page = pagination.value?.page ?? 1;
|
package/package.json
CHANGED