diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2026-01-31 16:22:14 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2026-01-31 16:22:14 +0000 |
| commit | 8c6f1b3bf6eac52041337b33e746888933e1e34a (patch) | |
| tree | 0787627b48ef1b1db8e6d76066eb3400afb71123 /src-migrate/services/product.ts | |
| parent | ec7ab4c654fc5b29b277d42ad84986f4c1220134 (diff) | |
| parent | 99aa3500fc5bbb3bb24d73461639e6fc88042a85 (diff) | |
Merged in magento-v2.1 (pull request #472)
Magento v2.1
Diffstat (limited to 'src-migrate/services/product.ts')
| -rw-r--r-- | src-migrate/services/product.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src-migrate/services/product.ts b/src-migrate/services/product.ts index 77b645f0..fa9dae54 100644 --- a/src-migrate/services/product.ts +++ b/src-migrate/services/product.ts @@ -64,3 +64,55 @@ export const getProductCategoryBreadcrumb = async ( ): Promise<ICategoryBreadcrumb[]> => { 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<GetProductSimilarRes> => { + if (!ids || ids.length === 0) { + return { products: [], num_found: 0, num_found_exact: true, start: 0 }; + } + + const idQuery = ids.join(' OR '); + + const query = [ + `q=*`, + `fq=(id:(${idQuery}) OR product_id_i:(${idQuery}))`, + 'rows=20', + `source=upsell`, + ]; + + const url = `${SELF_HOST}/api/shop/search?${query.join('&')}`; + + // 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 |
