mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
30 lines
559 B
TypeScript
30 lines
559 B
TypeScript
import getSortVariables from './get-sort-variables'
|
|
import type { SearchProductsInput } from '@commerce/types'
|
|
|
|
export const getSearchVariables = ({
|
|
brandId,
|
|
search,
|
|
categoryId,
|
|
sort,
|
|
locale,
|
|
}: 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,
|
|
locale,
|
|
...getSortVariables(sort, !!categoryId),
|
|
}
|
|
}
|
|
|
|
export default getSearchVariables
|