mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
query all products for vendors & paths, improve search
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
export const searchByProductType = (search?: string) => {
|
||||
return search
|
||||
? {
|
||||
query: `product_type:${search}`,
|
||||
}
|
||||
: {}
|
||||
import { SearchProductsInput } from '@framework/product/use-search'
|
||||
import getSortVariables from './get-sort-variables'
|
||||
|
||||
export const getSearchVariables = ({
|
||||
categoryId,
|
||||
brandId,
|
||||
search,
|
||||
sort,
|
||||
}: SearchProductsInput) => {
|
||||
let query = ''
|
||||
|
||||
if (search) {
|
||||
query += `product_type:${search} OR title:${search} OR tag:${search}`
|
||||
}
|
||||
|
||||
if (categoryId) {
|
||||
query += `tag:${categoryId}`
|
||||
}
|
||||
|
||||
if (brandId) {
|
||||
query += `${categoryId ? ' AND ' : ''}vendor:${brandId}`
|
||||
}
|
||||
|
||||
return {
|
||||
query,
|
||||
...getSortVariables(sort),
|
||||
}
|
||||
}
|
||||
|
||||
export const searchByTag = (categoryPath?: string) => {
|
||||
return categoryPath
|
||||
? {
|
||||
query: `tag:${categoryPath}`,
|
||||
}
|
||||
: {}
|
||||
}
|
||||
export default getSearchVariables
|
||||
|
Reference in New Issue
Block a user