foodbot-cart-calculations 1.0.51 → 1.0.52

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.
@@ -247,7 +247,8 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
247
247
  let basePrice = parseFloat(item.item_price) * item.quantity;
248
248
  let baseDiscount = ((basePrice - promoDiscount) * parseFloat(singlePriceDiscount));
249
249
  baseDiscount = parseFloat(baseDiscount).toFixed(2);
250
-
250
+ console.log("singlePriceDiscount -->", singlePriceDiscount);
251
+ console.log("baseDiscount -->", baseDiscount);
251
252
  // cap base discount
252
253
  if (parseFloat(baseDiscount) > basePrice) {
253
254
  baseDiscount = basePrice.toFixed(2);
@@ -266,6 +267,7 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
266
267
  let modiBase = parseFloat(modi.modifier_item_price) * modi.quantity * item.quantity;
267
268
  let modiDiscount = ((modiBase - modiPromoDiscount) * parseFloat(singlePriceDiscount));
268
269
  modiDiscount = parseFloat(modiDiscount).toFixed(2);
270
+ console.log("modiDiscount -->", modiDiscount);
269
271
 
270
272
  // cap modifier
271
273
  if (parseFloat(modiDiscount) > modiBase) {
@@ -298,6 +300,17 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
298
300
  }
299
301
  });
300
302
 
303
+ if ((Number(itemTotalDicount) < Number(pointsAmount) || Number(itemTotalDicount) > Number(pointsAmount)) && pointsAmount > 0 && itemTotalDicount > 0) {
304
+ let difference = Number(pointsAmount) - Number(itemTotalDicount);
305
+ difference = parseFloat(difference).toFixed(2);
306
+ if (indexes.length > 0 && difference) {
307
+ carts[indexes[0]].points_discount = (difference > 0) ? parseFloat(carts[indexes[0]].points_discount) + parseFloat(difference) : parseFloat(carts[indexes[0]].points_discount) - Math.abs(difference);
308
+ carts[indexes[0]].points_discount = parseFloat(carts[indexes[0]].points_discount).toFixed(2);
309
+ itemTotalDicount = (difference < 0) ? itemTotalDicount + difference : itemTotalDicount - Math.abs(difference);
310
+ itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
311
+ }
312
+ }
313
+
301
314
  cartObject.item_details = carts
302
315
  cartObject.store_value = pointsAmount
303
316
  cartObject.point_discount_amount = pointsAmount
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
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": {