1
0
mirror of https://github.com/vercel/commerce.git synced 2025-03-18 00:12:33 +00:00
commerce/framework/swell/utils/get-search-variables.ts
2021-03-02 21:05:13 -06:00

28 lines
543 B
TypeScript

import getSortVariables from './get-sort-variables'
import type { SearchProductsInput } from '../product/use-search'
export const getSearchVariables = ({
brandId,
search,
categoryId,
sort,
}: SearchProductsInput) => {
let query = ''
if (search) {
query += `product_type:${search} OR title:${search} OR tag:${search}`
}
if (brandId) {
query += `${search ? ' AND ' : ''}vendor:${brandId}`
}
return {
categoryId,
query,
...getSortVariables(sort, !!categoryId),
}
}
export default getSearchVariables