-
Notifications
You must be signed in to change notification settings - Fork 19
feat: send zip-code param to intelligent search api call #1370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughParses 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 Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Comment |
Tagging OptionsShould a new tag be published when this PR is merged?
|
There was a problem hiding this 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 sendingzip-code=undefinedto VTEXDepending 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
cacheKeywhitelists query params viaALLOWED_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.searchParamswill 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 whitespaceSmall 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 URLsFilter 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
📒 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 goodAdding
zipCode?: stringtoParamsaligns 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 correctThe optional
"zip-code"param is added with the right external key, matching howwithDefaultParamsemits it.
161-173: Types updated to include “zip-code” for facets — looks correctConsistent with product_search and the loader changes.
148-160: No changes required;zip-codequery parameter confirmed
VTEX Intelligent Search’s/api/io/_v/api/intelligent-search/product_search/*facetsand/facets/*facetsendpoints supportzip-codeboth as a path facet and as a query string (see Delivery Promise—Intelligent Search product_search and Intelligent Search facets reference).
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
Demonstration Link
Summary by CodeRabbit