summaryrefslogtreecommitdiff
path: root/src/lib/product/components
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-07-29 10:14:39 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-07-29 10:14:39 +0000
commit183e81ec22b7fb4e164fb222fa772c3765fa691a (patch)
treee8f6f5433c9773ad8ea84c47a322a97c04d51979 /src/lib/product/components
parentd980e4f1621f33edfbfb94c138be26edb30e60c8 (diff)
parent7c2a69c9b48c1930dc3f7cbef20d6479b3047ca2 (diff)
Merged in Feature/category-management (pull request #180)
Feature/category management
Diffstat (limited to 'src/lib/product/components')
-rw-r--r--src/lib/product/components/ProductSearch.jsx35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx
index 4d510c5b..dec82265 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;
@@ -375,8 +382,6 @@ const ProductSearch = ({
const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock';
- console.log("finalQuery",finalQuery)
-
return (
<>
<MobileView>
@@ -478,7 +483,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'
/>
@@ -667,7 +673,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>