foodbot-cart-calculations 1.0.28 → 1.0.29

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.
@@ -28,6 +28,7 @@ function offerCalculation(carts, offer) {
28
28
  });
29
29
  }
30
30
  });
31
+
31
32
  if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
32
33
  getOfferDetails(carts, offer).then(res => {
33
34
  carts = res
@@ -77,6 +78,12 @@ function offerCalculation(carts, offer) {
77
78
  }).catch(error => {
78
79
  reject(error);
79
80
  })
81
+ } else if (offer && offer.offer_discount_type && offer.offer_discount_type == 'fixed_price') {
82
+ getFixedPriceProductOffer(carts, offer).then(free => {
83
+ resolve(free)
84
+ }).catch(error => {
85
+ reject(error);
86
+ })
80
87
  } else {
81
88
  carts.discount = 0
82
89
  resolve(carts)
@@ -462,8 +469,6 @@ function getOfferDetails(carts, offer = []) {
462
469
  };
463
470
 
464
471
 
465
-
466
-
467
472
  function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
468
473
  return new Promise((resolve, reject) => {
469
474
  let carts = cartData.item_details;
@@ -532,7 +537,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
532
537
  // Handle absolute discount type
533
538
 
534
539
 
535
- buyItemAmount = buyItemAmount + desc[i].amount;
540
+ buyItemAmount = parseFloat(buyItemAmount) + desc[i].amount;
536
541
  desc[i].item.indexss = i;
537
542
  buyItemss.push(desc[i].item);
538
543
  }
@@ -907,6 +912,83 @@ function getFreeProductOffer(cartObject, offer) {
907
912
  }
908
913
  };
909
914
 
915
+ function getFixedPriceProductOffer(cartObject, offer) {
916
+ try {
917
+ let carts = cartObject.item_details;
918
+ carts.forEach(function (v) {
919
+ v.promotion_discount_modifier = 0;
920
+ v.promotion_discount = 0;
921
+ v.redeem_promotion_id = 0;
922
+ if (v.item_modifiers) v.item_modifiers.forEach((mod) => {
923
+ mod.promotion_discount = 0;
924
+ mod.redeem_promotion_id = 0;
925
+ });
926
+ });
927
+
928
+ if (carts && offer.oo_offer_type == "absolute") {
929
+ carts.map((a) => {
930
+ a.promotion_discount = 0;
931
+ a.redeem_promotion_id = 0;
932
+ a.remove = false;
933
+ });
934
+
935
+ return new Promise(function (resolve, reject) {
936
+ var total = 0;
937
+ var count = 0;
938
+ var fixedPrice = offer.oo_offer_value;
939
+
940
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
941
+ offer.offer_products.package_items = offer.offer_products.package_items.map(Number);
942
+
943
+ var cartItem = carts;
944
+
945
+ cartItem.forEach((element, index) => {
946
+ var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
947
+ if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) || offer.offer_products.package_items.includes(parseInt(element.item_id))) {
948
+ var offerAmount = 0;
949
+ var singleItemCost = element.item_price;
950
+
951
+ if(singleItemCost >= fixedPrice){
952
+ offerAmount = (singleItemCost * element.quantity) - (fixedPrice * element.quantity);
953
+ }
954
+
955
+ total = total + parseFloat(offerAmount);
956
+
957
+ carts[ItemIndex].promotion_discount_modifier = parseFloat(offerAmount).toFixed(2);
958
+ carts[ItemIndex].promotion_discount = parseFloat(offerAmount).toFixed(2);
959
+ carts[ItemIndex].remove = true;
960
+
961
+ if (offerAmount > 0) {
962
+ carts[ItemIndex].redeem_promotion_id = offer.offer_id;
963
+ } else {
964
+ carts[ItemIndex].item_modifiers.map((res) => {
965
+ res.promotion_discount = 0;
966
+ res.redeem_promotion_id = 0;
967
+ });
968
+ }
969
+ count++;
970
+ } else {
971
+ count++;
972
+ }
973
+
974
+ if (count == carts.length && carts) {
975
+ cartObject.item_details = carts
976
+ cartObject.discount = total
977
+ resolve(cartObject);
978
+ }
979
+ });
980
+ });
981
+ } else {
982
+ return new Promise(function (resolve, reject) {
983
+ cartObject.discount = 0
984
+ resolve(cartObject);
985
+ });
986
+ }
987
+ } catch (error) {
988
+ reject(error)
989
+ }
990
+ };
991
+
910
992
  function setPackageDefaultDiscount(cart) {
911
993
  return new Promise(async (resolve, reject) => {
912
994
  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.29",
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": {