mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
28 lines
567 B
TypeScript
28 lines
567 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 = 'available_for_sale:true'
|
|
|
|
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
|