summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-15 14:20:30 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-15 14:20:30 +0700
commit4fb570559e293d506819059ce42836562a2fb4d2 (patch)
tree4546cfa08d7be7342c80e2a1fa25a3d56dcbdeb1
parentbbbd7ccaab3102558dc82cbd051947b0e579360c (diff)
<iman> update search product using name
-rw-r--r--src-migrate/modules/product-detail/components/SimilarBottom.tsx2
-rw-r--r--src-migrate/modules/product-detail/components/SimilarSide.tsx2
-rw-r--r--src-migrate/services/product.ts7
-rw-r--r--src/lib/product/components/Product/ProductDesktopVariant.jsx9
4 files changed, 15 insertions, 5 deletions
diff --git a/src-migrate/modules/product-detail/components/SimilarBottom.tsx b/src-migrate/modules/product-detail/components/SimilarBottom.tsx
index 8ff0a6bf..f2daf664 100644
--- a/src-migrate/modules/product-detail/components/SimilarBottom.tsx
+++ b/src-migrate/modules/product-detail/components/SimilarBottom.tsx
@@ -11,7 +11,7 @@ type Props = {
const SimilarBottom = ({ product, source }: Props) => {
const productSimilar = useProductSimilar({
name: product.name,
- except: { productId: product.id },
+ except: { productId: product.id, manufactureId: product.manufacture.id },
source: source
})
diff --git a/src-migrate/modules/product-detail/components/SimilarSide.tsx b/src-migrate/modules/product-detail/components/SimilarSide.tsx
index d70a314d..2ba8fa21 100644
--- a/src-migrate/modules/product-detail/components/SimilarSide.tsx
+++ b/src-migrate/modules/product-detail/components/SimilarSide.tsx
@@ -11,7 +11,7 @@ type Props = {
const SimilarSide = ({ product }: Props) => {
const productSimilar = useProductSimilar({
name: product.name,
- except: { productId: product.id, manufactureId: product.manufacture.id },
+ except: { productId: product.id },
})
const products = productSimilar.data?.products || []
diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts
index 2152ba26..a5039ad9 100644
--- a/src-migrate/services/product.ts
+++ b/src-migrate/services/product.ts
@@ -76,8 +76,13 @@ export const getProductSimilar = async ({
dataflashSale = dataflashSale
}
}
+
+ const regex = /\b(?![A-Z\s]+\b)[A-Za-z\s]+\b/g;
+ const matches = name?.match(regex);
+ const extractedName = matches ? matches.join(' ').trim() : '';
+ console.log("extractedName",extractedName);
const query = [
- `q=${name}`,
+ `q=${extractedName}`,
'page=1',
'orderBy=popular-weekly',
'operation=OR',
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,