diff options
| author | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2025-12-01 11:31:30 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <andrifebriyadiputra@gmail.com> | 2025-12-01 11:31:30 +0700 |
| commit | 825d86bb50f48f9a21d740d474c0dddee858dffb (patch) | |
| tree | 023c9412c4c451aee45e54fe1d987e6220a8a6c5 /src-migrate/services/product.ts | |
| parent | a5e695f82e03577cc85c4a1dded9f6021f0235fc (diff) | |
(andri) show upsells product from magento in similarbottom product
Diffstat (limited to 'src-migrate/services/product.ts')
| -rw-r--r-- | src-migrate/services/product.ts | 38 |
1 files changed, 38 insertions, 0 deletions
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<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> => { + // 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 |
