foodbot-cart-calculations 1.0.49 → 1.0.50
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/functions/pointsCalculation.js +18 -14
- package/package.json +1 -1
|
@@ -152,16 +152,19 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
152
152
|
if (item.isPackage == 1) {
|
|
153
153
|
if (item.point_discount_status) {
|
|
154
154
|
let promoDiscount = (item.promotion_discount) ? item.promotion_discount : 0;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
|
|
156
|
+
// For package items, calculate discount based on actual item price
|
|
157
|
+
let mainItemPrice = parseFloat(item.item_price) * item.quantity;
|
|
158
|
+
let mainItemDiscount = ((mainItemPrice - promoDiscount) * parseFloat(singlePriceDiscount));
|
|
159
|
+
mainItemDiscount = Math.max(0, mainItemDiscount);
|
|
160
|
+
mainItemDiscount = parseFloat(mainItemDiscount).toFixed(2);
|
|
161
|
+
|
|
162
|
+
// Cap main item discount
|
|
163
|
+
if (parseFloat(mainItemDiscount) > (mainItemPrice - promoDiscount)) {
|
|
164
|
+
mainItemDiscount = (mainItemPrice - promoDiscount).toFixed(2);
|
|
162
165
|
}
|
|
163
166
|
|
|
164
|
-
if (
|
|
167
|
+
if (parseFloat(mainItemDiscount) > 0)
|
|
165
168
|
indexes.push(index);
|
|
166
169
|
|
|
167
170
|
let totalPackageItemsDiscount = 0;
|
|
@@ -229,12 +232,13 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
229
232
|
}
|
|
230
233
|
});
|
|
231
234
|
|
|
232
|
-
// Set main package
|
|
233
|
-
|
|
234
|
-
item.
|
|
235
|
+
// CRITICAL FIX: Set main package discount to match the actual main item price
|
|
236
|
+
// This ensures tax calculation gets the correct discount amount
|
|
237
|
+
item.points_discount = mainItemDiscount;
|
|
238
|
+
item.points_discount_modifier = "0.00";
|
|
235
239
|
|
|
236
|
-
// Add to cart
|
|
237
|
-
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(
|
|
240
|
+
// Add main item discount to cart total (not package items discount)
|
|
241
|
+
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(mainItemDiscount);
|
|
238
242
|
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
239
243
|
}
|
|
240
244
|
} else {
|
|
@@ -243,7 +247,7 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
243
247
|
|
|
244
248
|
// --- Base item discount ---
|
|
245
249
|
let basePrice = parseFloat(item.item_price) * item.quantity;
|
|
246
|
-
let baseDiscount = ((basePrice - promoDiscount) * singlePriceDiscount);
|
|
250
|
+
let baseDiscount = ((basePrice - promoDiscount) * parseFloat(singlePriceDiscount));
|
|
247
251
|
baseDiscount = parseFloat(baseDiscount).toFixed(2);
|
|
248
252
|
|
|
249
253
|
// cap base discount
|
package/package.json
CHANGED