From aaac6b72dddf8ef8460941797a1f6d88f289f726 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 5 Aug 2024 15:59:30 +0700
Subject: <iman> update category management

---
 src/lib/category/components/PopularBrand.jsx | 96 ++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 src/lib/category/components/PopularBrand.jsx

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
new file mode 100644
index 00000000..32623f91
--- /dev/null
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -0,0 +1,96 @@
+import odooApi from '@/core/api/odooApi'
+import {React } from 'react'
+import axios from 'axios';
+import { useQuery } from 'react-query'
+import Link from '@/core/components/elements/Link/Link'
+import { createSlug } from '@/core/utils/slug'
+import Image from 'next/image'
+import { ChevronRightIcon } from '@heroicons/react/24/outline'
+import useProductSearch from '../../../lib/product/hooks/useProductSearch';
+import { SolrResponse } from "~/types/solr";
+import {fetchPromoItemsSolr} from '../api/popularProduct'
+const SOLR_HOST = process.env.SOLR_HOST
+
+const PopularBrand = ({ category }) => {
+
+    const queryFinal = {
+        fq: `category_id_ids:(${category.categoryDataIds.join(' OR ')})`,
+        fl: 'manufacture_name_s,qty_sold_f',
+        sort: 'qty_sold_f desc',
+        rows: '2000'
+    };
+    
+    // Konversi objek queryFinal menjadi string query
+    // const queryString = new URLSearchParams(queryFinal).toString();
+    
+    async function fetchTopBrands() {
+        try {
+            // const items = await fetchPromoItemsSolr(`category_id_ids:(${category.categoryDataIds.join(' OR ')})`); 
+            const items = await fetchPromoItemsSolr(`type_value_s:discount_loading`);
+
+            console.log("queryFinal", queryFinal);
+            console.log("items", items);
+    
+            // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
+            function getTop12UniqueBrands(products) {
+                const brandSet = new Set();
+                const topBrands = [];
+    
+                for (const product of products) {
+                    if (!brandSet.has(product.manufacture_name_s)) {
+                        brandSet.add(product.manufacture_name_s);
+                        topBrands.push(product.manufacture_name_s);
+                    }
+                    if (topBrands.length === 12) break;
+                }
+    
+                return topBrands;
+            }
+    
+            // Menggunakan hasil pencarian produk
+            const products = items;
+            const top12UniqueBrands = getTop12UniqueBrands(products);
+    
+            console.log('top12UniqueBrands',top12UniqueBrands);
+            return top12UniqueBrands;
+        } catch (error) {
+            console.error("Error fetching data from Solr", error);
+            throw error;
+        }
+    }
+    
+    fetchTopBrands();
+
+
+  return (
+    <div className='flex flex-col'>
+                  <div className='grid grid-cols-2 max-h-full w-full gap-2'>
+                    {category.childs.map((brand, index) => (
+                      (index < 8 ) && (
+                        <div key={brand.id} className='w-full flex items-center justify-center pb-2'>
+                          <Link
+                            href={createSlug('/shop/category/', brand.name, brand.id)}
+                            className='category-mega-box__child-one w-fit h-full flex items-center justify-center '
+                          >
+                            <Image src='https://erp.indoteknik.com/api/image/x_manufactures/x_logo_manufacture/661' alt='' width={104} height={44} objectFit='cover' />
+                          </Link>
+                        </div>
+                      )
+                    ))}
+                  </div>
+                  {category.childs.length > 8 && (
+                    <div className='flex hover:bg-gray_r-8/35 rounded-10'>
+                      <Link
+                        href={createSlug('/shop/category/', category.name, category.id)}
+                        className='category-mega-box__child-one flex items-center gap-4 font-bold hover:ml-4'
+                      >
+                        <p className='mt-2 mb-0 text-danger-500 font-semibold'>Lihat Semua Brand</p>
+                        <ChevronRightIcon className='w-4 text-danger-500 font-bold' />
+                      </Link>
+                    </div>
+        )}
+    </div>
+  )
+}
+
+export default PopularBrand
-- 
cgit v1.2.3


From 54fca7062ee0963d6ea6a22a82fba7fa3fa516e5 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 5 Aug 2024 17:07:35 +0700
Subject: <iman> update category management

---
 src/lib/category/components/PopularBrand.jsx | 105 ++++++++++++---------------
 1 file changed, 46 insertions(+), 59 deletions(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index 32623f91..dca731e8 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -1,5 +1,5 @@
 import odooApi from '@/core/api/odooApi'
-import {React } from 'react'
+import React, { useEffect, useState } from 'react'
 import axios from 'axios';
 import { useQuery } from 'react-query'
 import Link from '@/core/components/elements/Link/Link'
@@ -8,89 +8,76 @@ import Image from 'next/image'
 import { ChevronRightIcon } from '@heroicons/react/24/outline'
 import useProductSearch from '../../../lib/product/hooks/useProductSearch';
 import { SolrResponse } from "~/types/solr";
-import {fetchPromoItemsSolr} from '../api/popularProduct'
+import { fetchPromoItemsSolr } from '../api/popularProduct'
+
 const SOLR_HOST = process.env.SOLR_HOST
 
 const PopularBrand = ({ category }) => {
+    const [topBrands, setTopBrands] = useState([]);
 
-    const queryFinal = {
-        fq: `category_id_ids:(${category.categoryDataIds.join(' OR ')})`,
-        fl: 'manufacture_name_s,qty_sold_f',
-        sort: 'qty_sold_f desc',
-        rows: '2000'
-    };
-    
-    // Konversi objek queryFinal menjadi string query
-    // const queryString = new URLSearchParams(queryFinal).toString();
-    
-    async function fetchTopBrands() {
+    const fetchTopBrands = async () => {
         try {
-            // const items = await fetchPromoItemsSolr(`category_id_ids:(${category.categoryDataIds.join(' OR ')})`); 
-            const items = await fetchPromoItemsSolr(`type_value_s:discount_loading`);
-
-            console.log("queryFinal", queryFinal);
-            console.log("items", items);
-    
+            const items = await fetchPromoItemsSolr(`category_id_ids:(${category.categoryDataIds.join(' OR ')})`);
+            // console.log("id",items)
             // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
-            function getTop12UniqueBrands(products) {
+            const getTop12UniqueBrands = (prod) => {
                 const brandSet = new Set();
                 const topBrands = [];
-    
-                for (const product of products) {
-                    if (!brandSet.has(product.manufacture_name_s)) {
-                        brandSet.add(product.manufacture_name_s);
-                        topBrands.push(product.manufacture_name_s);
+                
+                for (const product of prod) {
+                    if (!brandSet.has(product.manufacture_name)) {
+                        brandSet.add(product.manufacture_name);
+                        topBrands.push({ name: product.manufacture_name, id: product.manufacture_id });
+                    }else{
                     }
-                    if (topBrands.length === 12) break;
+                    if (topBrands.length === 18) break;
                 }
-    
                 return topBrands;
             }
-    
+
             // Menggunakan hasil pencarian produk
             const products = items;
             const top12UniqueBrands = getTop12UniqueBrands(products);
-    
-            console.log('top12UniqueBrands',top12UniqueBrands);
-            return top12UniqueBrands;
+
+            // console.log('top12UniqueBrands', top12UniqueBrands);
+            setTopBrands(top12UniqueBrands);
         } catch (error) {
             console.error("Error fetching data from Solr", error);
             throw error;
         }
     }
-    
-    fetchTopBrands();
 
+    useEffect(() => {
+        fetchTopBrands();
+    }, [category]);
 
-  return (
-    <div className='flex flex-col'>
-                  <div className='grid grid-cols-2 max-h-full w-full gap-2'>
-                    {category.childs.map((brand, index) => (
-                      (index < 8 ) && (
-                        <div key={brand.id} className='w-full flex items-center justify-center pb-2'>
-                          <Link
-                            href={createSlug('/shop/category/', brand.name, brand.id)}
-                            className='category-mega-box__child-one w-fit h-full flex items-center justify-center '
-                          >
-                            <Image src='https://erp.indoteknik.com/api/image/x_manufactures/x_logo_manufacture/661' alt='' width={104} height={44} objectFit='cover' />
-                          </Link>
-                        </div>
-                      )
-                    ))}
-                  </div>
-                  {category.childs.length > 8 && (
-                    <div className='flex hover:bg-gray_r-8/35 rounded-10'>
-                      <Link
+    return (
+        <div className='flex flex-col'>
+            <div className='grid grid-cols-3 max-h-full w-full gap-2'>
+                {topBrands.map((brand, index) => (
+                    <div key={index} className='w-full flex items-center justify-center pb-2'>
+                        <Link
+                            href={createSlug('/shop/brands/', brand.name, brand.id)}
+                            className='category-mega-box__child-one w-8 h-full flex items-center justify-center '
+                        >
+                            <Image src={`https://erp.indoteknik.com/api/image/x_manufactures/x_logo_manufacture/${brand.id}` } alt={`${brand.name}`} width={104} height={44} objectFit='cover' />
+                        </Link>
+                    </div>
+                ))}
+            </div>
+            {/* {topBrands.length > 8 && (
+                <div className='flex hover:bg-gray_r-8/35 rounded-10'>
+                    <Link
                         href={createSlug('/shop/category/', category.name, category.id)}
                         className='category-mega-box__child-one flex items-center gap-4 font-bold hover:ml-4'
-                      >
+                    >
                         <p className='mt-2 mb-0 text-danger-500 font-semibold'>Lihat Semua Brand</p>
                         <ChevronRightIcon className='w-4 text-danger-500 font-bold' />
-                      </Link>
-                    </div>
-        )}
-    </div>
-  )
+                    </Link>
+                </div>
+            )} */}
+        </div>
+    )
 }
 
-export default PopularBrand
+export default PopularBrand;
-- 
cgit v1.2.3


From 4dc62bbe5262be23b2622853973e803f63214a60 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 12 Aug 2024 17:09:13 +0700
Subject: <iman> update category management

---
 src/lib/category/components/PopularBrand.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index dca731e8..7c297d39 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -17,7 +17,7 @@ const PopularBrand = ({ category }) => {
 
     const fetchTopBrands = async () => {
         try {
-            const items = await fetchPromoItemsSolr(`category_id_ids:(${category.categoryDataIds.join(' OR ')})`);
+            const items = await fetchPromoItemsSolr(`category_id_ids:(${category?.categoryDataIds.join(' OR ')})`);
             // console.log("id",items)
             // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
             const getTop12UniqueBrands = (prod) => {
-- 
cgit v1.2.3


From 3e11fce63de4b0d99a1e48c9998d6fcfcec13d98 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 12 Aug 2024 17:11:07 +0700
Subject: <iman> update error code

---
 src/lib/category/components/PopularBrand.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index 7c297d39..09c0f8a1 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -17,7 +17,7 @@ const PopularBrand = ({ category }) => {
 
     const fetchTopBrands = async () => {
         try {
-            const items = await fetchPromoItemsSolr(`category_id_ids:(${category?.categoryDataIds.join(' OR ')})`);
+            const items = await fetchPromoItemsSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
             // console.log("id",items)
             // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
             const getTop12UniqueBrands = (prod) => {
-- 
cgit v1.2.3


From 004a9a644aed65d5c02263f19cce8b7c3000f354 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 13 Aug 2024 10:19:38 +0700
Subject: <iman> update category

---
 src/lib/category/components/PopularBrand.jsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index 09c0f8a1..f0b12e2c 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -8,7 +8,7 @@ import Image from 'next/image'
 import { ChevronRightIcon } from '@heroicons/react/24/outline'
 import useProductSearch from '../../../lib/product/hooks/useProductSearch';
 import { SolrResponse } from "~/types/solr";
-import { fetchPromoItemsSolr } from '../api/popularProduct'
+import { fetchPopulerProductSolr } from '../api/popularProduct'
 
 const SOLR_HOST = process.env.SOLR_HOST
 
@@ -17,7 +17,7 @@ const PopularBrand = ({ category }) => {
 
     const fetchTopBrands = async () => {
         try {
-            const items = await fetchPromoItemsSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
+            const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
             // console.log("id",items)
             // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
             const getTop12UniqueBrands = (prod) => {
-- 
cgit v1.2.3


From 5e2a8d315fa0bc58a18d4df5a995e402388995c9 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 22 Aug 2024 13:10:29 +0700
Subject: <iman> update category dropdown

---
 src/lib/category/components/PopularBrand.jsx | 45 ++++++++++++++++++----------
 1 file changed, 29 insertions(+), 16 deletions(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index f0b12e2c..4777fded 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -18,28 +18,41 @@ const PopularBrand = ({ category }) => {
     const fetchTopBrands = async () => {
         try {
             const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
-            // console.log("id",items)
-            // Fungsi untuk deduplikasi dan mengambil 12 nama brand teratas
             const getTop12UniqueBrands = (prod) => {
-                const brandSet = new Set();
-                const topBrands = [];
-                
+                const brandMap = new Map();
+    
                 for (const product of prod) {
-                    if (!brandSet.has(product.manufacture_name)) {
-                        brandSet.add(product.manufacture_name);
-                        topBrands.push({ name: product.manufacture_name, id: product.manufacture_id });
-                    }else{
+                    const { manufacture_name, manufacture_id, qty_sold } = product;
+    
+                    if (brandMap.has(manufacture_name)) {
+                        // Update the existing brand's qty_sold
+                        brandMap.set(manufacture_name, {
+                            name: manufacture_name,
+                            id: manufacture_id,
+                            qty_sold: brandMap.get(manufacture_name).qty_sold + qty_sold
+                        });
+                    } else {
+                        // Add a new brand to the map
+                        brandMap.set(manufacture_name, {
+                            name: manufacture_name,
+                            id: manufacture_id,
+                            qty_sold
+                        });
                     }
-                    if (topBrands.length === 18) break;
                 }
-                return topBrands;
-            }
-
-            // Menggunakan hasil pencarian produk
+    
+                // Convert the map to an array and sort by qty_sold in descending order
+                const sortedBrands = Array.from(brandMap.values()).sort((a, b) => b.qty_sold - a.qty_sold);
+    
+                // Return the top 12 brands
+                return sortedBrands.slice(0, 18);
+            };
+    
+            // Using the fetched products
             const products = items;
             const top12UniqueBrands = getTop12UniqueBrands(products);
-
-            // console.log('top12UniqueBrands', top12UniqueBrands);
+    
+            // Set the top 12 brands to the state
             setTopBrands(top12UniqueBrands);
         } catch (error) {
             console.error("Error fetching data from Solr", error);
-- 
cgit v1.2.3


From 39cf7a6066d3b7064cb57e4f5583232b4d4d2292 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 3 Sep 2024 08:53:30 +0700
Subject: <iman> delete popular brand

---
 src/lib/category/components/PopularBrand.jsx | 88 ++++++++++++++--------------
 1 file changed, 44 insertions(+), 44 deletions(-)

(limited to 'src/lib/category/components/PopularBrand.jsx')

diff --git a/src/lib/category/components/PopularBrand.jsx b/src/lib/category/components/PopularBrand.jsx
index 4777fded..8124b5b4 100644
--- a/src/lib/category/components/PopularBrand.jsx
+++ b/src/lib/category/components/PopularBrand.jsx
@@ -13,60 +13,60 @@ import { fetchPopulerProductSolr } from '../api/popularProduct'
 const SOLR_HOST = process.env.SOLR_HOST
 
 const PopularBrand = ({ category }) => {
-    const [topBrands, setTopBrands] = useState([]);
+    // const [topBrands, setTopBrands] = useState([]);
 
-    const fetchTopBrands = async () => {
-        try {
-            const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
-            const getTop12UniqueBrands = (prod) => {
-                const brandMap = new Map();
+    // const fetchTopBrands = async () => {
+    //     try {
+    //         const items = await fetchPopulerProductSolr(`category_id_ids:(${category?.categoryDataIds?.join(' OR ')})`);
+    //         const getTop12UniqueBrands = (prod) => {
+    //             const brandMap = new Map();
     
-                for (const product of prod) {
-                    const { manufacture_name, manufacture_id, qty_sold } = product;
+    //             for (const product of prod) {
+    //                 const { manufacture_name, manufacture_id, qty_sold } = product;
     
-                    if (brandMap.has(manufacture_name)) {
-                        // Update the existing brand's qty_sold
-                        brandMap.set(manufacture_name, {
-                            name: manufacture_name,
-                            id: manufacture_id,
-                            qty_sold: brandMap.get(manufacture_name).qty_sold + qty_sold
-                        });
-                    } else {
-                        // Add a new brand to the map
-                        brandMap.set(manufacture_name, {
-                            name: manufacture_name,
-                            id: manufacture_id,
-                            qty_sold
-                        });
-                    }
-                }
+    //                 if (brandMap.has(manufacture_name)) {
+    //                     // Update the existing brand's qty_sold
+    //                     brandMap.set(manufacture_name, {
+    //                         name: manufacture_name,
+    //                         id: manufacture_id,
+    //                         qty_sold: brandMap.get(manufacture_name).qty_sold + qty_sold
+    //                     });
+    //                 } else {
+    //                     // Add a new brand to the map
+    //                     brandMap.set(manufacture_name, {
+    //                         name: manufacture_name,
+    //                         id: manufacture_id,
+    //                         qty_sold
+    //                     });
+    //                 }
+    //             }
     
-                // Convert the map to an array and sort by qty_sold in descending order
-                const sortedBrands = Array.from(brandMap.values()).sort((a, b) => b.qty_sold - a.qty_sold);
+    //             // Convert the map to an array and sort by qty_sold in descending order
+    //             const sortedBrands = Array.from(brandMap.values()).sort((a, b) => b.qty_sold - a.qty_sold);
     
-                // Return the top 12 brands
-                return sortedBrands.slice(0, 18);
-            };
+    //             // Return the top 12 brands
+    //             return sortedBrands.slice(0, 18);
+    //         };
     
-            // Using the fetched products
-            const products = items;
-            const top12UniqueBrands = getTop12UniqueBrands(products);
+    //         // Using the fetched products
+    //         const products = items;
+    //         const top12UniqueBrands = getTop12UniqueBrands(products);
     
-            // Set the top 12 brands to the state
-            setTopBrands(top12UniqueBrands);
-        } catch (error) {
-            console.error("Error fetching data from Solr", error);
-            throw error;
-        }
-    }
+    //         // Set the top 12 brands to the state
+    //         setTopBrands(top12UniqueBrands);
+    //     } catch (error) {
+    //         console.error("Error fetching data from Solr", error);
+    //         throw error;
+    //     }
+    // }
 
-    useEffect(() => {
-        fetchTopBrands();
-    }, [category]);
+    // useEffect(() => {
+    //     fetchTopBrands();
+    // }, [category]);
 
     return (
         <div className='flex flex-col'>
-            <div className='grid grid-cols-3 max-h-full w-full gap-2'>
+            {/* <div className='grid grid-cols-3 max-h-full w-full gap-2'>
                 {topBrands.map((brand, index) => (
                     <div key={index} className='w-full flex items-center justify-center pb-2'>
                         <Link
@@ -77,7 +77,7 @@ const PopularBrand = ({ category }) => {
                         </Link>
                     </div>
                 ))}
-            </div>
+            </div> */}
             {/* {topBrands.length > 8 && (
                 <div className='flex hover:bg-gray_r-8/35 rounded-10'>
                     <Link
-- 
cgit v1.2.3

