summaryrefslogtreecommitdiff
path: root/src/lib/category/api/popularProduct.js
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-31 09:25:53 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-31 09:25:53 +0700
commit6a0c477de3df773f2a818b904029624c212f083f (patch)
treee1f7a09eb83509de594fe7dbb015a71dd18cec26 /src/lib/category/api/popularProduct.js
parent3de1a412bba31b19b8b443dd91df8aff8d6eda07 (diff)
parentc6e970598c6c23f0606d1bc19036f0decd57cc05 (diff)
Merge branch 'release' into Feature/new-cart-popup
Diffstat (limited to 'src/lib/category/api/popularProduct.js')
-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