summaryrefslogtreecommitdiff
path: root/src/lib/category/api
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-23 09:22:29 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-23 09:22:29 +0700
commitc13bb5c6f78032695b24cf8a6c23942eb465c6d5 (patch)
treee48c1ab39a61fd5702f578fbfdb7a7375cc1ce43 /src/lib/category/api
parent870bede9df9920b23f2e5cb771ff5ae6448e3ac7 (diff)
parent4bd29979c34c1ec3b31dd384829b008eb726769c (diff)
Merge branch 'Feature/new-register' into Feature/switch-account
Diffstat (limited to 'src/lib/category/api')
-rw-r--r--src/lib/category/api/popularProduct.js32
1 files changed, 32 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..3fdfc41c
--- /dev/null
+++ b/src/lib/category/api/popularProduct.js
@@ -0,0 +1,32 @@
+
+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,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,
+ qty_sold: promotion.qty_sold_f,
+ };
+ result.push(data);
+ }
+ return result;
+ }; \ No newline at end of file