From 4fb570559e293d506819059ce42836562a2fb4d2 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Thu, 15 Aug 2024 14:20:30 +0700
Subject: <iman> update search product using name

---
 src/lib/product/components/Product/ProductDesktopVariant.jsx | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'src/lib/product/components/Product/ProductDesktopVariant.jsx')

diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx
index b8ec0580..c8a5a205 100644
--- a/src/lib/product/components/Product/ProductDesktopVariant.jsx
+++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx
@@ -137,20 +137,25 @@ const ProductDesktopVariant = ({
       });
     }
   };
+  const regex = /\b(?![A-Z\s]+\b)[A-Za-z\s]+\b/g;
+  const matches = product?.parent?.name?.match(regex);
 
+  const extractedName = matches ? matches.join(' ').trim() : '';
+  console.log("extractedName",extractedName)
   const productSimilarQuery = [
     product?.name,
     `fq=-product_id_i:${product.id}`,
     `fq=-manufacture_id_i:${product.manufacture?.id || 0}`,
   ].join('&');
-
+  
   const [productSimilarInBrand, setProductSimilarInBrand] = useState(null);
-
+  
   useEffect(() => {
     const loadProductSimilarInBrand = async () => {
       const productSimilarQuery = [
         product?.name,
         `fq=-product_id_i:${product.id}`,
+        `fq=display_name_s:${extractedName}`,
       ].join('&');
       const dataProductSimilar = await productSimilarApi({
         query: productSimilarQuery,
-- 
cgit v1.2.3

