foodbot-cart-calculations 1.0.38 → 1.0.40

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))
@@ -55,6 +55,7 @@ function offerCalculation(carts, offer) {
55
55
  reject(error);
56
56
  })
57
57
  } else if (offer && offer.offer_discount_type && (offer.offer_discount_type == 'discount' || offer.offer_discount_type == 'manual')) {
58
+
58
59
  getCategorySpeificOffer(carts, offer).then(res => {
59
60
  carts = res
60
61
 
@@ -120,16 +121,15 @@ function getCategorySpeificOffer(carts, offer) {
120
121
  if (parseFloat(offer.oo_min_amount) <= parseFloat(afterTotal)) {
121
122
 
122
123
  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
- );
124
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(val =>
125
+ val.toString().length > 10 ? val : Number(val)
126
+ );
127
127
 
128
128
  if (offer.offer_discount_type != 'manual')
129
129
  if (offer.offer_products.package_items) {
130
- offer.offer_products.package_items = offer.offer_products.package_items.map(function (x) {
131
- return (x);
132
- });
130
+ offer.offer_products.package_items = offer.offer_products.package_items.map(x =>
131
+ x.toString().length > 10 ? x : parseInt(x, 10)
132
+ );
133
133
  }
134
134
  else {
135
135
  offer.offer_products.package_items = []
@@ -137,7 +137,8 @@ function getCategorySpeificOffer(carts, offer) {
137
137
 
138
138
  let foundItemsSum = 0
139
139
  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))) {
140
+ let itemId = res.item_id.toString().length > 10 ? res.item_id : parseInt(res.item_id);
141
+ if (!res.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(itemId) && res.isPackage == 0) || (offer.offer_products.package_items.includes(itemId) && res.isPackage == 1))) {
141
142
 
142
143
  foundItemsSum = foundItemsSum + res.item_price_with_modifier * res.quantity
143
144
  return foundItemsSum
@@ -147,8 +148,8 @@ function getCategorySpeificOffer(carts, offer) {
147
148
  let offerAmount = (offer.oo_offer_value <= foundItemsSum) ? offer.oo_offer_value : foundItemsSum;
148
149
  let remaningOfferAmount = offerAmount
149
150
  carts.item_details.forEach((element, index) => {
150
-
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))) {
151
+ let itemId = element.item_id.toString().length > 10 ? element.item_id : parseInt(element.item_id);
152
+ if (!element.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(itemId) && element.isPackage == 0) || (offer.offer_products.package_items.includes(itemId) && element.isPackage == 1))) {
152
153
  var itemAmount = 0;
153
154
 
154
155
  // Apply discount on Packages
@@ -362,7 +363,7 @@ function getCategorySpeificOffer(carts, offer) {
362
363
  count++
363
364
  }
364
365
 
365
- // console.log("count", total)
366
+ // console.log("count", count)
366
367
  if (count == carts.item_details.length && carts.item_details) {
367
368
  if ((Number(total) < Number(offerAmount) || Number(total) > Number(offerAmount)) && offer.oo_offer_type != 'percentage') {
368
369
  let difference = Number(offerAmount) - Number(total)
@@ -628,14 +629,14 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
628
629
  function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total) {
629
630
  return new Promise(function (resolve, reject) {
630
631
  try {
631
- // console.log("ooooooooooooooo",JSON.parse(JSON.stringify(offer)))
632
+ console.log("ooooooooooooooo",JSON.parse(JSON.stringify(offer)))
632
633
  let offerAmount = offer.oo_offer_value;
633
634
  let singlePriceDiscount = offerAmount / buyItemAmount;
634
635
  singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
635
636
  let remaningOfferAmount = offer.oo_offer_value;
636
637
  let count = 0;
637
638
  let carts = cartObject.item_details;
638
- // console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",buyItemss,total)
639
+ console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",buyItemss,total)
639
640
  if(buyItemss && buyItemss.length>0){
640
641
  buyItemss.forEach((element, buyIndex) => {
641
642
  let itemAmount = 0;
@@ -648,7 +649,7 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
648
649
  return obj.item_id == element.item_id;
649
650
  });
650
651
 
651
- // console.log("carts index",carts,itemIndex)
652
+ console.log("carts index",carts,itemIndex)
652
653
 
653
654
  if ( !carts[itemIndex].promotion_discount_modifier) carts[itemIndex].promotion_discount_modifier = 0;
654
655
 
@@ -735,10 +736,15 @@ function addItemQuantity(items, offer) {
735
736
  try {
736
737
  var finalItems = [];
737
738
  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));
739
+ offer.offer_products.offer_buy_products=offer.offer_products.offer_buy_products.map(item =>
740
+ item.toString().length > 10 ? item : parseInt(item, 10)
741
+ );
742
+ offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item =>
743
+ item.toString().length > 10 ? item : parseInt(item, 10)
744
+ );
740
745
  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))) {
746
+ let itemId = element.item_id.toString().length > 10 ? element.item_id : parseInt(element.item_id);
747
+ if (offer.offer_products.offer_buy_products.includes(itemId) || offer.offer_products.offer_get_products.includes(itemId)) {
742
748
  for (var i = 1; i <= element.quantity; i++) {
743
749
  if (offer.offer_products.order_modifiercost_use == 1) {
744
750
  var amount = element.item_price;
@@ -746,12 +752,13 @@ function addItemQuantity(items, offer) {
746
752
  if (offer.offer_products.modifier_category.includes('all') || offer.offer_products.modifier_category.includes('All')) {
747
753
  amount = element.item_price_with_modifier;
748
754
  } else {
749
- offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
750
- return (x);
751
- });
755
+ offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(x =>
756
+ x.toString().length > 10 ? x : parseInt(x, 10)
757
+ );
752
758
  var modifiers = [];
753
759
  element.item_modifiers.forEach(function (modifier) {
754
- if (offer.offer_products.modifier_category.includes(String(modifier.modifier_category_id))) {
760
+
761
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
755
762
  amount = amount + modifier.modifier_item_price;
756
763
  modifiers.push(modifier);
757
764
  }
@@ -763,8 +770,8 @@ function addItemQuantity(items, offer) {
763
770
  'item_id': element.item_id,
764
771
  'amount': amount,
765
772
  '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))
773
+ 'buy': offer.offer_products.offer_buy_products.includes(itemId),
774
+ 'get': offer.offer_products.offer_get_products.includes(itemId)
768
775
  });
769
776
  } else {
770
777
  finalItems.push({
@@ -772,8 +779,8 @@ function addItemQuantity(items, offer) {
772
779
  'item_id': element.item_id,
773
780
  // / element.quantity
774
781
  '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))
782
+ 'buy': offer.offer_products.offer_buy_products.includes(itemId),
783
+ 'get': offer.offer_products.offer_get_products.includes(itemId)
777
784
  });
778
785
  }
779
786
  }
@@ -814,9 +821,8 @@ function getFreeProductOffer(cartObject, offer) {
814
821
  var total = 0;
815
822
  var count = 0;
816
823
  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
824
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(val =>
825
+ val.toString().length > 10 ? val : Number(val)
820
826
  );
821
827
 
822
828
  var cartItem = carts;
@@ -837,7 +843,8 @@ function getFreeProductOffer(cartObject, offer) {
837
843
  cartItem.forEach((element, index) => {
838
844
  var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
839
845
 
840
- if (offer.offer_products.offer_discount_products.includes(String(element.item_id))) {
846
+ let itemId = element.item_id.toString().length > 10 ? element.item_id : parseInt(element.item_id);
847
+ if (offer.offer_products.offer_discount_products.includes(itemId)) {
841
848
  var offerAmount = 0;
842
849
  let costWithOutModifier = 0;
843
850
  var singleItemCost = element.item_price;
@@ -856,12 +863,12 @@ function getFreeProductOffer(cartObject, offer) {
856
863
  singleItemCost = singleItemCost + singModPrice;
857
864
  });
858
865
  } else {
859
- offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
860
- return (x);
861
- });
866
+ offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(x =>
867
+ x.toString().length > 10 ? x : parseInt(x, 10)
868
+ );
862
869
 
863
870
  element.item_modifiers.forEach((modifier, modiIndex) => {
864
- if (offer.offer_products.modifier_category.includes(String(modifier.modifier_category_id))) {
871
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
865
872
  let singModPrice1 = modifier.modifier_item_price * modifier.quantity;
866
873
 
867
874
  if (!carts[ItemIndex].item_modifiers[modiIndex].promotion_discount)
@@ -947,20 +954,19 @@ function getFixedPriceProductOffer(cartObject, offer) {
947
954
  var count = 0;
948
955
  var fixedPrice = offer.oo_offer_value;
949
956
 
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
957
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(val =>
958
+ val.toString().length > 10 ? val : Number(val)
953
959
  );
954
- // offer.offer_products.package_items = offer.offer_products.package_items.map(Number);
955
960
  offer.offer_products.package_items = offer.offer_products.package_items.map(x =>
956
- typeof x === "string" && !isNaN(x) ? Number(x) : x
957
- );
961
+ x.toString().length > 10 ? x : parseInt(x, 10)
962
+ );
958
963
 
959
964
  var cartItem = carts;
960
965
 
961
966
  cartItem.forEach((element, index) => {
962
967
  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))) {
968
+ let itemId = element.item_id.toString().length > 10 ? element.item_id : parseInt(element.item_id);
969
+ if (offer.offer_products.offer_discount_products.includes(itemId) || offer.offer_products.package_items.includes(itemId)) {
964
970
  var offerAmount = 0;
965
971
  var singleItemCost = element.item_price;
966
972
 
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.40",
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": {