Skip to content

Conversation

@vitoUwu
Copy link
Contributor

@vitoUwu vitoUwu commented Sep 8, 2025

What is this Contribution About?

Please provide a brief description of the changes or enhancements you are proposing in this pull request.

Issue Link

Please link to the relevant issue that this pull request addresses:

Loom Video

Record a quick screencast describing your changes to help the team understand and review your contribution. This will greatly assist in the review process.

Demonstration Link

Provide a link to a branch or environment where this pull request can be tested and seen in action.

Summary by CodeRabbit

  • New Features
    • Added optional zip code support for search and product listing pages so results can be tailored by location when provided (e.g., via URL).
    • Zip code now applies consistently to product results and facets for improved location-relevant filtering.
    • No behavior change when no zip code is supplied.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Walkthrough

Parses a "zip-code" query parameter in the product listing page loader, threads it through intelligentSearch plumbing as zipCode mapped to "zip-code", and updates VTEX client typings to accept an optional "zip-code" in relevant intelligent-search endpoints.

Changes

Cohort / File(s) Change summary
Loader: parse and forward zip code
vtex/loaders/intelligentSearch/productListingPage.ts
Parses url.searchParams.get("zip-code"), exposes it as zipCode in searchArgsOf, and includes it in the loader's search arguments.
Intelligent search params plumbing
vtex/utils/intelligentSearch.ts
Adds Params.zipCode?: string; withDefaultParams now accepts zipCode and sets "zip-code": zipCode in the returned search params.
VTEX client endpoint typings
vtex/utils/client.ts
Adds optional "zip-code"?: string to searchParams for GET /api/io/_v/api/intelligent-search/product_search/*facets and GET /api/io/_v/api/intelligent-search/facets/*facets.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant PLP Loader as productListingPage loader
  participant IS Utils as withDefaultParams
  participant VTEX API as VTEX intelligent-search

  User->>PLP Loader: Request /plp?...&zip-code=12345
  PLP Loader->>PLP Loader: Parse url.searchParams.get("zip-code")
  PLP Loader->>IS Utils: withDefaultParams({ ..., zipCode: "12345" })
  IS Utils-->>PLP Loader: Params include "zip-code": "12345"
  PLP Loader->>VTEX API: GET product_search/... with "zip-code"=12345
  VTEX API-->>PLP Loader: Results
  PLP Loader-->>User: Rendered PLP
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit tucked in query fur,
Nosed a zip and gave a purr.
Carried it from URL to call,
Hopped through facets, heedless of fall.
Results arrive—one crunchy chew, hooray! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d98cc89 and 5298a99.

📒 Files selected for processing (1)
  • vtex/loaders/intelligentSearch/productListingPage.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • vtex/loaders/intelligentSearch/productListingPage.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/delivery-promise

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2025

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.121.5 update
  • 🎉 for Minor 0.122.0 update
  • 🚀 for Major 1.0.0 update

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
vtex/utils/intelligentSearch.ts (1)

57-78: Avoid sending zip-code=undefined to VTEX

Depending on the request builder, undefined props can leak as "undefined" query values. Add the param only when defined.

Apply:

-export const withDefaultParams = ({
-  query = "",
-  page = 0,
-  count = 12,
-  sort = "",
-  fuzzy = "auto",
-  locale = "pt-BR",
-  hideUnavailableItems,
-  simulationBehavior = "default",
-  zipCode,
-}: Partial<Params>) => ({
-  page: page + 1,
-  count,
-  query,
-  sort,
-  fuzzy,
-  locale,
-  // locale: locale ?? ctx.configVTEX!.defaultLocale,
-  hideUnavailableItems: hideUnavailableItems ?? false,
-  simulationBehavior,
-  "zip-code": zipCode,
-});
+export const withDefaultParams = ({
+  query = "",
+  page = 0,
+  count = 12,
+  sort = "",
+  fuzzy = "auto",
+  locale = "pt-BR",
+  hideUnavailableItems,
+  simulationBehavior = "default",
+  zipCode,
+}: Partial<Params>) => {
+  const base = {
+    page: page + 1,
+    count,
+    query,
+    sort,
+    fuzzy,
+    locale,
+    // locale: locale ?? ctx.configVTEX!.defaultLocale,
+    hideUnavailableItems: hideUnavailableItems ?? false,
+    simulationBehavior,
+  };
+  return zipCode ? { ...base, "zip-code": zipCode } : base;
+};
vtex/loaders/intelligentSearch/productListingPage.ts (1)

81-90: Cache key must vary by zip-code to avoid cross-zip results

cacheKey whitelists query params via ALLOWED_PARAMS, but "zip-code" isn’t included. Results may be cached for one ZIP and served to another. Include it in the allowlist (and thus in the cache key).

Apply:

 const ALLOWED_PARAMS = new Set([
   "ps",
   "sort",
   "page",
   "o",
   "q",
   "fuzzy",
   "map",
+  "zip-code",
 ]);

No other changes needed: the loop over url.searchParams will now append "zip-code" and the cache key will vary accordingly.

Also applies to: 435-473

🧹 Nitpick comments (2)
vtex/loaders/intelligentSearch/productListingPage.ts (2)

184-195: Parse zip code: trim to avoid accidental whitespace

Small hardening: trim the value so stray spaces don’t break matching on the backend or caching.

Apply:

-  const zipCode = url.searchParams.get("zip-code") ?? undefined;
+  const zipCodeRaw = url.searchParams.get("zip-code");
+  const zipCode = zipCodeRaw?.trim() || undefined;

391-397: Preserve zip-code on facet toggle URLs

Filter URLs are built from paramsToPersist. Without "zip-code", users can lose the ZIP when toggling filters.

Apply:

   const paramsToPersist = new URLSearchParams();
   searchArgs.query && paramsToPersist.set("q", searchArgs.query);
   searchArgs.sort && paramsToPersist.set("sort", searchArgs.sort);
+  searchArgs.zipCode && paramsToPersist.set("zip-code", searchArgs.zipCode);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 08dbe34 and d98cc89.

📒 Files selected for processing (3)
  • vtex/loaders/intelligentSearch/productListingPage.ts (2 hunks)
  • vtex/utils/client.ts (2 hunks)
  • vtex/utils/intelligentSearch.ts (3 hunks)
🔇 Additional comments (4)
vtex/utils/intelligentSearch.ts (1)

54-55: zipCode param introduction looks good

Adding zipCode?: string to Params aligns with the new URL param and keeps internal naming consistent (camelCase internally, hyphenated on the wire).

vtex/utils/client.ts (3)

148-160: Types updated to include “zip-code” for product_search — looks correct

The optional "zip-code" param is added with the right external key, matching how withDefaultParams emits it.


161-173: Types updated to include “zip-code” for facets — looks correct

Consistent with product_search and the loader changes.


148-160: No changes required; zip-code query parameter confirmed
VTEX Intelligent Search’s /api/io/_v/api/intelligent-search/product_search/*facets and /facets/*facets endpoints support zip-code both as a path facet and as a query string (see Delivery Promise—Intelligent Search product_search and Intelligent Search facets reference).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants