From a20fd43f0cafe86444605c3bb8f2a998e1b9dbe6 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 11:03:58 +0700 Subject: update link lihat semua non display voucher --- src/lib/product/components/ProductSearch.jsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (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 fb9017f4..09727e81 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -40,6 +40,24 @@ const ProductSearch = ({ const [limit, setLimit] = useState(query?.limit || 30); const [orderBy, setOrderBy] = useState(router.query?.orderBy); if (defaultBrand) query.brand = defaultBrand.toLowerCase(); + + useEffect(() => { + const checkIfPenawaran = async () => { + if (router.asPath.includes('penawaran')) { + query = { + ...query, + fq: [ + `-flashsale_id_i:${router.query.penawaran}`, + `flashsale_price_f:[1 TO *]` + ], + orderBy: 'flashsale-discount-desc' + }; + setOrderBy('flashsale-discount-desc') + } + }; + checkIfPenawaran(); + }, [router]); + const { productSearch } = useProductSearch({ query: { ...query, q, limit, orderBy }, operation: 'AND', -- cgit v1.2.3 From b4101696955b2573a5b259d6166c9e950f33d992 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 11:09:50 +0700 Subject: update flash sale non display --- src/lib/product/components/ProductSearch.jsx | 2 ++ 1 file changed, 2 insertions(+) (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 09727e81..994efce0 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -239,6 +239,7 @@ const ProductSearch = ({ const handleDeleteFilter = async (source, value) => { let params = { + penawaran: router.query.penawaran, q: router.query.q, orderBy: orderBy, brand: brandValues.join(','), @@ -266,6 +267,7 @@ const ProductSearch = ({ break; case 'delete': params = { + penawaran: router.query.penawaran, q: router.query.q, orderBy: orderBy, }; -- cgit v1.2.3 From dcfd0995a4fe85d947a96f3fffd54914a1e2e171 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 11:14:59 +0700 Subject: merge product search development into all promo --- src/lib/product/components/ProductSearch.jsx | 145 +++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 10 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 994efce0..42ea94d5 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -26,6 +26,10 @@ import ProductSearchSkeleton from './Skeleton/ProductSearchSkeleton'; import SideBanner from '~/modules/side-banner'; import FooterBanner from '~/modules/footer-banner'; +import CategorySection from './CategorySection'; +import LobSectionCategory from './LobSectionCategory'; +import { getIdFromSlug } from '@/core/utils/slug' +import { data } from 'autoprefixer'; const ProductSearch = ({ query, @@ -37,9 +41,107 @@ const ProductSearch = ({ const { page = 1 } = query; const [q, setQ] = useState(query?.q || '*'); const [search, setSearch] = useState(query?.q || '*'); + const [finalQuery, setFinalQuery] = useState({}); + const [queryFinal, setQueryFinal] = useState({}); + const [dataCategoriesProduct, setDataCategoriesProduct] = useState([]) + const [dataCategoriesLob, setDataCategoriesLob] = useState([]) + const categoryId = getIdFromSlug(prefixUrl) + const [data, setData] = useState([]) + const [dataLob, setDataLob] = useState([]); const [limit, setLimit] = useState(query?.limit || 30); const [orderBy, setOrderBy] = useState(router.query?.orderBy); if (defaultBrand) query.brand = defaultBrand.toLowerCase(); + const dataIdCategories = [] + useEffect(() => { + if(prefixUrl.includes('category')){ + const loadProduct = async () => { + const getCategoriesId = await odooApi('GET', `/api/v1/category/numFound?parent_id=${categoryId}`); + if (getCategoriesId) { + setDataCategoriesProduct(getCategoriesId); + } + }; + loadProduct(); + }else if(prefixUrl.includes('lob')){ + const loadProduct = async () => { + const lobData = await odooApi('GET', `/api/v1/lob_homepage/${categoryId}/category_id`); + + if (lobData) { + setDataLob(lobData); + } + }; + loadProduct(); + + } + }, [categoryId]); + + const collectIds = (category) => { + const ids = []; + function recurse(cat) { + if (cat && cat.id) { + ids.push(cat.id); + } + if (Array.isArray(cat.children)) { + cat.children.forEach(recurse); + } + } + recurse(category); + return ids; + }; + + useEffect(() => { + if(prefixUrl.includes('category')){ + const ids = collectIds(dataCategoriesProduct); + const newQuery = { + fq: `category_id_ids:(${ids.join(' OR ')})`, + 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')){ + + const fetchCategoryData = async () => { + if (dataLob[0]?.categoryIds) { + + for (const cate of dataLob[0].categoryIds) { + + dataIdCategories.push(cate.childId) + } + + + const mergedArray = 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 : 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); + + } + }; + fetchCategoryData(); + } + }, [dataCategoriesProduct, dataLob]); + + useEffect(() => { + if (prefixUrl.includes('category') || prefixUrl.includes('lob')) { + setQueryFinal({ ...finalQuery, q, limit, orderBy }); + } else { + setQueryFinal({ ...query, q, limit, orderBy }); + } + }, [prefixUrl,dataCategoriesProduct, query, finalQuery]); + useEffect(() => { const checkIfPenawaran = async () => { @@ -59,7 +161,7 @@ const ProductSearch = ({ }, [router]); const { productSearch } = useProductSearch({ - query: { ...query, q, limit, orderBy }, + query: queryFinal, operation: 'AND', }); const [products, setProducts] = useState(null); @@ -71,22 +173,24 @@ 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; const productRows = limit; const productFound = productSearch.data?.response.numFound; - + const [dataCategories, setDataCategories] = useState([]) + useEffect(() => { if (productFound == 0 && query.q && !spellings) { searchSpellApi({ query: query.q }).then((response) => { @@ -116,7 +220,7 @@ const ProductSearch = ({ }); } }, [productFound, query, spellings]); - + let id = [] useEffect(() => { const checkIfBrand = async () => { const brand = await axios( @@ -133,6 +237,21 @@ const ProductSearch = ({ checkIfBrand(); } }, [q]); + + useEffect(() => { + if(prefixUrl.includes('category')){ + const loadCategories = async () => { + const getCategories = await odooApi('GET', `/api/v1/category/child?parent_id=${categoryId}`) + if(getCategories){ + setDataCategories(getCategories) + } + } + loadCategories() + } + }, []) + + + const brands = []; for ( @@ -243,7 +362,7 @@ const ProductSearch = ({ q: router.query.q, orderBy: orderBy, brand: brandValues.join(','), - category: categoryValues.join(','), + category: categoryValues?.join(','), priceFrom, priceTo, }; @@ -283,7 +402,6 @@ const ProductSearch = ({ }; const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock'; - return ( <> @@ -344,6 +462,8 @@ const ProductSearch = ({ SpellingComponent )} + + {productFound > 0 && (
@@ -384,6 +504,7 @@ const ProductSearch = ({ pageCount={pageCount} currentPage={parseInt(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' /> @@ -432,7 +553,10 @@ const ProductSearch = ({
+
+ + {bannerPromotionHeader && bannerPromotionHeader?.image && (
-- cgit v1.2.3 From 5fb7f3fe3488e9d1b4885d9c5ad9720032babb54 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 11:26:23 +0700 Subject: update --- src/lib/product/components/ProductSearch.jsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 a427e134..07398795 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -26,8 +26,8 @@ import ProductSearchSkeleton from './Skeleton/ProductSearchSkeleton'; import SideBanner from '~/modules/side-banner'; import FooterBanner from '~/modules/footer-banner'; -import CategorySection from './CategorySection'; -import LobSectionCategory from './LobSectionCategory'; +// import CategorySection from './CategorySection'; +// import LobSectionCategory from './LobSectionCategory'; import { getIdFromSlug } from '@/core/utils/slug' import { data } from 'autoprefixer'; @@ -461,8 +461,8 @@ const ProductSearch = ({ SpellingComponent )}
- - + {/* + */} {productFound > 0 && (
@@ -554,8 +554,8 @@ const ProductSearch = ({
- - + {/* + */} {bannerPromotionHeader && bannerPromotionHeader?.image && (
Date: Mon, 19 Aug 2024 14:02:10 +0700 Subject: update position code --- src/lib/product/components/ProductSearch.jsx | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 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 07398795..b799d533 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -52,6 +52,24 @@ const ProductSearch = ({ const [orderBy, setOrderBy] = useState(router.query?.orderBy); if (defaultBrand) query.brand = defaultBrand.toLowerCase(); const dataIdCategories = [] + + useEffect(() => { + const checkIfPenawaran = async () => { + if (router.asPath.includes('penawaran')) { + query = { + ...query, + fq: [ + `-flashsale_id_i:${router.query.penawaran}`, + `flashsale_price_f:[1 TO *]` + ], + orderBy: 'flashsale-discount-desc' + }; + setOrderBy('flashsale-discount-desc') + } + }; + checkIfPenawaran(); + }, [router]); + useEffect(() => { if(prefixUrl.includes('category')){ const loadProduct = async () => { @@ -142,22 +160,6 @@ const ProductSearch = ({ } }, [prefixUrl,dataCategoriesProduct, query, finalQuery]); - useEffect(() => { - const checkIfPenawaran = async () => { - if (router.asPath.includes('penawaran')) { - query = { - ...query, - fq: [ - `-flashsale_id_i:${router.query.penawaran}`, - `flashsale_price_f:[1 TO *]` - ], - orderBy: 'flashsale-discount-desc' - }; - setOrderBy('flashsale-discount-desc') - } - }; - checkIfPenawaran(); - }, [router]); const { productSearch } = useProductSearch({ query: queryFinal, -- cgit v1.2.3 From 3c6c2a888e3ab27b4d5eead34104fd142f82b1ff Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 14:53:22 +0700 Subject: update order by non flash display --- src/lib/product/components/ProductSearch.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 b799d533..f8b44529 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -53,6 +53,8 @@ const ProductSearch = ({ if (defaultBrand) query.brand = defaultBrand.toLowerCase(); const dataIdCategories = [] + console.log('data',router) + useEffect(() => { const checkIfPenawaran = async () => { if (router.asPath.includes('penawaran')) { @@ -64,11 +66,13 @@ const ProductSearch = ({ ], orderBy: 'flashsale-discount-desc' }; + console.log('setOrder') setOrderBy('flashsale-discount-desc') + console.log('orderBy',orderBy) } }; checkIfPenawaran(); - }, [router]); + }, [router.query, prefixUrl, q, finalQuery, queryFinal]); useEffect(() => { if(prefixUrl.includes('category')){ @@ -156,9 +160,10 @@ const ProductSearch = ({ if (prefixUrl.includes('category') || prefixUrl.includes('lob')) { setQueryFinal({ ...finalQuery, q, limit, orderBy }); } else { + console.log("data query",orderBy) setQueryFinal({ ...query, q, limit, orderBy }); } - }, [prefixUrl,dataCategoriesProduct, query, finalQuery]); + }, [prefixUrl,dataCategoriesProduct, query, finalQuery, orderBy]); const { productSearch } = useProductSearch({ -- cgit v1.2.3 From 3722093f3a84c7b6700da06b3e176cdca4a22b26 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 19 Aug 2024 14:59:03 +0700 Subject: delete console log --- src/lib/product/components/ProductSearch.jsx | 2 -- 1 file changed, 2 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 f8b44529..7c1b0a40 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -53,8 +53,6 @@ const ProductSearch = ({ if (defaultBrand) query.brand = defaultBrand.toLowerCase(); const dataIdCategories = [] - console.log('data',router) - useEffect(() => { const checkIfPenawaran = async () => { if (router.asPath.includes('penawaran')) { -- cgit v1.2.3