Skip to content

Commit

Permalink
Fix name
Browse files Browse the repository at this point in the history
  • Loading branch information
thalytafabrine committed Jan 10, 2024
1 parent 5a2d684 commit a4dc810
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion node/resolvers/search/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const resolvers = {
return items ? path([0, 'productId'], items) : null
},

name: (root: any) => root.name ?? "",
name: (root: any) => root.productName ?? root.name ?? "",

href: (root: any) => root.href ?? `https://portal.vtexcommercestable.com.br/${root.linkText}/p`,

Expand Down
37 changes: 13 additions & 24 deletions node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,58 +322,47 @@ export const queries = {
throw new UserInputError('No search term provided')
}

// do we still need to translate it? not sure.
const translatedTerm = await translateToStoreDefaultLanguage(
ctx,
args.searchTerm
)

const workspaceSearchParams = await getWorkspaceSearchParamsFromStorage(ctx)

const biggyArgs : {[key: string] : any} = {
query: translatedTerm,
query: args.searchTerm,
from: 0,
to: args.maxRows ? args.maxRows - 1 : 4,
sort: '',
allowRedirect: false, // When there is a redirect, no product is returned.
...workspaceSearchParams,
}

const isItems: (SearchAutocompleteUnit | { items: any[], linkText: string, productId: string, name: string })[] = []
const items: (SearchAutocompleteUnit | SearchProduct)[] = []

const [isResult, searchSuggestions] = await Promise.all([
const [productSuggestions, searchSuggestions] = await Promise.all([
intelligentSearchApi.productSearch(biggyArgs, ''),
intelligentSearchApi.autocompleteSearchSuggestions({query: translatedTerm})
intelligentSearchApi.autocompleteSearchSuggestions({query: args.searchTerm})
])

const criterias = searchSuggestions.searches.filter((searchItem: any) => searchItem.term === translatedTerm)
const criterias = searchSuggestions.searches.filter((searchItem: any) => searchItem.term === args.searchTerm)
if (criterias.length) {
criterias[0].attributes.map((att: any) => {
isItems.push({
items.push({
items: [],
thumb: "",
thumbUrl: null,
name: `${translatedTerm} ${att.labelValue}`,
href: `https://portal.vtexcommercestable.com.br/${att.value}/${translatedTerm}`,
criteria: ${translatedTerm} ${att.labelValue}¢/${att.value}/${translatedTerm}`, // validate with catalog
name: `${args.searchTerm} ${att.labelValue}`,
href: `https://portal.vtexcommercestable.com.br/${att.value}/${args.searchTerm}`,
criteria: ${args.searchTerm} ${att.labelValue}¢/${att.value}/${args.searchTerm}`, // validate with catalog
})
})
}

if (isResult.products.length) {
isResult.products.map((product: any) => {
isItems.push({
name: product.productName,
items: product.items,
productId: product.productId,
linkText: product.linkText,
})
if (productSuggestions.products.length) {
productSuggestions.products.map((product: SearchProduct) => {
items.push(product)
})
}

return {
cacheId: args.searchTerm,
itemsReturned: isItems,
itemsReturned: items,
}
},
facets: async (_: any, args: FacetsInput, ctx: any) => {
Expand Down

0 comments on commit a4dc810

Please sign in to comment.