foodbot-cart-calculations 1.0.34 → 1.0.36

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.
@@ -125,7 +125,7 @@ function getCategorySpeificOffer(carts, offer) {
125
125
  if (offer.offer_discount_type != 'manual')
126
126
  if (offer.offer_products.package_items) {
127
127
  offer.offer_products.package_items = offer.offer_products.package_items.map(function (x) {
128
- return parseInt(x, 10);
128
+ return (x);
129
129
  });
130
130
  }
131
131
  else {
@@ -134,7 +134,7 @@ function getCategorySpeificOffer(carts, offer) {
134
134
 
135
135
  let foundItemsSum = 0
136
136
  carts.item_details.filter((res) => {
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))) {
137
+ if (!res.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes((res.item_id)) && res.isPackage == 0) || (offer.offer_products.package_items.includes((res.item_id)) && res.isPackage == 1))) {
138
138
 
139
139
  foundItemsSum = foundItemsSum + res.item_price_with_modifier * res.quantity
140
140
  return foundItemsSum
@@ -145,7 +145,7 @@ function getCategorySpeificOffer(carts, offer) {
145
145
  let remaningOfferAmount = offerAmount
146
146
  carts.item_details.forEach((element, index) => {
147
147
 
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))) {
148
+ if (!element.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes((element.item_id)) && element.isPackage == 0) || (offer.offer_products.package_items.includes((element.item_id)) && element.isPackage == 1))) {
149
149
  var itemAmount = 0;
150
150
 
151
151
  // Apply discount on Packages
@@ -732,10 +732,10 @@ function addItemQuantity(items, offer) {
732
732
  try {
733
733
  var finalItems = [];
734
734
  var count = 0;
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));
735
+ offer.offer_products.offer_buy_products=offer.offer_products.offer_buy_products.map(item => (item));
736
+ offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item => (item));
737
737
  items.forEach(function (element) {
738
- if (offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)) || offer.offer_products.offer_get_products.includes(parseInt(element.item_id))) {
738
+ if (offer.offer_products.offer_buy_products.includes((element.item_id)) || offer.offer_products.offer_get_products.includes((element.item_id))) {
739
739
  for (var i = 1; i <= element.quantity; i++) {
740
740
  if (offer.offer_products.order_modifiercost_use == 1) {
741
741
  var amount = element.item_price;
@@ -744,7 +744,7 @@ function addItemQuantity(items, offer) {
744
744
  amount = element.item_price_with_modifier;
745
745
  } else {
746
746
  offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
747
- return parseInt(x, 10);
747
+ return (x);
748
748
  });
749
749
  var modifiers = [];
750
750
  element.item_modifiers.forEach(function (modifier) {
@@ -761,8 +761,8 @@ function addItemQuantity(items, offer) {
761
761
  'item_id': element.item_id,
762
762
  'amount': amount,
763
763
  'item': item,
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))
764
+ 'buy': offer.offer_products.offer_buy_products.includes((element.item_id)),
765
+ 'get': offer.offer_products.offer_get_products.includes((element.item_id))
766
766
  });
767
767
  } else {
768
768
  finalItems.push({
@@ -770,8 +770,8 @@ function addItemQuantity(items, offer) {
770
770
  'item_id': element.item_id,
771
771
  // / element.quantity
772
772
  'amount': element.item_price,
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))
773
+ 'buy': offer.offer_products.offer_buy_products.includes((element.item_id)),
774
+ 'get': offer.offer_products.offer_get_products.includes((element.item_id))
775
775
  });
776
776
  }
777
777
  }
@@ -815,13 +815,15 @@ function getFreeProductOffer(cartObject, offer) {
815
815
  offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
816
816
 
817
817
  var cartItem = carts;
818
-
819
818
  if (offer.offer_products.order_modifiercost_use == 1) {
820
819
  cartItem.sort(function (a, b) {
821
820
  return a.item_price_with_modifier / a.quantity > b.item_price_with_modifier / b.quantity ? 1 : -1;
822
821
  });
823
822
  } else {
824
823
  cartItem.sort(function (a, b) {
824
+ // If price is zero, move it to the end
825
+ if (a.item_price == 0) return 1;
826
+ if (b.item_price == 0) return -1;
825
827
  return a.item_price / a.quantity > b.item_price / b.quantity ? 1 : -1;
826
828
  });
827
829
  }
@@ -830,7 +832,7 @@ function getFreeProductOffer(cartObject, offer) {
830
832
  cartItem.forEach((element, index) => {
831
833
  var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
832
834
 
833
- if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id))) {
835
+ if (offer.offer_products.offer_discount_products.includes((element.item_id))) {
834
836
  var offerAmount = 0;
835
837
  let costWithOutModifier = 0;
836
838
  var singleItemCost = element.item_price;
@@ -850,7 +852,7 @@ function getFreeProductOffer(cartObject, offer) {
850
852
  });
851
853
  } else {
852
854
  offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
853
- return parseInt(x, 10);
855
+ return (x);
854
856
  });
855
857
 
856
858
  element.item_modifiers.forEach((modifier, modiIndex) => {
@@ -947,7 +949,7 @@ function getFixedPriceProductOffer(cartObject, offer) {
947
949
 
948
950
  cartItem.forEach((element, index) => {
949
951
  var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
950
- if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) || offer.offer_products.package_items.includes(parseInt(element.item_id))) {
952
+ if (offer.offer_products.offer_discount_products.includes((element.item_id)) || offer.offer_products.package_items.includes((element.item_id))) {
951
953
  var offerAmount = 0;
952
954
  var singleItemCost = element.item_price;
953
955
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
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": {