foodbot-cart-calculations 1.0.38 → 1.0.39

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.
@@ -35,7 +35,7 @@ function offerCalculation(carts, offer) {
35
35
  if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
36
36
  getOfferDetails(carts, offer).then(res => {
37
37
  carts = res
38
- // console.log("res",res)
38
+ console.log("res",res)
39
39
  if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
40
40
 
41
41
  // offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
@@ -120,15 +120,12 @@ function getCategorySpeificOffer(carts, offer) {
120
120
  if (parseFloat(offer.oo_min_amount) <= parseFloat(afterTotal)) {
121
121
 
122
122
  if (offer.offer_discount_type != 'manual')
123
- // offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
124
- offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(x =>
125
- typeof x === "string" && !isNaN(x) ? Number(x) : x
126
- );
123
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
127
124
 
128
125
  if (offer.offer_discount_type != 'manual')
129
126
  if (offer.offer_products.package_items) {
130
127
  offer.offer_products.package_items = offer.offer_products.package_items.map(function (x) {
131
- return (x);
128
+ return parseInt(x, 10);
132
129
  });
133
130
  }
134
131
  else {
@@ -137,7 +134,7 @@ function getCategorySpeificOffer(carts, offer) {
137
134
 
138
135
  let foundItemsSum = 0
139
136
  carts.item_details.filter((res) => {
140
- if (!res.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(String(res.item_id)) && res.isPackage == 0) || (offer.offer_products.package_items.includes(String(res.item_id)) && res.isPackage == 1))) {
137
+ if (!res.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(parseInt(res.item_id)) && res.isPackage == 0) || (offer.offer_products.package_items.includes(parseInt(res.item_id)) && res.isPackage == 1))) {
141
138
 
142
139
  foundItemsSum = foundItemsSum + res.item_price_with_modifier * res.quantity
143
140
  return foundItemsSum
@@ -148,7 +145,7 @@ function getCategorySpeificOffer(carts, offer) {
148
145
  let remaningOfferAmount = offerAmount
149
146
  carts.item_details.forEach((element, index) => {
150
147
 
151
- if (!element.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(String(element.item_id)) && element.isPackage == 0) || (offer.offer_products.package_items.includes(String(element.item_id)) && element.isPackage == 1))) {
148
+ if (!element.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) && element.isPackage == 0) || (offer.offer_products.package_items.includes(parseInt(element.item_id)) && element.isPackage == 1))) {
152
149
  var itemAmount = 0;
153
150
 
154
151
  // Apply discount on Packages
@@ -362,7 +359,7 @@ function getCategorySpeificOffer(carts, offer) {
362
359
  count++
363
360
  }
364
361
 
365
- // console.log("count", total)
362
+ // console.log("count", count)
366
363
  if (count == carts.item_details.length && carts.item_details) {
367
364
  if ((Number(total) < Number(offerAmount) || Number(total) > Number(offerAmount)) && offer.oo_offer_type != 'percentage') {
368
365
  let difference = Number(offerAmount) - Number(total)
@@ -628,14 +625,14 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
628
625
  function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total) {
629
626
  return new Promise(function (resolve, reject) {
630
627
  try {
631
- // console.log("ooooooooooooooo",JSON.parse(JSON.stringify(offer)))
628
+ console.log("ooooooooooooooo",JSON.parse(JSON.stringify(offer)))
632
629
  let offerAmount = offer.oo_offer_value;
633
630
  let singlePriceDiscount = offerAmount / buyItemAmount;
634
631
  singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
635
632
  let remaningOfferAmount = offer.oo_offer_value;
636
633
  let count = 0;
637
634
  let carts = cartObject.item_details;
638
- // console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",buyItemss,total)
635
+ console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",buyItemss,total)
639
636
  if(buyItemss && buyItemss.length>0){
640
637
  buyItemss.forEach((element, buyIndex) => {
641
638
  let itemAmount = 0;
@@ -648,7 +645,7 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
648
645
  return obj.item_id == element.item_id;
649
646
  });
650
647
 
651
- // console.log("carts index",carts,itemIndex)
648
+ console.log("carts index",carts,itemIndex)
652
649
 
653
650
  if ( !carts[itemIndex].promotion_discount_modifier) carts[itemIndex].promotion_discount_modifier = 0;
654
651
 
@@ -735,10 +732,10 @@ function addItemQuantity(items, offer) {
735
732
  try {
736
733
  var finalItems = [];
737
734
  var count = 0;
738
- offer.offer_products.offer_buy_products=offer.offer_products.offer_buy_products.map(item => (item));
739
- offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item => (item));
735
+ offer.offer_products.offer_buy_products=offer.offer_products.offer_buy_products.map(item => parseInt(item, 10));
736
+ offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item => parseInt(item, 10));
740
737
  items.forEach(function (element) {
741
- if (offer.offer_products.offer_buy_products.includes(String(element.item_id)) || offer.offer_products.offer_get_products.includes(String(element.item_id))) {
738
+ if (offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)) || offer.offer_products.offer_get_products.includes(parseInt(element.item_id))) {
742
739
  for (var i = 1; i <= element.quantity; i++) {
743
740
  if (offer.offer_products.order_modifiercost_use == 1) {
744
741
  var amount = element.item_price;
@@ -747,11 +744,12 @@ function addItemQuantity(items, offer) {
747
744
  amount = element.item_price_with_modifier;
748
745
  } else {
749
746
  offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
750
- return (x);
747
+ return parseInt(x, 10);
751
748
  });
752
749
  var modifiers = [];
753
750
  element.item_modifiers.forEach(function (modifier) {
754
- if (offer.offer_products.modifier_category.includes(String(modifier.modifier_category_id))) {
751
+
752
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
755
753
  amount = amount + modifier.modifier_item_price;
756
754
  modifiers.push(modifier);
757
755
  }
@@ -763,8 +761,8 @@ function addItemQuantity(items, offer) {
763
761
  'item_id': element.item_id,
764
762
  'amount': amount,
765
763
  'item': item,
766
- 'buy': offer.offer_products.offer_buy_products.includes(String(element.item_id)),
767
- 'get': offer.offer_products.offer_get_products.includes(String(element.item_id))
764
+ 'buy': offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)),
765
+ 'get': offer.offer_products.offer_get_products.includes(parseInt(element.item_id))
768
766
  });
769
767
  } else {
770
768
  finalItems.push({
@@ -772,8 +770,8 @@ function addItemQuantity(items, offer) {
772
770
  'item_id': element.item_id,
773
771
  // / element.quantity
774
772
  'amount': element.item_price,
775
- 'buy': offer.offer_products.offer_buy_products.includes(String(element.item_id)),
776
- 'get': offer.offer_products.offer_get_products.includes(String(element.item_id))
773
+ 'buy': offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)),
774
+ 'get': offer.offer_products.offer_get_products.includes(parseInt(element.item_id))
777
775
  });
778
776
  }
779
777
  }
@@ -814,10 +812,7 @@ function getFreeProductOffer(cartObject, offer) {
814
812
  var total = 0;
815
813
  var count = 0;
816
814
  var offerAmount = offer.oo_offer_value;
817
- // offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
818
- offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(x =>
819
- typeof x === "string" && !isNaN(x) ? Number(x) : x
820
- );
815
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
821
816
 
822
817
  var cartItem = carts;
823
818
  if (offer.offer_products.order_modifiercost_use == 1) {
@@ -837,7 +832,7 @@ function getFreeProductOffer(cartObject, offer) {
837
832
  cartItem.forEach((element, index) => {
838
833
  var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
839
834
 
840
- if (offer.offer_products.offer_discount_products.includes(String(element.item_id))) {
835
+ if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id))) {
841
836
  var offerAmount = 0;
842
837
  let costWithOutModifier = 0;
843
838
  var singleItemCost = element.item_price;
@@ -857,11 +852,11 @@ function getFreeProductOffer(cartObject, offer) {
857
852
  });
858
853
  } else {
859
854
  offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
860
- return (x);
855
+ return parseInt(x, 10);
861
856
  });
862
857
 
863
858
  element.item_modifiers.forEach((modifier, modiIndex) => {
864
- if (offer.offer_products.modifier_category.includes(String(modifier.modifier_category_id))) {
859
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
865
860
  let singModPrice1 = modifier.modifier_item_price * modifier.quantity;
866
861
 
867
862
  if (!carts[ItemIndex].item_modifiers[modiIndex].promotion_discount)
@@ -947,20 +942,14 @@ function getFixedPriceProductOffer(cartObject, offer) {
947
942
  var count = 0;
948
943
  var fixedPrice = offer.oo_offer_value;
949
944
 
950
- // offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
951
- offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(x =>
952
- typeof x === "string" && !isNaN(x) ? Number(x) : x
953
- );
954
- // offer.offer_products.package_items = offer.offer_products.package_items.map(Number);
955
- offer.offer_products.package_items = offer.offer_products.package_items.map(x =>
956
- typeof x === "string" && !isNaN(x) ? Number(x) : x
957
- );
945
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
946
+ offer.offer_products.package_items = offer.offer_products.package_items.map(Number);
958
947
 
959
948
  var cartItem = carts;
960
949
 
961
950
  cartItem.forEach((element, index) => {
962
951
  var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
963
- if (offer.offer_products.offer_discount_products.includes(String(element.item_id)) || offer.offer_products.package_items.includes(String(element.item_id))) {
952
+ if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) || offer.offer_products.package_items.includes(parseInt(element.item_id))) {
964
953
  var offerAmount = 0;
965
954
  var singleItemCost = element.item_price;
966
955
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
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": {