Skip to content

Commit

Permalink
chore: pickBestSku instead of first sku in suggestions query
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoformiga committed Dec 4, 2023
1 parent 0a4c5ea commit 472076a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/api/src/platforms/vtex/resolvers/searchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Resolver } from '..'
import type { SearchArgs } from '../clients/search'
import type { Facet } from '../clients/search/types/FacetSearchResult'
import { ProductSearchResult } from '../clients/search/types/ProductSearchResult'
import { inStock } from '../utils/productStock'
import { pickBestSku } from '../utils/sku'

type Root = {
searchArgs: Omit<SearchArgs, 'type'>
Expand Down Expand Up @@ -41,7 +41,9 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {

const skus = productSearchResult.products
.map((product) => {
const [maybeSku] = product.items
// What determines the presentation of the SKU is the price order
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
const maybeSku = pickBestSku(product.items)

return maybeSku && enhanceSku(maybeSku, product)
})
Expand All @@ -59,9 +61,9 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {

const skus = productSearchResult.products
.map((product) => {
const maybeSku = product.items.find((item) =>
item.sellers.some((item) => inStock(item.commertialOffer))
)
// What determines the presentation of the SKU is the price order
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
const maybeSku = pickBestSku(product.items)

return maybeSku && enhanceSku(maybeSku, product)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/platforms/vtex/utils/sku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const pickBestSku = (skus: Item[]) => {
bestOfferFirst(o1, o2)
)

return best.sku
return best ? best.sku : skus[0]
}

export const isValidSkuId = (skuId: string) =>
Expand Down

0 comments on commit 472076a

Please sign in to comment.