query all products for vendors & paths, improve search

This commit is contained in:
cond0r
2021-02-12 09:56:03 +02:00
parent 1450492826
commit 8d801ce5d7
20 changed files with 315 additions and 126 deletions

View File

@@ -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