foodbot-cart-calculations 1.0.6 → 1.0.7

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.
@@ -32,8 +32,9 @@ function offerCalculation(carts, offer) {
32
32
  getOfferDetails(carts, offer).then(res => {
33
33
  carts = res
34
34
  if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
35
- offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
36
- offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
35
+
36
+ // offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
37
+ // offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
37
38
  offer.oo_offer_type = 'absolute'
38
39
  offer.oo_offer_value = Math.round(carts.discount)
39
40
  getOfferDetails(carts, offer).then(res => {
@@ -53,8 +54,8 @@ function offerCalculation(carts, offer) {
53
54
  carts = res
54
55
 
55
56
  if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
56
- offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
57
- offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
57
+ // offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
58
+ // offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
58
59
  offer.oo_offer_type = 'absolute'
59
60
  offer.oo_offer_value = Math.round(carts.discount)
60
61
  getCategorySpeificOffer(carts, offer).then(res => {
@@ -398,8 +399,8 @@ function getOfferDetails(carts, offer = []) {
398
399
  return new Promise(function (resolve, reject) {
399
400
  try {
400
401
  // buyItemAmount = 0
401
- buyItemss = []
402
- total = 0
402
+ // buyItemss = []
403
+ // total = 0
403
404
 
404
405
  offer.offer_products.get_item_count = parseInt(offer.offer_products.get_item_count);
405
406
  offer.offer_products.buy_item_count = parseInt(offer.offer_products.buy_item_count);
@@ -432,18 +433,21 @@ function getOfferDetails(carts, offer = []) {
432
433
  a.promotion_discount_modifier = 0;
433
434
  a.discount_applied = false;
434
435
  });
435
- let total = 0;
436
+
436
437
  const loopArray = [];
437
438
  const offerBuyProducts = offer.offer_products.offer_buy_products.map(Number);
438
439
  const offerGetProducts = offer.offer_products.offer_get_products.map(Number);
439
440
  addItemQuantity(carts.item_details, offer).then((data) => {
440
441
  const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? -1 : 1);
441
- getBuyxGetYOnCondition(descending, carts, offer).then((total) => {
442
- carts.discount = carts.totalDiscount
442
+ let total = 0
443
+ let buyItemAmount=0;
444
+ let buyItemss =[]
445
+ getBuyxGetYOnCondition(descending, carts, offer,total,buyItemAmount,buyItemss).then((total) => {
446
+ // carts.discount = carts.totalDiscount
443
447
  resolve(carts)
444
448
  }).catch(error => {
445
449
  reject(error)
446
- });;
450
+ });
447
451
  }).catch(error => {
448
452
  reject(error);
449
453
  })
@@ -456,7 +460,7 @@ function getOfferDetails(carts, offer = []) {
456
460
  })
457
461
  };
458
462
 
459
- function getBuyxGetYOnCondition(descending, cartData, offer) {
463
+ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
460
464
  return new Promise(function (resolve, reject) {
461
465
 
462
466
  try {
@@ -466,8 +470,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
466
470
  var amount = 0;
467
471
  var buyArray = [];
468
472
  var getArray = [];
469
- let total = 0
470
- let buyItemAmount=0;
473
+
471
474
 
472
475
  if (!cartData.totalDiscount)
473
476
  cartData.totalDiscount = 0
@@ -478,14 +481,11 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
478
481
  }
479
482
  });
480
483
 
484
+
485
+
481
486
  let totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
482
487
 
483
- if (
484
- buyItems &&
485
- parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) &&
486
- desc.length > 1 &&
487
- descending.length >= totalCount
488
- ) {
488
+ if (buyItems && parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) && desc.length > 1 && descending.length >= totalCount) {
489
489
  var buyCount = 0;
490
490
  var getCount = 0;
491
491
 
@@ -620,10 +620,9 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
620
620
  }
621
621
  });
622
622
 
623
- console.log('dddddddddfilterItem', filterItem)
624
623
 
625
624
  cartData.item_details = carts
626
- getBuyxGetYOnCondition(filterItem, cartData, offer).then((data) => {
625
+ getBuyxGetYOnCondition(filterItem, cartData, offer,total,buyItemAmount,buyItemss).then((data) => {
627
626
  resolve(data)
628
627
  }).catch(error => {
629
628
  reject(error);
@@ -632,7 +631,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
632
631
  } else {
633
632
  if (offer.oo_offer_type == 'absolute') {
634
633
  cartData.item_details = carts
635
- getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount).then((data) => {
634
+ getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount,total).then((data) => {
636
635
  resolve(data);
637
636
  }).catch(error => {
638
637
  reject(error);
@@ -654,7 +653,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
654
653
  } else {
655
654
  if (offer.oo_offer_type == 'absolute') {
656
655
  cartData.item_details = carts
657
- getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount).then((data) => {
656
+ getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount,total).then((data) => {
658
657
  resolve(data);
659
658
  }).catch(error => {
660
659
  reject(error);
@@ -680,7 +679,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer) {
680
679
  });
681
680
  };
682
681
 
683
- function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount) {
682
+ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total) {
684
683
  return new Promise(function (resolve, reject) {
685
684
  try {
686
685
  let offerAmount = offer.oo_offer_value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
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": {