From 7c2a69c9b48c1930dc3f7cbef20d6479b3047ca2 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 29 Jul 2024 17:13:30 +0700
Subject: <iman> update category lob

---
 src/lib/product/components/ProductSearch.jsx | 35 +++++++++++++++++-----------
 1 file changed, 21 insertions(+), 14 deletions(-)

(limited to 'src/lib/product/components/ProductSearch.jsx')

diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index 12e3b358..7ab6b8af 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -38,11 +38,10 @@ const ProductSearch = ({
   brand = null,
 }) => {
   const router = useRouter();
-   
   const { page = 1 } = query;
   const [q, setQ] = useState(query?.q || '*');
   const [search, setSearch] = useState(query?.q || '*');
-  const [limit, setLimit] = useState(query?.limit || 30);
+  const [limit, setLimit] = useState(router.query?.limit || 30);
   const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular');
   const [finalQuery, setFinalQuery] = useState({});
   const [queryFinal, setQueryFinal] = useState({});
@@ -94,9 +93,13 @@ const ProductSearch = ({
       const ids = collectIds(dataCategoriesProduct);
       const newQuery = {
         fq: `category_id_ids:(${ids.join(' OR ')})`,
-        page,
+        page : router.query.page? router.query.page : 1,
         brand : router.query.brand? router.query.brand : '',
         category : router.query.category? router.query.category : '',
+        priceFrom : router.query.priceFrom? router.query.priceFrom : '',
+        priceTo : router.query.priceTo? router.query.priceTo : '',
+        limit : router.query.limit? router.query.limit : '',
+        orderBy : router.query.orderBy? router.query.orderBy : ''
       };
       setFinalQuery(newQuery);
     } else if (prefixUrl.includes('lob')){
@@ -114,9 +117,13 @@ const ProductSearch = ({
          
           const newQuery = {
             fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
-            page,
-            brand : router.query.brand? router.query.brand : '',
             category : router.query.category? router.query.category : '',
+            page : router.query.page? router.query.page : 1,
+            brand : router.query.brand? router.query.brand : '',
+            priceFrom : router.query.priceFrom? router.query.priceFrom : '',
+            priceTo : router.query.priceTo? router.query.priceTo : '',
+            limit : router.query.limit? router.query.limit : '',
+            orderBy : router.query.orderBy? router.query.orderBy : ''
           };
        
           setFinalQuery(newQuery);
@@ -148,17 +155,17 @@ const ProductSearch = ({
   const numRows = [30, 50, 80, 100];
   const [brandValues, setBrand] = useState(
     !router.pathname.includes('brands')
-      ? query.brand
-        ? query.brand.split(',')
+      ? router.query.brand
+        ? router.query.brand.split(',')
         : []
       : []
   );
   const [categoryValues, setCategory] = useState(
-    query?.category?.split(',') || []
+    router.query?.category?.split(',') || router.query?.category?.split(',')
   );
   
-  const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null);
-  const [priceTo, setPriceTo] = useState(query?.priceTo || null);
+  const [priceFrom, setPriceFrom] = useState(router.query?.priceFrom || null);
+  const [priceTo, setPriceTo] = useState(router.query?.priceTo || null);
 
   const pageCount = Math.ceil(productSearch.data?.response.numFound / limit);
   const productStart = productSearch.data?.responseHeader.params.start;
@@ -373,8 +380,6 @@ const ProductSearch = ({
 
   const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock';
   
-  console.log("finalQuery",finalQuery)
-
   return (
     <>
       <MobileView>
@@ -476,7 +481,8 @@ const ProductSearch = ({
           <Pagination
             pageCount={pageCount}
             currentPage={parseInt(page)}
-            url={`${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
+            // url={`${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
+            url={prefixUrl.includes('category') || prefixUrl.includes('lob')? `${prefixUrl}?${toQuery(_.omit(finalQuery, ['page']))}` : `${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
             className='mt-6 mb-2'
           />
 
@@ -665,7 +671,8 @@ const ProductSearch = ({
               <Pagination
                 pageCount={pageCount}
                 currentPage={parseInt(page)}
-                url={`${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
+                // url={`${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
+                url={prefixUrl.includes('category') || prefixUrl.includes('lob')? `${prefixUrl}?${toQuery(_.omit(finalQuery, ['page']))}` : `${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
                 className='!justify-end'
               />
             </div>
-- 
cgit v1.2.3

