Skip to content

Commit

Permalink
Don't break because VTEX does - page above 50 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucis committed Jul 2, 2023
1 parent ed29762 commit 042da01
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packs/vtex/loaders/intelligentSearch/productListingPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ import type { Context } from "deco-sites/std/packs/vtex/accounts/vtex.ts";
/** this type is more friendly user to fuzzy type that is 0, 1 or auto. */
export type LabelledFuzzy = "automatic" | "disabled" | "enabled";

/**
* VTEX Intelligent Search doesn't support pagination above 50 pages.
*
* We're now showing results for the last page so the page doesn't crash
*/
const VTEX_MAX_PAGES = 50;

const sortOptions = [
{ value: "", label: "relevance:desc" },
{ value: "price:desc", label: "price:desc" },
Expand Down Expand Up @@ -135,9 +142,12 @@ const searchArgsOf = (props: Props, url: URL) => {
const count = props.count ?? 12;
const query = props.query ?? url.searchParams.get("q") ?? "";
const currentPageoffset = props.pageOffset ?? 1;
const page = url.searchParams.get("page")
? Number(url.searchParams.get("page")) - (currentPageoffset)
: 0;
const page = Math.min(
url.searchParams.get("page")
? Number(url.searchParams.get("page")) - (currentPageoffset)
: 0,
VTEX_MAX_PAGES - currentPageoffset,
);
const sort = url.searchParams.get("sort") as Sort ??
LEGACY_TO_IS[url.searchParams.get("O") ?? ""] ?? props.sort ??
sortOptions[0].value;
Expand Down

0 comments on commit 042da01

Please sign in to comment.