/
categoryMerchandising.ts
61 lines (56 loc) · 1.42 KB
/
categoryMerchandising.ts
1
2
3
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { KlevuFetchFunctionReturnValue } from "../index.js"
import { KlevuFetchModifer } from "../../index.js"
import { KlevuBaseQuery } from "../../models/KlevuBaseQuery.js"
import { KlevuBaseQuerySettingsQuery } from "../../models/KlevuBaseQuerySettingsQuery.js"
import {
KlevuBaseQuerySettings,
KlevuTypeOfRequest,
} from "../../models/index.js"
export type KlevuMerchandisingOptions = {
id: string
searchTerm: string
} & Omit<KlevuBaseQuerySettings, "query">
const defaults: KlevuMerchandisingOptions = {
id: "categoryMerchandising",
searchTerm: "*",
limit: 24,
}
/**
* Fetch products for a category listing page.
* Default result id is "categoryMerchandising".
*
* @category Query
* @param category
* @param options
* @returns
*/
export function categoryMerchandising(
category: KlevuBaseQuerySettingsQuery["categoryPath"],
options?: Partial<KlevuMerchandisingOptions>,
...modifiers: KlevuFetchModifer[]
): KlevuFetchFunctionReturnValue {
const params: KlevuMerchandisingOptions = {
...defaults,
...options,
}
const query: KlevuBaseQuery = {
id: params.id,
typeOfRequest: KlevuTypeOfRequest.CategoryNavigation,
settings: {
query: {
categoryPath: category,
term: params.searchTerm,
},
...params,
},
}
return {
klevuFunctionId: "categoryMerchandising",
queries: [query],
modifiers,
params: {
...params,
category,
},
}
}