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