@klevu/core
Version:
Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.
48 lines (47 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.alsoViewed = void 0;
const index_js_1 = require("../../index.js");
const lastClickedProducts_js_1 = require("../../store/lastClickedProducts.js");
const defaultOptions = {
limit: 5,
lastClickedProductIds: [],
};
/**
* Shows products that visitor should also see. Automatically applies products that user has already clicked.
*
* @category RecommendationQuery
* @param {Options} options Allows to override limit of products to return or pass custom lastClickedProductIds
* @returns
*/
function alsoViewed(options, ...modifiers) {
const params = Object.assign(Object.assign({}, defaultOptions), options);
const lastProducts = params.lastClickedProductIds && params.lastClickedProductIds.length > 0
? params.lastClickedProductIds
: lastClickedProducts_js_1.KlevuLastClickedProducts.getLastClickedLatestsFirst();
return {
klevuFunctionId: "recommendation",
modifiers,
queries: [
{
id: "alsoviewed",
typeOfRequest: index_js_1.KlevuTypeOfRequest.AlsoViewed,
settings: {
limit: params.limit,
context: {
recentObjects: [
{
typeOfRecord: index_js_1.KlevuTypeOfRecord.Product,
records: lastProducts.map((id) => ({
id,
})),
},
],
},
typeOfRecords: [index_js_1.KlevuTypeOfRecord.Product],
},
},
],
};
}
exports.alsoViewed = alsoViewed;