From 8d2d384509cd21fb76aeec76d82f362995e4851e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 23 Oct 2023 15:40:04 +0700 Subject: bugs fix query solr filter brand dan category --- src/lib/product/components/ProductSearch.jsx | 2 +- src/pages/api/shop/search.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index d094a25b..79df93f4 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -28,7 +28,7 @@ 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) 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 -- cgit v1.2.3 From 84d81890283155056c26058df65939f4837b14b4 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 23 Oct 2023 15:48:06 +0700 Subject: CR UI - change label if product not found --- src/lib/product/components/ProductSearch.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 79df93f4..5fc75930 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -28,7 +28,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) if (defaultBrand) query.brand = defaultBrand.toLowerCase() const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy }, - operation: 'AND' + operation: 'AND' }) const [products, setProducts] = useState(null) const [spellings, setSpellings] = useState(null) @@ -148,7 +148,7 @@ 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 anda tidak ada} {spellings?.map((spelling, i) => ( {spelling} -- cgit v1.2.3 From 7c08e60acc68f4fbd3ff6af756aeae7c1e7b866c Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 24 Oct 2023 10:02:44 +0700 Subject: change label --- src/lib/product/components/ProductSearch.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 5fc75930..3740d264 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -148,7 +148,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) const SpellingComponent = useMemo(() => { return ( <> - {spellings?.length > 0 ? <>Mungkin yang anda cari : <>Produk yang anda tidak ada} + {spellings?.length > 0 ? <>Mungkin yang anda cari : <>Produk yang cari anda tidak ada} {spellings?.map((spelling, i) => ( {spelling} -- cgit v1.2.3 From 51726bd7e8e69535590d70327ebd340ffaf96abd Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 25 Oct 2023 09:50:46 +0700 Subject: show brand logo di page search --- src/lib/product/components/ProductSearch.jsx | 36 +++++++++++++++++++++++++++- src/pages/api/shop/brands.js | 6 ++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 3740d264..50936d9a 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() @@ -34,6 +36,7 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = 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,22 @@ 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}` + ) + if (brand.data.length > 0) { + brand.data.map((brand) => { + if (brand.name.toLowerCase() === q.toLowerCase()) { + setIsBrand(brand) + } + }) + } + } + checkIfBrand() + }, [q]) + const brands = [] for ( let i = 0; @@ -148,7 +167,11 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) const SpellingComponent = useMemo(() => { return ( <> - {spellings?.length > 0 ? <>Mungkin yang anda cari : <>Produk yang cari anda tidak ada} + {spellings?.length > 0 ? ( + <>Mungkin yang anda cari + ) : ( + <>Produk yang cari anda tidak ada + )} {spellings?.map((spelling, i) => ( {spelling} @@ -331,6 +354,17 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) )} + {isBrand && isBrand.logo && ( +
+

Brand Pencarian {q}

+ +
+ )} +

Hasil Pencarian

Date: Mon, 30 Oct 2023 09:30:25 +0700 Subject: show brand logo in page search if search is brand --- src/lib/product/components/ProductSearch.jsx | 9 ++------- src/pages/api/shop/brands.js | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 50936d9a..190d026b 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -86,13 +86,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null, brand = null }) const brand = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${q}` ) - if (brand.data.length > 0) { - brand.data.map((brand) => { - if (brand.name.toLowerCase() === q.toLowerCase()) { - setIsBrand(brand) - } - }) - } + setIsBrand(brand?.data[0]) + } checkIfBrand() }, [q]) diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js index 85ebee56..2025da70 100644 --- a/src/pages/api/shop/brands.js +++ b/src/pages/api/shop/brands.js @@ -13,9 +13,9 @@ export default async function handler(req, res) { params = 'level_s:prioritas' break case 'search': - params = `{!func}strdist(name_s, "${req?.query?.q}",edit)` + params = `name_s:${req?.query?.q}` sort = '' - rows = 10 + rows = 1 break; default: params = `name_s:${req.query.params}` -- cgit v1.2.3