diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-08-05 10:10:08 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-08-05 10:10:08 +0000 |
| commit | 9441fe06320c63c20f193babe5efd4da48de165e (patch) | |
| tree | 94ec1a5c497178298dc2fb88182e3b131c495cba /src/lib/category/api | |
| parent | 3d1758a7b6969822e85cbd3cf16f7ad6e64de553 (diff) | |
| parent | 54fca7062ee0963d6ea6a22a82fba7fa3fa516e5 (diff) | |
Merged in Feature/category-management (pull request #214)
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..e17e0ae5 --- /dev/null +++ b/src/lib/category/api/popularProduct.js @@ -0,0 +1,31 @@ + +export const fetchPromoItemsSolr = 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&${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 |
