foodbot-cart-calculations 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ function offerCalculation(carts, offer) {
9
9
  if(element.item_modifiers && element.item_modifiers.length>0){
10
10
  element.item_modifiers.forEach(mod => {
11
11
  delete mod.promotion_discount;
12
+ delete mod.points_discount;
12
13
  let modTotal = (mod.modifier_item_price * mod.quantity) * element.quantity
13
14
  carts.total += modTotal
14
15
  });
@@ -19,15 +20,18 @@ function offerCalculation(carts, offer) {
19
20
  if (p.item_modifiers)
20
21
  p.item_modifiers.forEach((pMod) => {
21
22
  delete pMod.points_discount;
23
+ delete pMod.promotion_discount;
22
24
  });
23
25
 
24
26
  if (p.modifiers)
25
27
  p.modifiers.forEach((pMod) => {
26
28
  delete pMod.points_discount;
29
+ delete pMod.promotion_discount;
27
30
  });
28
31
  });
29
32
  }
30
33
  });
34
+
31
35
  if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
32
36
  getOfferDetails(carts, offer).then(res => {
33
37
  carts = res
@@ -77,6 +81,12 @@ function offerCalculation(carts, offer) {
77
81
  }).catch(error => {
78
82
  reject(error);
79
83
  })
84
+ } else if (offer && offer.offer_discount_type && offer.offer_discount_type == 'fixed_price') {
85
+ getFixedPriceProductOffer(carts, offer).then(free => {
86
+ resolve(free)
87
+ }).catch(error => {
88
+ reject(error);
89
+ })
80
90
  } else {
81
91
  carts.discount = 0
82
92
  resolve(carts)
@@ -462,8 +472,6 @@ function getOfferDetails(carts, offer = []) {
462
472
  };
463
473
 
464
474
 
465
-
466
-
467
475
  function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
468
476
  return new Promise((resolve, reject) => {
469
477
  let carts = cartData.item_details;
@@ -532,7 +540,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
532
540
  // Handle absolute discount type
533
541
 
534
542
 
535
- buyItemAmount = buyItemAmount + desc[i].amount;
543
+ buyItemAmount = parseFloat(buyItemAmount) + desc[i].amount;
536
544
  desc[i].item.indexss = i;
537
545
  buyItemss.push(desc[i].item);
538
546
  }
@@ -907,6 +915,83 @@ function getFreeProductOffer(cartObject, offer) {
907
915
  }
908
916
  };
909
917
 
918
+ function getFixedPriceProductOffer(cartObject, offer) {
919
+ try {
920
+ let carts = cartObject.item_details;
921
+ carts.forEach(function (v) {
922
+ v.promotion_discount_modifier = 0;
923
+ v.promotion_discount = 0;
924
+ v.redeem_promotion_id = 0;
925
+ if (v.item_modifiers) v.item_modifiers.forEach((mod) => {
926
+ mod.promotion_discount = 0;
927
+ mod.redeem_promotion_id = 0;
928
+ });
929
+ });
930
+
931
+ if (carts && offer.oo_offer_type == "absolute") {
932
+ carts.map((a) => {
933
+ a.promotion_discount = 0;
934
+ a.redeem_promotion_id = 0;
935
+ a.remove = false;
936
+ });
937
+
938
+ return new Promise(function (resolve, reject) {
939
+ var total = 0;
940
+ var count = 0;
941
+ var fixedPrice = offer.oo_offer_value;
942
+
943
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
944
+ offer.offer_products.package_items = offer.offer_products.package_items.map(Number);
945
+
946
+ var cartItem = carts;
947
+
948
+ cartItem.forEach((element, index) => {
949
+ var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
950
+ if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) || offer.offer_products.package_items.includes(parseInt(element.item_id))) {
951
+ var offerAmount = 0;
952
+ var singleItemCost = element.item_price;
953
+
954
+ if(singleItemCost >= fixedPrice){
955
+ offerAmount = (singleItemCost * element.quantity) - (fixedPrice * element.quantity);
956
+ }
957
+
958
+ total = total + parseFloat(offerAmount);
959
+
960
+ carts[ItemIndex].promotion_discount_modifier = parseFloat(offerAmount).toFixed(2);
961
+ carts[ItemIndex].promotion_discount = parseFloat(offerAmount).toFixed(2);
962
+ carts[ItemIndex].remove = true;
963
+
964
+ if (offerAmount > 0) {
965
+ carts[ItemIndex].redeem_promotion_id = offer.offer_id;
966
+ } else {
967
+ carts[ItemIndex].item_modifiers.map((res) => {
968
+ res.promotion_discount = 0;
969
+ res.redeem_promotion_id = 0;
970
+ });
971
+ }
972
+ count++;
973
+ } else {
974
+ count++;
975
+ }
976
+
977
+ if (count == carts.length && carts) {
978
+ cartObject.item_details = carts
979
+ cartObject.discount = total
980
+ resolve(cartObject);
981
+ }
982
+ });
983
+ });
984
+ } else {
985
+ return new Promise(function (resolve, reject) {
986
+ cartObject.discount = 0
987
+ resolve(cartObject);
988
+ });
989
+ }
990
+ } catch (error) {
991
+ reject(error)
992
+ }
993
+ };
994
+
910
995
  function setPackageDefaultDiscount(cart) {
911
996
  return new Promise(async (resolve, reject) => {
912
997
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Package for cart calculations in which it performs discount distribution and tax distribution on order",
5
5
  "main": "index.js",
6
6
  "scripts": {