foodbot-cart-calculations 1.0.71 → 1.0.72
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.
- package/functions/promotionCalculation.js +2 -2
- package/index.js +17 -17
- package/package.json +1 -1
- package/response.json +257 -459
- package/sample.json +203 -3326
|
@@ -994,7 +994,7 @@ function getFixedPriceProductOffer(cartObject, offer) {
|
|
|
994
994
|
var offerAmount = 0;
|
|
995
995
|
var singleItemCost = element.item_price;
|
|
996
996
|
|
|
997
|
-
const maxQty = offer.max_quantity ||
|
|
997
|
+
const maxQty = offer.max_quantity || 1;
|
|
998
998
|
let remainingQty = maxQty - appliedQty;
|
|
999
999
|
const qtyToDiscount = Math.min(element.quantity, remainingQty);
|
|
1000
1000
|
|
|
@@ -1091,7 +1091,7 @@ function applyDiscountModifierPromotion(cartObject, offer) {
|
|
|
1091
1091
|
eligibleUnits.sort((a, b) => a.price - b.price);
|
|
1092
1092
|
|
|
1093
1093
|
// 4. Apply Discount up to Max Limit
|
|
1094
|
-
const maxLimit = offer.max_quantity || 1;
|
|
1094
|
+
const maxLimit = offer.en_id ? (offer.max_product || 1) : (offer.max_quantity || 1);
|
|
1095
1095
|
const discountValue = offer.oo_offer_value; // e.g., 100 for 100%
|
|
1096
1096
|
const unitsToDiscount = eligibleUnits.slice(0, maxLimit);
|
|
1097
1097
|
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const calculation = require('./calculations');
|
|
2
2
|
const { calculateItemWiseSplit, calculateHalfSplit } = require('./functions/taxCalculation');
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path')
|
|
5
5
|
|
|
6
6
|
async function calculateTax(inputJSON) {
|
|
7
7
|
return new Promise(async (resolve, reject) => {
|
|
@@ -76,24 +76,24 @@ async function calculateTax(inputJSON) {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
79
|
+
let json = JSON.parse(fs.readFileSync('./sample.json', 'utf8'));
|
|
80
|
+
calculateTax(json).then(res=>{
|
|
81
|
+
// console.log(JSON.stringify(res))
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const jsonResponse = JSON.stringify(res, null, 2); // Format the JSON with indentation
|
|
84
|
+
const filePath = path.join(__dirname, 'response.json'); // File path in the same directory
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
fs.writeFile(filePath, jsonResponse, 'utf8', err => {
|
|
87
|
+
if (err) {
|
|
88
|
+
console.error('Error writing to file:', err);
|
|
89
|
+
} else {
|
|
90
|
+
console.log('Response successfully written to response.json');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
}).catch(err=>{
|
|
95
|
+
console.log(err)
|
|
96
|
+
})
|
|
97
97
|
|
|
98
98
|
// calculateItemWiseSplit(json).then(res=>{
|
|
99
99
|
// // console.log(JSON.stringify(res))
|
package/package.json
CHANGED