diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-10-30 02:32:42 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-10-30 02:32:42 +0000 |
| commit | 3196c41e81bce2f012e245e44beb689dcd1fc853 (patch) | |
| tree | 25f9169a48fabcdcabb4da2621f1196b840241a3 | |
| parent | e8c414325a1e32474e740cc6e7dca8396affc5e3 (diff) | |
| parent | 0a1413aec32fddc433a34bf7d03d8681dedc266d (diff) | |
Merged in CR/UI (pull request #111)
CR/UI
| -rw-r--r-- | src/lib/product/components/ProductSearch.jsx | 33 | ||||
| -rw-r--r-- | src/pages/api/shop/brands.js | 6 | ||||
| -rw-r--r-- | src/pages/api/shop/search.js | 5 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index d094a25b..190d026b 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -18,6 +18,8 @@ import whatsappUrl from '@/core/utils/whatsappUrl' import { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react' import odooApi from '@/core/api/odooApi' import { formatCurrency } from '@/core/utils/formatValue' +import axios from 'axios' +import Skeleton from 'react-loading-skeleton' const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) => { const router = useRouter() @@ -28,12 +30,13 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) if (defaultBrand) query.brand = defaultBrand.toLowerCase() const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy }, - operation: 'OR' + operation: 'AND' }) const [products, setProducts] = useState(null) const [spellings, setSpellings] = useState(null) const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null) const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null) + const [isBrand, setIsBrand] = useState(null) const popup = useActive() const numRows = [30, 50, 80, 100] const [brandValues, setBrand] = useState( @@ -78,6 +81,17 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) } }, [productFound, query, spellings]) + useEffect(() => { + const checkIfBrand = async () => { + const brand = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}` + ) + setIsBrand(brand?.data[0]) + + } + checkIfBrand() + }, [q]) + const brands = [] for ( let i = 0; @@ -148,7 +162,11 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) const SpellingComponent = useMemo(() => { return ( <> - Mungkin yang anda cari{' '} + {spellings?.length > 0 ? ( + <>Mungkin yang anda cari </> + ) : ( + <>Produk yang cari anda tidak ada</> + )} {spellings?.map((spelling, i) => ( <Link href={`/shop/search?q=${spelling}`} key={i} className='inline'> {spelling} @@ -331,6 +349,17 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) </div> )} + {isBrand && isBrand.logo && ( + <div className='mb-3'> + <h1 className='text-2xl mb-2 font-semibold'>Brand Pencarian {q}</h1> + <Image + src={isBrand?.logo} + alt='' + className='object-cover object-center h-[100px]' + /> + </div> + )} + <h1 className='text-2xl mb-2 font-semibold'>Hasil Pencarian</h1> <FilterChoicesComponent brandValues={brandValues} diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js index e93fe2c9..2025da70 100644 --- a/src/pages/api/shop/brands.js +++ b/src/pages/api/shop/brands.js @@ -12,6 +12,11 @@ export default async function handler(req, res) { case 'level_s': params = 'level_s:prioritas' break + case 'search': + params = `name_s:${req?.query?.q}` + sort = '' + rows = 1 + break; default: params = `name_s:${req.query.params}` } @@ -20,7 +25,6 @@ export default async function handler(req, res) { process.env.SOLR_HOST + `/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}` ) - let dataBrands = responseMap(brands.data.response.docs) res.status(200).json(dataBrands) diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 883bb8df..576d028a 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -66,8 +66,9 @@ export default async function handler(req, res) { ) } - if (brand) parameter.push(`fq=manufacture_name:${brand.replace(/,/g, ' OR ')}`) - if (category) parameter.push(`fq=category_name:${category.replace(/,/g, ' OR ')}`) + if (brand) parameter.push(`fq=${brand.split(',').map(manufacturer => `manufacture_name:"${manufacturer}"`).join(" OR ")}`) + if (category) parameter.push(`fq=${category.split(',').map(cat => `category_name:"${cat}"`).join(' OR ')}`) + // if (category) parameter.push(`fq=category_name:${capitalizeFirstLetter(category.replace(/,/g, ' OR '))}`) if (stock) parameter.push(`fq=stock_total_f:{1 TO *}`) // Single fq in url params |
