diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-08-20 09:14:52 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-08-20 09:14:52 +0000 |
| commit | 7388f27d1778aaa66191b44d725ce7c3e3e4ddd8 (patch) | |
| tree | 7fdef4f99f0f42e2d99a40bfd5b81f1ca5f4ef30 /src/lib/category/api | |
| parent | 6d302bb338e26810a7f90326b84086217f1f4ae0 (diff) | |
| parent | 5c5eef9d62efd83f52f7c37dacb94d50ff7cb915 (diff) | |
Merged in Feature/category-management (pull request #248)
Feature/category management
Diffstat (limited to 'src/lib/category/api')
| -rw-r--r-- | src/lib/category/api/popularProduct.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/category/api/popularProduct.js b/src/lib/category/api/popularProduct.js new file mode 100644 index 00000000..48f8a2a0 --- /dev/null +++ b/src/lib/category/api/popularProduct.js @@ -0,0 +1,31 @@ + +export const fetchPopulerProductSolr = async (category_id_ids) => { + let sort ='sort=qty_sold_f desc'; + try { + const queryParams = new URLSearchParams({ q: category_id_ids }); + const response = await fetch(`/solr/product/select?${queryParams.toString()}&rows=2000&fl=manufacture_name_s,manufacture_id_i,id,display_name_s,qty_sold_f&${sort}`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); + const promotions = await map(data.response.docs); + return promotions; + } catch (error) { + console.error("Error fetching promotion data:", error); + return []; + } + }; + + const map = async (promotions) => { + const result = []; + for (const promotion of promotions) { + const data = { + id: promotion.id, + name: promotion.display_name_s, + manufacture_name: promotion.manufacture_name_s, + manufacture_id: promotion.manufacture_id_i, + }; + result.push(data); + } + return result; + };
\ No newline at end of file |
