foodbot-cart-calculations 1.0.18 → 1.0.19
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.
|
@@ -31,12 +31,13 @@ function offerCalculation(carts, offer) {
|
|
|
31
31
|
if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
|
|
32
32
|
getOfferDetails(carts, offer).then(res => {
|
|
33
33
|
carts = res
|
|
34
|
+
console.log("res",res)
|
|
34
35
|
if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
|
|
35
36
|
|
|
36
37
|
// offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
|
|
37
38
|
// offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
|
|
38
39
|
offer.oo_offer_type = 'absolute'
|
|
39
|
-
offer.oo_offer_value = Math.round(carts.discount)
|
|
40
|
+
offer.oo_offer_value = (carts && carts.discount)?Math.round(carts.discount):0
|
|
40
41
|
getOfferDetails(carts, offer).then(res => {
|
|
41
42
|
resolve(res)
|
|
42
43
|
}).catch(error=>{
|
|
@@ -452,7 +453,7 @@ function getOfferDetails(carts, offer = []) {
|
|
|
452
453
|
reject(error);
|
|
453
454
|
})
|
|
454
455
|
} else {
|
|
455
|
-
resolve(
|
|
456
|
+
resolve(carts);
|
|
456
457
|
}
|
|
457
458
|
} catch (error) {
|
|
458
459
|
reject(error)
|
|
@@ -477,7 +478,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
477
478
|
}
|
|
478
479
|
});
|
|
479
480
|
|
|
480
|
-
|
|
481
|
+
|
|
481
482
|
|
|
482
483
|
const totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
|
|
483
484
|
if (buyItems && parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) && desc.length > 1 && descending.length >= totalCount) {
|
|
@@ -489,17 +490,17 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
489
490
|
if (desc[i].buy && buyCount < offer.offer_products.buy_item_count && buyCount != offer.offer_products.buy_item_count) {
|
|
490
491
|
buyCount++;
|
|
491
492
|
desc1[i].remove = true;
|
|
492
|
-
|
|
493
|
+
// buyItemss.push(desc[i].item_id);
|
|
493
494
|
} else if (desc[i] && desc[i].get && getCount < offer.offer_products.get_item_count && getCount != offer.offer_products.get_item_count) {
|
|
494
495
|
let amt = 0;
|
|
495
496
|
let amtWithModi = 0;
|
|
496
|
-
getArray.push(desc[i].item_id);
|
|
497
|
+
// getArray.push(desc[i].item_id);
|
|
497
498
|
|
|
498
499
|
let itemIndex = -1;
|
|
499
500
|
if (desc[i]) itemIndex = carts.findIndex(obj => obj.item_id == desc[i].item.item_id && !obj.discount_status);
|
|
500
501
|
if (itemIndex == -1) itemIndex = carts.findIndex(obj => obj.item_id == desc[i].item.item_id);
|
|
501
502
|
|
|
502
|
-
|
|
503
|
+
|
|
503
504
|
|
|
504
505
|
if (offer.oo_offer_type === "percentage") {
|
|
505
506
|
let itemTotalDiscount = 0;
|
|
@@ -545,9 +546,11 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
545
546
|
carts[itemIndex].discount_status = true;
|
|
546
547
|
total = total + amtWithModi;
|
|
547
548
|
carts[itemIndex].redeem_promotion_id = offer.offer_id;
|
|
549
|
+
|
|
548
550
|
}
|
|
549
551
|
getCount++;
|
|
550
552
|
desc1[i].remove = true;
|
|
553
|
+
cartData.totalDiscount = total;
|
|
551
554
|
}
|
|
552
555
|
|
|
553
556
|
|
|
@@ -583,7 +586,7 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
583
586
|
|
|
584
587
|
if(i == desc.length -1){
|
|
585
588
|
|
|
586
|
-
cartData.discount = cartData.totalDiscount
|
|
589
|
+
cartData.discount = cartData.totalDiscount?cartData.totalDiscount:0;
|
|
587
590
|
resolve(cartData);
|
|
588
591
|
}
|
|
589
592
|
|
|
@@ -613,12 +616,14 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
613
616
|
function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total) {
|
|
614
617
|
return new Promise(function (resolve, reject) {
|
|
615
618
|
try {
|
|
619
|
+
console.log("ooooooooooooooo",JSON.parse(JSON.stringify(offer)))
|
|
616
620
|
let offerAmount = offer.oo_offer_value;
|
|
617
621
|
let singlePriceDiscount = offerAmount / buyItemAmount;
|
|
618
622
|
singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
|
|
619
623
|
let remaningOfferAmount = offer.oo_offer_value;
|
|
620
624
|
let count = 0;
|
|
621
625
|
let carts = cartObject.item_details;
|
|
626
|
+
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",buyItemss,total)
|
|
622
627
|
if(buyItemss && buyItemss.length>0){
|
|
623
628
|
buyItemss.forEach((element, buyIndex) => {
|
|
624
629
|
let itemAmount = 0;
|
|
@@ -630,8 +635,10 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
|
|
|
630
635
|
if (itemIndex == -1) itemIndex = carts.findIndex((obj) => {
|
|
631
636
|
return obj.item_id == element.item_id;
|
|
632
637
|
});
|
|
638
|
+
|
|
639
|
+
console.log("carts index",carts,itemIndex)
|
|
633
640
|
|
|
634
|
-
if (!carts[itemIndex].promotion_discount_modifier) carts[itemIndex].promotion_discount_modifier = 0;
|
|
641
|
+
if ( !carts[itemIndex].promotion_discount_modifier) carts[itemIndex].promotion_discount_modifier = 0;
|
|
635
642
|
|
|
636
643
|
if (element.item_modifiers && element.item_modifiers.length > 0 && offer.offer_products.order_modifiercost_use == 1) {
|
|
637
644
|
let modiCount = 0;
|
|
@@ -676,6 +683,7 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
|
|
|
676
683
|
carts[itemIndex].discount_applied = true;
|
|
677
684
|
|
|
678
685
|
if (buyItemss[buyItemss.length - 1].item_id == element.item_id) {
|
|
686
|
+
console.log("innnn ifffffffffffff",element.item_price,remaningOfferAmount)
|
|
679
687
|
|
|
680
688
|
itemAmount = (element.item_price < remaningOfferAmount) ? element.item_price : parseFloat(remaningOfferAmount).toFixed(2);
|
|
681
689
|
} else {
|
|
@@ -683,6 +691,7 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
|
|
|
683
691
|
}
|
|
684
692
|
|
|
685
693
|
itemAmount = parseFloat(itemAmount);
|
|
694
|
+
console.log("iiiiiiiiii",itemAmount)
|
|
686
695
|
total = parseFloat(total) + parseFloat(itemAmount);
|
|
687
696
|
total = parseFloat(total).toFixed(2);
|
|
688
697
|
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount);
|
|
@@ -693,10 +702,10 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
|
|
|
693
702
|
carts[itemIndex].redeem_promotion_id = offer.offer_id;
|
|
694
703
|
|
|
695
704
|
if (count == buyItemss.length) {
|
|
705
|
+
console.log("ttttttttttttttt",total)
|
|
696
706
|
cartObject.item_details = carts
|
|
697
707
|
cartObject.discount = total
|
|
698
|
-
|
|
699
|
-
|
|
708
|
+
|
|
700
709
|
resolve(cartObject);
|
|
701
710
|
}
|
|
702
711
|
});
|
package/package.json
CHANGED