summaryrefslogtreecommitdiff
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
parentd980e4f1621f33edfbfb94c138be26edb30e60c8 (diff)
parent7c2a69c9b48c1930dc3f7cbef20d6479b3047ca2 (diff)
Merged in Feature/category-management (pull request #180)
Feature/category management
-rw-r--r--src/lib/product/components/ProductSearch.jsx35
-rw-r--r--src/pages/index.jsx10
-rw-r--r--src/pages/shop/lob/[slug].jsx49
3 files changed, 74 insertions, 20 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>
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index 30a7ac1f..64c880c7 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -45,9 +45,9 @@ const FlashSale = dynamic(
}
);
-const ProgramPromotion = dynamic(() =>
- import('@/lib/home/components/PromotionProgram')
-);
+// const ProgramPromotion = dynamic(() =>
+// import('@/lib/home/components/PromotionProgram')
+// );
const BannerSection = dynamic(() =>
import('@/lib/home/components/BannerSection')
@@ -138,7 +138,7 @@ export default function Home({categoryId}) {
</div>
{!auth?.feature?.soApproval && (
<>
- <ProgramPromotion /> <FlashSale />
+ {/* <ProgramPromotion /> <FlashSale /> */}
</>
)}
<PromotinProgram />
@@ -168,7 +168,7 @@ export default function Home({categoryId}) {
{!auth?.feature?.soApproval && (
<>
<DelayRender renderAfter={400}>
- <ProgramPromotion />
+ {/* <ProgramPromotion /> */}
</DelayRender>
<DelayRender renderAfter={600}>
<FlashSale />
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) {