foodbot-cart-calculations 1.0.59 → 1.0.61

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/calculations.js CHANGED
@@ -137,12 +137,15 @@ function applyDistribution(body) {
137
137
 
138
138
  if(mainCart.order_items && mainCart.order_items.item_details && mainCart.order_items.item_details.length > 0){
139
139
  mainCart.order_items.item_details.forEach((item) =>{
140
- let promoDisc = item.promotion_discount_modifier ?? 0;
141
- let pointItemDisc = item.points_discount ?? 0;
142
- let pointDisc = item.points_discount_modifier ?? 0;
143
- let totalDiscount = (parseFloat(promoDisc) + parseFloat(pointDisc) + parseFloat(pointItemDisc)).toFixed(2);
144
- let totalItemCost = (item.item_price_with_modifier * item.quantity).toFixed(2)
145
- item.total_item_cost = (totalItemCost - totalDiscount).toFixed(2)
140
+ const promoDisc = parseFloat(item.promotion_discount_modifier ?? 0);
141
+ const pointItemDisc = parseFloat(item.points_discount ?? 0);
142
+ const pointDisc = parseFloat(item.points_discount_modifier ?? 0);
143
+ const totalDiscount = promoDisc + pointDisc + pointItemDisc;
144
+ const totalItemCost = item.item_price_with_modifier * item.quantity;
145
+ const finalItemCost = totalItemCost - totalDiscount;
146
+
147
+ item.total_item_cost = +finalItemCost.toFixed(2);
148
+ item.per_item_cost = +(finalItemCost / item.quantity).toFixed(2);
146
149
  })
147
150
  }
148
151
  resolve(mainCart);
@@ -147,7 +147,9 @@ function getCategorySpeificOffer(carts, offer) {
147
147
  if(!res.purchase_points){
148
148
  let itemId = res.item_id?.toString().length > 10 ? res.item_id : parseInt(res.item_id);
149
149
  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))) {
150
- foundItemsSum = foundItemsSum + res.item_price_with_modifier * res.quantity
150
+ // let ItemPriceWithMod = res.item_price_with_modifier ? res.item_price_with_modifier : (res.item_price || res.item_cost)
151
+ let ItemPriceWithMod = res.item_price_with_modifier ?? res.item_price ?? res.item_cost;
152
+ foundItemsSum = foundItemsSum + ItemPriceWithMod * res.quantity
151
153
  return foundItemsSum
152
154
  }
153
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
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": {