diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-08 17:09:56 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-08 17:09:56 +0700 |
| commit | 616d8ffc973eba673069243ec8981b5234234fe5 (patch) | |
| tree | bd3aac41921bbad8959e0c4b6b083aabd7d097e3 | |
| parent | bd62835db7dc521a17d6b0aea81badaae6ade95c (diff) | |
<iman> add similar product template
| -rw-r--r-- | src-migrate/modules/product-detail/components/ProductDetail.tsx | 2 | ||||
| -rw-r--r-- | src-migrate/modules/product-detail/components/SimilarBottom.tsx | 6 | ||||
| -rw-r--r-- | src-migrate/services/product.ts | 13 |
3 files changed, 17 insertions, 4 deletions
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) => { <div className='h-6' /> <LazyLoadComponent> - <SimilarBottom product={product} /> + <SimilarBottom product={product} source={'bottom'}/> </LazyLoadComponent> </div> 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<GetProductSimilarRes> => { 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}`, |
