From 825d86bb50f48f9a21d740d474c0dddee858dffb Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 1 Dec 2025 11:31:30 +0700 Subject: (andri) show upsells product from magento in similarbottom product --- src-migrate/services/product.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src-migrate/services') diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts index 77b645f0..f77fc3ec 100644 --- a/src-migrate/services/product.ts +++ b/src-migrate/services/product.ts @@ -64,3 +64,41 @@ export const getProductCategoryBreadcrumb = async ( ): Promise => { return await odooApi('GET', `/api/v1/product/${id}/category-breadcrumb`); }; + +// ================================================================= +// TAMBAHAN BARU: SERVICE FETCH BY LIST ID (UNTUK UPSELL/RELATED) +// ================================================================= + +export interface GetProductsByIdsProps { + ids: number[]; +} + +export const getProductsByIds = async ({ + ids, +}: GetProductsByIdsProps): Promise => { + // Jika array ID kosong, kembalikan object kosong agar tidak error + if (!ids || ids.length === 0) { + return { + products: [], + num_found: 0, + num_found_exact: true, + start: 0 + }; + } + + // Buat query Solr format: product_id_i:(224102 OR 88019 OR ...) + const idQuery = ids.join(' OR '); + + const query = [ + `q=*`, // Query wildcard (ambil semua) + `fq=product_id_i:(${idQuery})`, // TAPI difilter hanya ID yang ada di list upsell + 'rows=20', + `source=upsell`, + ]; + + const url = `${SELF_HOST}/api/shop/search?${query.join('&')}`; + + return await fetch(url) + .then((res) => res.json()) + .then((res) => snakeCase(res.response)); +}; \ No newline at end of file -- cgit v1.2.3 From 219c61c5c14e3a8dfed3d7158d59d11c476e3586 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Wed, 3 Dec 2025 11:49:18 +0700 Subject: (andri) fix search for similar product side dan bottom pada detail product --- src-migrate/services/product.ts | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src-migrate/services') diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts index f77fc3ec..fa9dae54 100644 --- a/src-migrate/services/product.ts +++ b/src-migrate/services/product.ts @@ -76,29 +76,43 @@ export interface GetProductsByIdsProps { export const getProductsByIds = async ({ ids, }: GetProductsByIdsProps): Promise => { - // Jika array ID kosong, kembalikan object kosong agar tidak error if (!ids || ids.length === 0) { - return { - products: [], - num_found: 0, - num_found_exact: true, - start: 0 - }; + return { products: [], num_found: 0, num_found_exact: true, start: 0 }; } - // Buat query Solr format: product_id_i:(224102 OR 88019 OR ...) const idQuery = ids.join(' OR '); const query = [ - `q=*`, // Query wildcard (ambil semua) - `fq=product_id_i:(${idQuery})`, // TAPI difilter hanya ID yang ada di list upsell + `q=*`, + `fq=(id:(${idQuery}) OR product_id_i:(${idQuery}))`, 'rows=20', `source=upsell`, ]; const url = `${SELF_HOST}/api/shop/search?${query.join('&')}`; - return await fetch(url) - .then((res) => res.json()) - .then((res) => snakeCase(res.response)); + // Request + const res = await fetch(url).then((res) => res.json()); + + // LOG 2: Hasil Pencarian SOLR + console.group("🔍 2. [Solr Search Result]"); + console.log("Request URL:", url); + console.log("Requested IDs:", ids); + + const foundDocs = res.response?.docs || []; + const foundIds = foundDocs.map((doc: any) => doc.id || doc.product_id_i); + + console.log("Found Products Count:", res.response?.numFound); + console.log("Found IDs:", foundIds); + + // Cek ID mana yang hilang + const missingIds = ids.filter((reqId) => !foundIds.includes(String(reqId)) && !foundIds.includes(Number(reqId))); + if (missingIds.length > 0) { + console.warn("⚠️ MISSING / NOT FOUND IDs:", missingIds); + } else { + console.log("✅ All IDs Found!"); + } + console.groupEnd(); + + return snakeCase(res.response); }; \ No newline at end of file -- cgit v1.2.3