foodbot-cart-calculations 1.0.4-dev.1 → 1.0.5-dev.1
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 +12 -7
- package/package.json +1 -1
package/calculations.js
CHANGED
|
@@ -34,7 +34,8 @@ function applyDistribution(body) {
|
|
|
34
34
|
body.promotion_applied = body.promotions_applied
|
|
35
35
|
}
|
|
36
36
|
mainCart.store_value = 0;
|
|
37
|
-
|
|
37
|
+
const originalDeliveryDiscount = final.delivery_discount;
|
|
38
|
+
const originalIsDeliveryDiscount = final.is_delivery_discount;
|
|
38
39
|
pointsCalculation.getPointsDiscount(final, body.loyalty_points_details, body.user_detais, body.delivery_cost, body.service_amount).then(pointsCal => {
|
|
39
40
|
if (typeof (final.store_value) == "undefined" || isNaN(final.store_value))
|
|
40
41
|
final.store_value = 0
|
|
@@ -81,18 +82,22 @@ function applyDistribution(body) {
|
|
|
81
82
|
let delivery_cost = body.delivery_cost ? body.delivery_cost : 0;
|
|
82
83
|
let service_amount = body.service_amount ? body.service_amount : 0;
|
|
83
84
|
// Adjust delivery cost based on delivery discount
|
|
84
|
-
if (
|
|
85
|
-
delivery_cost = Math.max(0, delivery_cost -
|
|
86
|
-
body.delivery_cost = delivery_cost;
|
|
85
|
+
if (originalIsDeliveryDiscount) {
|
|
86
|
+
delivery_cost = Math.max(0, delivery_cost - parseFloat(originalDeliveryDiscount));
|
|
87
|
+
body.delivery_cost = delivery_cost;
|
|
88
|
+
mainCart.order_items.delivery_discount = parseFloat(originalDeliveryDiscount);
|
|
89
|
+
mainCart.order_items.is_delivery_discount = true;
|
|
90
|
+
console.log("✅ Applied delivery discount:", { delivery_cost, body_delivery_cost: body.delivery_cost, order_items: mainCart.order_items });
|
|
87
91
|
}
|
|
92
|
+
|
|
88
93
|
// Adjust service amount based on service discount
|
|
89
94
|
if (final.is_service_discount) {
|
|
90
95
|
service_amount = Math.max(0, service_amount - final.service_discount);
|
|
91
96
|
body.service_amount = service_amount;
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
//we took 2 value because in case of absolute we use tipValue
|
|
99
|
+
let tipValue = body.tip_value?body.tip_value:0;
|
|
100
|
+
let tipValueReq = body.tip_value?body.tip_value:0;
|
|
96
101
|
|
|
97
102
|
if (body.tip_type && body.tip_type == 'percentage') {
|
|
98
103
|
tipValue = (mainCart.final_amount * parseInt(tipValueReq)) / 100
|
package/package.json
CHANGED