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.
@@ -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
- let itemDiscount = ((item.item_price * item.quantity) - promoDiscount) * singlePriceDiscount;
156
- itemDiscount = parseFloat(itemDiscount).toFixed(2);
157
-
158
- // Cap item discount to not exceed actual item price
159
- let maxItemDiscount = (item.item_price * item.quantity) - promoDiscount;
160
- if (parseFloat(itemDiscount) > maxItemDiscount) {
161
- itemDiscount = parseFloat(maxItemDiscount).toFixed(2);
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 (itemDiscount > 0)
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 item discounts to reflect total of package items
233
- item.points_discount = parseFloat(totalPackageItemsDiscount).toFixed(2);
234
- item.points_discount_modifier = parseFloat(totalPackageModifiersDiscount).toFixed(2);
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-level total
237
- itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(totalPackageItemsDiscount) + parseFloat(totalPackageModifiersDiscount);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
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": {