Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions vtex/loaders/intelligentSearch/productListingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ export interface Props {
* @title Include price in facets
*/
priceFacets?: boolean;
/**
* @title Additional Search Parameters
* @description Extra query params to pass to VTEX Intelligent Search API (e.g., for VTEX Ads).
* Use key: "showSponsored", value: "true" and key: "placement", value: "top-search" for VTEX Ads.
*/
additionalSearchParams?: {
key: string;
value: string;
}[];
/**
* @title Advanced Configuration
* @description Further change loader behaviour
Expand Down Expand Up @@ -307,17 +316,26 @@ const loader = async (
ctx.defaultSegment?.cultureInfo ?? "pt-BR";

const params = withDefaultParams({ ...searchArgs, page, locale });

// Build additional search params object from array
const additionalParams: Record<string, string> = {};
props.additionalSearchParams?.forEach((param) => {
additionalParams[param.key] = param.value;
});

// search products on VTEX. Feel free to change any of these parameters
const [productsResult, facetsResult] = await Promise.all([
vcsDeprecated
["GET /api/io/_v/api/intelligent-search/product_search/*facets"]({
...additionalParams,
...params,
facets: toPath(selected),
}, {
...STALE,
headers: segment ? withSegmentCookie(segment) : undefined,
}).then((res) => res.json()),
vcsDeprecated["GET /api/io/_v/api/intelligent-search/facets/*facets"]({
...additionalParams,
...params,
facets: toPath(fselected),
}, { ...STALE, headers: segment ? withSegmentCookie(segment) : undefined })
Expand Down Expand Up @@ -462,6 +480,12 @@ export const cacheKey = (props: Props, req: Request, ctx: AppContext) => {
url.searchParams.get("simulationBehavior") || props.simulationBehavior ||
"default",
],
[
"additionalSearchParams",
(props.additionalSearchParams ?? [])
.map((p) => `${p.key}:${p.value}`)
.join("\\"),
],
]);
url.searchParams.forEach((value, key) => {
if (!ALLOWED_PARAMS.has(key.toLowerCase()) && !isFilterParam(key)) {
Expand Down
Loading