foodbot-cart-calculations 1.0.40 → 1.0.41

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.
package/calculations.js CHANGED
@@ -7,8 +7,9 @@ function applyDistribution(body) {
7
7
  body.discount = 0
8
8
  let mainCart = body
9
9
  let promotion = (body.promotion_applied && body.promotion_applied) ? body.promotion_applied : {};
10
+ let deliveryCost = (body.delivery_cost && body.delivery_cost) ? body.delivery_cost : 0;
10
11
  promoCalculation.setPackageDefaultDiscount(body.order_items).then(res => {
11
- promoCalculation.offerCalculation(res, promotion).then(final => {
12
+ promoCalculation.offerCalculation(res, promotion, deliveryCost).then(final => {
12
13
 
13
14
  let taxSettings = (body.tax_settings && body.tax_settings.length > 0) ? body.tax_settings : []
14
15
  let taxType = (body.tax_type) ? body.tax_type : 1
@@ -67,8 +68,14 @@ function applyDistribution(body) {
67
68
  mainCart.cash_expected = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount);
68
69
  }
69
70
  mainCart.order_items = taxData
70
-
71
+
71
72
  let delivery_cost = body.delivery_cost?body.delivery_cost:0;
73
+
74
+ if(final.is_delivery_discount){
75
+ delivery_cost = 0;
76
+ body.delivery_cost = 0
77
+ }
78
+
72
79
  let service_amount = body.service_amount?body.service_amount:0;
73
80
 
74
81
  //we took 2 value because in case of absolute we use tipValue
@@ -1,4 +1,4 @@
1
- function offerCalculation(carts, offer) {
1
+ function offerCalculation(carts, offer, deliveryCost = 0) {
2
2
  return new Promise(function (resolve, reject) {
3
3
  try {
4
4
  carts.total = 0
@@ -88,6 +88,12 @@ function offerCalculation(carts, offer) {
88
88
  }).catch(error => {
89
89
  reject(error);
90
90
  })
91
+ } else if (offer && offer.offer_discount_type && offer.offer_discount_type == 'free_delivery') {
92
+ getFreeDeliveryOffer(carts, offer, deliveryCost).then(free => {
93
+ resolve(free)
94
+ }).catch(error => {
95
+ reject(error);
96
+ })
91
97
  } else {
92
98
  carts.discount = 0
93
99
  resolve(carts)
@@ -1011,6 +1017,25 @@ function getFixedPriceProductOffer(cartObject, offer) {
1011
1017
  }
1012
1018
  };
1013
1019
 
1020
+ function getFreeDeliveryOffer(cartObject, offer, deliveryCost = 0) {
1021
+ return new Promise(function (resolve, reject) {
1022
+ try {
1023
+ if(cartObject.total >= offer.oo_min_amount){
1024
+ cartObject.discount = 0
1025
+ cartObject.delivery_discount = deliveryCost;
1026
+ cartObject.is_delivery_discount = true;
1027
+ }else{
1028
+ cartObject.discount = 0
1029
+ cartObject.delivery_discount = 0;
1030
+ cartObject.is_delivery_discount = false;
1031
+ }
1032
+ resolve(cartObject); // Resolve the promise with updated cartObject
1033
+ } catch (error) {
1034
+ reject(error)
1035
+ }
1036
+ })
1037
+ };
1038
+
1014
1039
  function setPackageDefaultDiscount(cart) {
1015
1040
  return new Promise(async (resolve, reject) => {
1016
1041
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
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": {