From 2e71abba4ca5b83cc1fec229d4d85961c4b56d71 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 25 Jul 2024 08:27:05 +0700
Subject: <iman> update category management

---
 src/lib/product/components/ProductSearch.jsx | 35 +++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 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 c4970b21..b5c1e87d 100644
--- a/src/lib/product/components/ProductSearch.jsx
+++ b/src/lib/product/components/ProductSearch.jsx
@@ -28,6 +28,7 @@ import SideBanner from '~/modules/side-banner';
 import FooterBanner from '~/modules/footer-banner';
 import CategorySection from './CategorySection';
 import { getIdFromSlug } from '@/core/utils/slug'
+import { data } from 'autoprefixer';
 
 const ProductSearch = ({
   query,
@@ -63,6 +64,7 @@ const ProductSearch = ({
   const [categoryValues, setCategory] = useState(
     query?.category?.split(',') || []
   );
+  
   const [priceFrom, setPriceFrom] = useState(query?.priceFrom || null);
   const [priceTo, setPriceTo] = useState(query?.priceTo || null);
 
@@ -71,6 +73,9 @@ const ProductSearch = ({
   const productRows = limit;
   const productFound = productSearch.data?.response.numFound;
   const [dataCategories, setDataCategories] = useState([])
+  const [dataCategoriesProduct, setDataCategoriesProduct] = useState([])
+  const dataId = []
+  // console.log("dataCategories",dataCategories)
 
   const categoryId = getIdFromSlug(prefixUrl)
 
@@ -103,7 +108,7 @@ const ProductSearch = ({
       });
     }
   }, [productFound, query, spellings]);
-
+  let id = []
   useEffect(() => {
     const checkIfBrand = async () => {
       const brand = await axios(
@@ -123,13 +128,37 @@ const ProductSearch = ({
  
   useEffect(() => {
     const loadCategories = async () => {
-      const getCategories = await odooApi('GET', `/api/v1/category/child?parent_id=${categoryId}`) 
+      const getCategories = await odooApi('GET', `/api/v1/category/child?parent_id=${categoryId}`)
      if(getCategories){
       setDataCategories(getCategories)
      }
     }
     loadCategories()
+
+    const loadProduct = async () => {
+      const getCategoriesId = await odooApi('GET', `/api/v1/category/numFound?parent_id=${categoryId}`)
+      console.log("getCategoriesId",getCategoriesId)
+     if(getCategoriesId){
+      setDataCategoriesProduct(getCategoriesId)
+     }
+    }
+    loadProduct()
   }, [])
+  collectIds(dataCategoriesProduct);
+
+// Fungsi rekursif untuk menambahkan ID dari kategori dan subkategori ke array dataId
+function collectIds(category) {
+  if (category && category.id) {
+    dataId.push(category.id);
+  }
+  if (Array.isArray(category.children)) {
+    for (const child of category.children) {
+      collectIds(child);
+    }
+  }
+}
+
+console.log("dataID",dataId)
 
   const brands = [];
   for (
@@ -275,7 +304,7 @@ const ProductSearch = ({
   };
 
   const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock';
-
+  console.log("query?.category?.split(',')",query.fq)
   return (
     <>
       <MobileView>
-- 
cgit v1.2.3

