From 616d8ffc973eba673069243ec8981b5234234fe5 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 8 Aug 2024 17:09:56 +0700 Subject: add similar product template --- .../modules/product-detail/components/ProductDetail.tsx | 2 +- .../modules/product-detail/components/SimilarBottom.tsx | 6 ++++-- src-migrate/services/product.ts | 13 ++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index fad35a7d..f5feae76 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -178,7 +178,7 @@ const ProductDetail = ({ product }: Props) => {
- +
diff --git a/src-migrate/modules/product-detail/components/SimilarBottom.tsx b/src-migrate/modules/product-detail/components/SimilarBottom.tsx index 40d4dd82..ab33f106 100644 --- a/src-migrate/modules/product-detail/components/SimilarBottom.tsx +++ b/src-migrate/modules/product-detail/components/SimilarBottom.tsx @@ -5,12 +5,14 @@ import { IProductDetail } from '~/types/product' type Props = { product: IProductDetail + source: string } -const SimilarBottom = ({ product }: Props) => { +const SimilarBottom = ({ product, source }: Props) => { const productSimilar = useProductSimilar({ name: product.name, - except: { productId: product.id } + except: { productId: product.id }, + source: source }) const products = productSimilar.data?.products || [] diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts index 51667eb9..ec5435cd 100644 --- a/src-migrate/services/product.ts +++ b/src-migrate/services/product.ts @@ -21,6 +21,7 @@ export const getProductById = async ( }; export interface GetProductSimilarProps { + source?: string; name: string; except?: { productId?: number; @@ -34,18 +35,22 @@ export interface GetProductSimilarRes { num_found: number; num_found_exact: boolean; start: number; + source: string; } export const getProductSimilar = async ({ name, except, limit = 30, + source, }: GetProductSimilarProps): Promise => { let dataflashSale = null const flashSale = await odooApi('GET', '/api/v1/flashsale/header') if (flashSale && flashSale.length > 0) { const dataFlash = await productSearchApi({ - query: `fq=flashsale_id_i:${flashSale[0].pricelist_id}&fq=flashsale_price_f:[1 TO *]&limit=4`, + query: `fq=flashsale_id_i:${flashSale[0].pricelist_id}&fq=flashsale_price_f:[1 TO *]&limit=${ + source === 'bottom' ? '4' : '1' + }`, operation: 'AND' }) @@ -61,6 +66,12 @@ export const getProductSimilar = async ({ qty_sold: product.qtySold, lowestPrice: undefined })); + if (source === 'bottom') { + dataflashSale = dataflashSale.slice('2', '4') + } else { + dataflashSale = dataflashSale + } + console.log("dataflashSale",dataflashSale) } const query = [ `q=${name}`, -- cgit v1.2.3