From 6115a7b9e9e1cd2231c946609cb1ceac6d167386 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 12 Oct 2023 13:21:00 +0700 Subject: banner promotion page search --- src/lib/cart/components/Cartheader.jsx | 30 +++++++++++----------- src/lib/product/components/ProductSearch.jsx | 37 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/lib/cart/components/Cartheader.jsx b/src/lib/cart/components/Cartheader.jsx index 901b1501..aa6980ac 100644 --- a/src/lib/cart/components/Cartheader.jsx +++ b/src/lib/cart/components/Cartheader.jsx @@ -125,7 +125,7 @@ const Cardheader = (cartCount) => { >
-
Keranjang Belanja
+
Keranjang Belanja
Lihat Semua @@ -145,15 +145,15 @@ const Cardheader = (cartCount) => { )} {isLoading && itemLoading.map((item) => ( -
-
-
- +
+
+
+
-
-
-
-
+
+
+
+
@@ -167,13 +167,13 @@ const Cardheader = (cartCount) => { )} {auth && products.length > 0 && !isLoading && ( <> -
    +
      {products && products?.map((product, index) => ( <> -
    • -
      -
      +
    • +
      +
      { />
      -
      +
      { className='line-clamp-2 leading-6 !text-gray_r-12 font-normal' > {' '} -

      +

      {product.parent.name}

      diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index ef4580d6..1072b2ae 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -15,6 +15,8 @@ import { useRouter } from 'next/router' import searchSpellApi from '@/core/api/searchSpellApi' import Link from '@/core/components/elements/Link/Link' import whatsappUrl from '@/core/utils/whatsappUrl' +import { Image } from '@chakra-ui/react' +import odooApi from '@/core/api/odooApi' const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { const router = useRouter() @@ -25,6 +27,8 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { const { productSearch } = useProductSearch({ query: { ...query, q, limit } }) const [products, setProducts] = useState(null) const [spellings, setSpellings] = useState(null) + const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null) + const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null) const popup = useActive() const numRows = [30, 50, 80, 100] @@ -117,6 +121,20 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { params = toQuery(params) router.push(`${prefixUrl}?${params}`) } + const getBanner = async () => { + if (router.pathname.includes('search')) { + const getBannerHeader = await odooApi('GET', '/api/v1/banner?type=promotion-header') + const getBannerFooter = await odooApi('GET', '/api/v1/banner?type=promotion-footer') + var randomIndex = Math.floor(Math.random() * getBannerHeader.length) + var randomIndexFooter = Math.floor(Math.random() * getBannerFooter.length) + setBannerPromotionHeader(getBannerHeader[randomIndex]) + setBannerPromotionFooter(getBannerFooter[randomIndexFooter]) + } + } + + useEffect(() => { + getBanner() + }, []) useEffect(() => { setProducts(productSearch.data?.response?.products) @@ -230,6 +248,16 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { />
      + {bannerPromotionHeader && bannerPromotionHeader?.image && ( +
      + +
      + )} +

      Hasil Pencarian

      @@ -332,6 +360,15 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { className='!justify-end' />
      + {bannerPromotionFooter && bannerPromotionFooter?.image && ( +
      + +
      + )}
      -- cgit v1.2.3 From 6d8b6fb53e8f884a0e8ad5682facc37963190014 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 13 Oct 2023 11:05:56 +0700 Subject: Update env example file --- .env.example | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 71977847..397c01f0 100644 --- a/.env.example +++ b/.env.example @@ -13,14 +13,23 @@ MIDTRANS_ENV= MIDTRANS_SERVER_KEY= MIDTRANS_CLIENT_KEY= +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= -GOOGLE_CLIENT_ID="396438712998-308hckshgeekr34phr5jskj1f6qltfvk.apps.googleusercontent.com" -GOOGLE_CLIENT_SECRET=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 +JWT_SECRET= -JWT_SECRET=NTNv7j0TuYARvmNMmWXo6fKvM4o6nvaUi9ryX38ZHL1bkrnD1ObOQ8JAUmHCBq7Iy7otZcyAagBLHVKvvYaIpmMuxmARQ97jUVG16Jkpkp1wXOPsrF9zwew6TpczyHkHgX5EuLg2MeBuiTqJACs1J0apruOOJCggOtkjB4c +RECAPTCHA_GOOGLE= +RAJA_ONGKIR_HOST= +RAJA_ONGKIR_KEY= + +PPN= NEXT_PUBLIC_SELF_HOST=$SELF_HOST NEXT_PUBLIC_ODOO_API_HOST=$ODOO_API_HOST NEXT_PUBLIC_ODOO_HOST=$ODOO_HOST -NEXT_PUBLIC_MIDTRANS_CLIENT_KEY=$MIDTRANS_CLIENT_KEY \ No newline at end of file +NEXT_PUBLIC_MIDTRANS_CLIENT_KEY=$MIDTRANS_CLIENT_KEY +NEXT_PUBLIC_RECAPTCHA_GOOGLE=$RECAPTCHA_GOOGLE +NEXT_PUBLIC_RAJA_ONGKIR_HOST=$RAJA_ONGKIR_HOST +NEXT_PUBLIC_RAJA_ONGKIR_KEY=$RAJA_ONGKIR_KEY +NEXT_PUBLIC_PPN=$PPN \ No newline at end of file -- cgit v1.2.3 From 7ada2eab1773629a3f74fe1a16ba78227953f912 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Sat, 14 Oct 2023 09:03:10 +0700 Subject: add fillterby brand di kolom pencarian --- src/core/components/elements/Navbar/Search.jsx | 42 +++++++++++++++++++++++--- src/pages/api/shop/search.js | 2 +- src/pages/shop/category/[slug].jsx | 6 +++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/core/components/elements/Navbar/Search.jsx b/src/core/components/elements/Navbar/Search.jsx index f4a8ab3a..e4f89103 100644 --- a/src/core/components/elements/Navbar/Search.jsx +++ b/src/core/components/elements/Navbar/Search.jsx @@ -3,12 +3,18 @@ import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' import { useCallback, useEffect, useRef, useState } from 'react' import Link from '../Link/Link' import { useRouter } from 'next/router' +import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug' const Search = () => { const router = useRouter() const queryRef = useRef() + const { slug = '' } = router.query const [query, setQuery] = useState(router.query.q || '') const [suggestions, setSuggestions] = useState([]) + const [segment, setSegment] = useState(null) + const [optionSegment, setOptionSegment] = useState(null) + const [optoinSelected, setOptionSelected] = useState(getNameFromSlug(slug) || 'default') + const [pathSegments, setPathSegments] = useState(router?.asPath.split('/') || []) const loadSuggestion = useCallback(() => { if (query && document.activeElement == queryRef.current) { @@ -26,14 +32,29 @@ const Search = () => { } else { setSuggestions([]) } + setFilterSearch() }, [loadSuggestion, query]) const handleSubmit = (e) => { e.preventDefault() - if (query) { - router.push(`/shop/search?q=${query}`) + if (optionSegment && optoinSelected !== 'default' && optoinSelected) { + router.push(`/shop/${segment}/${slug}?q=${query}`) } else { - queryRef.current.focus() + if (query) { + router.push(`/shop/search?q=${query}`) + } else { + queryRef.current.focus() + } + } + } + + const handleSelectChange = async (e) => { + await setOptionSelected(e.target.value) + } + const setFilterSearch = async () => { + if (router.pathname.includes('brands') && pathSegments[3]) { + await setSegment(pathSegments[2]) + await setOptionSegment(getNameFromSlug(slug)) } } @@ -46,10 +67,23 @@ const Search = () => { return ( <>
      + {segment && ( + + )} + setQuery(e.target.value)} diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 874431e0..fd7a215a 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -13,7 +13,7 @@ export default async function handler(req, res) { orderBy = '', operation = 'AND', fq = '', - limit = '', + limit = 0, stock = '' } = req.query diff --git a/src/pages/shop/category/[slug].jsx b/src/pages/shop/category/[slug].jsx index e3650235..6d3985a8 100644 --- a/src/pages/shop/category/[slug].jsx +++ b/src/pages/shop/category/[slug].jsx @@ -14,8 +14,12 @@ export default function CategoryDetail() { const categoryName = getNameFromSlug(slug) const categoryId = getIdFromSlug(slug) + const q = router?.query.q || null const query = { - fq: `manufacture_id_i:${categoryId}` + fq: `category_id_i:${categoryId}` + } + if (q) { + query.q = q } return ( -- cgit v1.2.3 From 094c341e35376ee2c20e12031830c3020ffb251d Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Sat, 14 Oct 2023 09:13:50 +0700 Subject: delete brand and category 0, & add product found in category filter --- src/lib/product/components/ProductFilter.jsx | 44 +++++++++++----------- .../product/components/ProductFilterDesktop.jsx | 9 +++-- src/lib/product/components/ProductSearch.jsx | 17 +++++++-- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/lib/product/components/ProductFilter.jsx b/src/lib/product/components/ProductFilter.jsx index 40bfc824..38e2d2c3 100644 --- a/src/lib/product/components/ProductFilter.jsx +++ b/src/lib/product/components/ProductFilter.jsx @@ -87,27 +87,25 @@ const ProductFilter = ({ active, close, brands, categories, prefixUrl, defaultBr return (
      - {!router.pathname.includes('brands') && - !defaultBrand && ( -
      - - -
      - ) - } - + {!router.pathname.includes('brands') && !defaultBrand && ( +
      + + +
      + )} +
      diff --git a/src/lib/product/components/ProductFilterDesktop.jsx b/src/lib/product/components/ProductFilterDesktop.jsx index cdfd85e8..582dabea 100644 --- a/src/lib/product/components/ProductFilterDesktop.jsx +++ b/src/lib/product/components/ProductFilterDesktop.jsx @@ -156,12 +156,15 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu {categories.map((category, index) => (
      - {category} +
      + {category.name} + ({category.qty}) +
      ))} diff --git a/src/lib/product/components/ProductSearch.jsx b/src/lib/product/components/ProductSearch.jsx index 3c954548..fd75d587 100644 --- a/src/lib/product/components/ProductSearch.jsx +++ b/src/lib/product/components/ProductSearch.jsx @@ -75,7 +75,9 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { ) { const brand = productSearch.data?.facetCounts?.facetFields?.manufactureName[i] const qty = productSearch.data?.facetCounts?.facetFields?.manufactureName[i + 1] - brands.push({ brand, qty }) + if (qty > 0) { + brands.push({ brand, qty }) + } } /*const brandsList = productSearch.data?.facetCounts?.facetFields?.manufactureName?.filter( (value, index) => { @@ -87,13 +89,22 @@ const ProductSearch = ({ query, prefixUrl, defaultBrand = null }) => { } )*/ - const categories = productSearch.data?.facetCounts?.facetFields?.categoryName?.filter( + const categories = [] + for (let i = 0; i < productSearch.data?.facetCounts?.facetFields?.categoryName.length; i += 2) { + const name = productSearch.data?.facetCounts?.facetFields?.categoryName[i] + const qty = productSearch.data?.facetCounts?.facetFields?.categoryName[i + 1] + if (qty > 0) { + categories.push({ name, qty }) + } + } + + /*const categories = productSearch.data?.facetCounts?.facetFields?.categoryName?.filter( (value, index) => { if (index % 2 === 0) { return true } } - ) + )*/ const orderOptions = [ { value: 'price-asc', label: 'Harga Terendah' }, -- cgit v1.2.3 From 43e59b8c7f8b742e5781a8a8b991afcf9aabb90e Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Sat, 14 Oct 2023 11:08:42 +0700 Subject: add information label if brand and categories in empty --- src/lib/product/components/ProductFilter.jsx | 36 ++++++++---- .../product/components/ProductFilterDesktop.jsx | 67 ++++++++++++---------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/lib/product/components/ProductFilter.jsx b/src/lib/product/components/ProductFilter.jsx index 38e2d2c3..14eef0ba 100644 --- a/src/lib/product/components/ProductFilter.jsx +++ b/src/lib/product/components/ProductFilter.jsx @@ -96,12 +96,18 @@ const ProductFilter = ({ active, close, brands, categories, prefixUrl, defaultBr value={brand} onChange={(e) => setBrand(e.target.value)} > - - {brands.map((brand, index) => ( - - ))} + {brands.length > 0 ? ( + <> + + {brands.map((brand, index) => ( + + ))} + + ) : ( + + )}
      )} @@ -114,12 +120,18 @@ const ProductFilter = ({ active, close, brands, categories, prefixUrl, defaultBr value={category} onChange={(e) => setCategory(e.target.value)} > - - {categories.map((category, index) => ( - - ))} + {categories.length > 0 ? ( + <> + + {categories.map((category, index) => ( + + ))} + + ) : ( + + )}
      diff --git a/src/lib/product/components/ProductFilterDesktop.jsx b/src/lib/product/components/ProductFilterDesktop.jsx index 582dabea..e84d6526 100644 --- a/src/lib/product/components/ProductFilterDesktop.jsx +++ b/src/lib/product/components/ProductFilterDesktop.jsx @@ -111,7 +111,6 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu return ( <> - {!router.pathname.includes('brands') && ( @@ -123,21 +122,25 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu - {brands.map((brand, index) => ( -
      - -
      - {brand.brand} - ({brand.qty}) -
      -
      -
      - ))} + {brands && brands.length > 0 ? ( + brands.map((brand, index) => ( +
      + +
      + {brand.brand} + ({brand.qty}) +
      +
      +
      + )) + ) : ( +
      Brands tidak tersedia
      + )}
      @@ -153,21 +156,25 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu - {categories.map((category, index) => ( -
      - -
      + {categories && categories.length > 0 ? ( + categories.map((category, index) => ( +
      + +
      {category.name} ({category.qty})
      -
      -
      - ))} + +
      + )) + ) : ( +
      Kategori tidak tersedia
      + )} @@ -218,7 +225,7 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu - + {/* Ketersedian Stok @@ -236,7 +243,7 @@ const ProductFilterDesktop = ({ brands, categories, prefixUrl, defaultBrand = nu Ketersedian Stock
      - + */}