foodbot-cart-calculations 1.0.41 → 1.0.42

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
@@ -8,6 +8,11 @@ function applyDistribution(body) {
8
8
  let mainCart = body
9
9
  let promotion = (body.promotion_applied && body.promotion_applied) ? body.promotion_applied : {};
10
10
  let deliveryCost = (body.delivery_cost && body.delivery_cost) ? body.delivery_cost : 0;
11
+
12
+ if(body?.order_items?.delivery_discount)
13
+ body.order_items.delivery_discount = 0
14
+ body.order_items.is_delivery_discount = false
15
+
11
16
  promoCalculation.setPackageDefaultDiscount(body.order_items).then(res => {
12
17
  promoCalculation.offerCalculation(res, promotion, deliveryCost).then(final => {
13
18
 
@@ -69,11 +74,11 @@ function applyDistribution(body) {
69
74
  }
70
75
  mainCart.order_items = taxData
71
76
 
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
+ let delivery_cost = body.delivery_cost ? body.delivery_cost : 0;
78
+ // Adjust delivery cost based on delivery discount
79
+ if (final.is_delivery_discount) {
80
+ delivery_cost = Math.max(0, delivery_cost - final.delivery_discount);
81
+ body.delivery_cost = delivery_cost; // Update body accordingly
77
82
  }
78
83
 
79
84
  let service_amount = body.service_amount?body.service_amount:0;
@@ -1018,23 +1018,35 @@ function getFixedPriceProductOffer(cartObject, offer) {
1018
1018
  };
1019
1019
 
1020
1020
  function getFreeDeliveryOffer(cartObject, offer, deliveryCost = 0) {
1021
- return new Promise(function (resolve, reject) {
1021
+ return new Promise((resolve, reject) => {
1022
1022
  try {
1023
- if(cartObject.total >= offer.oo_min_amount){
1024
- cartObject.discount = 0
1025
- cartObject.delivery_discount = deliveryCost;
1023
+ let discountRoundOff = offer.discount_roundoff; // 1 = Round off, 0 = No rounding
1024
+ let deliveryDiscount = 0; // Default
1025
+
1026
+ if (cartObject.total >= offer.oo_min_amount && offer.oo_offer_type == 'percentage' && offer.oo_offer_value > 0) {
1027
+ // Calculate discount as a percentage of delivery cost
1028
+ deliveryDiscount = (deliveryCost * offer.oo_offer_value) / 100;
1029
+
1030
+ // Apply rounding if discountRoundOff is 1
1031
+ if (discountRoundOff == 1) {
1032
+ deliveryDiscount = Math.round(deliveryDiscount);
1033
+ }
1034
+
1035
+ cartObject.discount = 0;
1036
+ cartObject.delivery_discount = deliveryDiscount;
1026
1037
  cartObject.is_delivery_discount = true;
1027
- }else{
1028
- cartObject.discount = 0
1038
+ } else {
1039
+ cartObject.discount = 0;
1029
1040
  cartObject.delivery_discount = 0;
1030
1041
  cartObject.is_delivery_discount = false;
1031
1042
  }
1032
- resolve(cartObject); // Resolve the promise with updated cartObject
1043
+
1044
+ resolve(cartObject); // Return updated cartObject
1033
1045
  } catch (error) {
1034
- reject(error)
1046
+ reject(error);
1035
1047
  }
1036
- })
1037
- };
1048
+ });
1049
+ }
1038
1050
 
1039
1051
  function setPackageDefaultDiscount(cart) {
1040
1052
  return new Promise(async (resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.41",
3
+ "version": "1.0.42",
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": {