summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-07-29 17:13:30 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-07-29 17:13:30 +0700
commit7c2a69c9b48c1930dc3f7cbef20d6479b3047ca2 (patch)
tree7a6500b4b57a9122328ced79a919761435dd6e83
parente79b956cd190419100e52a5468f91eefb7933387 (diff)
<iman> update category lob
-rw-r--r--src/lib/product/components/ProductSearch.jsx35
-rw-r--r--src/pages/shop/lob/[slug].jsx49
2 files changed, 69 insertions, 15 deletions
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>
diff --git a/src/pages/shop/lob/[slug].jsx b/src/pages/shop/lob/[slug].jsx
index 2153b565..cdaf3c91 100644
--- a/src/pages/shop/lob/[slug].jsx
+++ b/src/pages/shop/lob/[slug].jsx
@@ -24,8 +24,55 @@ export default function CategoryDetail() {
const categoryName = getNameFromSlug(slug);
const lobId = getIdFromSlug(slug);
const q = router?.query.q || null;
+
+ useEffect(() => {
+ if(router.pathname.includes('lob')){
+ const loadProduct = async () => {
+ const lobData = await odooApi('GET', `/api/v1/lob_homepage/${lobId}/category_id`);
+
+ if (lobData) {
+ setDataLob(lobData);
+ }
+ };
+ loadProduct();
+
+ }
+ }, [lobId]);
+
+ useEffect(() => {
+ if (router.pathname.includes('lob')){
+
+ const fetchCategoryData = async () => {
+ if (dataLob[0]?.categoryIds) {
+
+ for (const cate of dataLob[0].categoryIds) {
+
+ dataIdCategories.push(cate.childId)
+ }
+
+
+ setData(dataIdCategories.flat())
+
+ // const newQuery = {
+ // fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
+ // category : router.query.category? router.query.category : '',
+ // page : router.query.page? router.query.page : 1,
+ // brand : router.query.brand? router.query.brand : '',
+ // priceFrom,
+ // priceTo,
+ // limit,
+ // orderBy
+ // };
+
+ // setFinalQuery(newQuery);
+
+ }
+ };
+ fetchCategoryData();
+ }
+ }, [dataCategoriesProduct, dataLob]);
const query = {
- fq: `id:${lobId}`,
+ fq: `category_id_ids:(${data.join(' OR ')})`,
page,
};
if (q) {