@artisan-commerce/analytics-rn 0.3.0-canary.69 → 0.3.0-canary.70

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.3.0-canary.70](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-rn@0.3.0-canary.69...@artisan-commerce/analytics-rn@0.3.0-canary.70) (2022-04-05)
7
+
8
+ **Note:** Version bump only for package @artisan-commerce/analytics-rn
9
+
10
+
11
+
12
+
13
+
6
14
  ## [0.3.0-canary.69](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-rn@0.3.0-canary.68...@artisan-commerce/analytics-rn@0.3.0-canary.69) (2022-03-07)
7
15
 
8
16
  **Note:** Version bump only for package @artisan-commerce/analytics-rn
@@ -49,7 +49,7 @@ const getState$2 = () => {
49
49
 
50
50
  var name = "@artisan-commerce/analytics-rn";
51
51
  var description = "Artisn commerce analytics react native library";
52
- var version = "0.3.0-canary.69";
52
+ var version = "0.3.0-canary.70";
53
53
  var main = "./dist/bundle.esm.js";
54
54
  var module$1 = "./dist/bundle.esm.js";
55
55
  var types = "./dist/bundle.d.ts";
@@ -91,9 +91,9 @@ var dependencies = {
91
91
  "snake-case": "^3.0.4"
92
92
  };
93
93
  var devDependencies = {
94
- "@artisan-commerce/products": "0.9.0-canary.42",
95
- "@artisan-commerce/shopping-cart": "0.12.0-canary.65",
96
- "@artisan-commerce/types": "0.14.0-canary.33",
94
+ "@artisan-commerce/products": "0.9.0-canary.43",
95
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.66",
96
+ "@artisan-commerce/types": "0.14.0-canary.34",
97
97
  "@babel/core": "^7.13.15",
98
98
  "@babel/preset-env": "^7.10.4",
99
99
  "@babel/preset-react": "^7.10.4",
@@ -112,7 +112,7 @@ var peerDependencies = {
112
112
  react: ">=16.8.6",
113
113
  "react-native-fbsdk-next": "*"
114
114
  };
115
- var gitHead = "0f7d112c16f14207b4ac0c92606736e8bf6618a8";
115
+ var gitHead = "bd05f9bb540ac313d058fb96936fa3810f7cc103";
116
116
  var packageJSON = {
117
117
  name: name,
118
118
  description: description,
@@ -1482,7 +1482,7 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1482
1482
  total: acc.total + normal
1483
1483
  };
1484
1484
  }, initialValue);
1485
- const totalsWithBenefits = applyBenefits(shoppingCart == null ? void 0 : shoppingCart.additional_info, shoppingCart == null ? void 0 : shoppingCart.benefits, totals);
1485
+ const totalsWithBenefits = applyBenefits(shoppingCart, totals);
1486
1486
  const { shippingCost = shoppingCart.shippingCost } = config;
1487
1487
  if (!shippingCost) {
1488
1488
  return totalsWithBenefits;
@@ -1512,14 +1512,16 @@ const getShoppingCartProducts = (shoppingCart, storeId) => {
1512
1512
  return [...acc, ...products];
1513
1513
  }, []);
1514
1514
  };
1515
- const applyBenefits = (additionalInfo, benefits, shoppingCartTotals) => {
1515
+ const applyBenefits = (shoppingCart, shoppingCartTotals) => {
1516
+ const additionalInfo = shoppingCart["additional_info"];
1517
+ const benefits = shoppingCart["benefits"];
1516
1518
  if (!benefits) {
1517
1519
  return shoppingCartTotals;
1518
1520
  }
1519
1521
  const benefitsValues = Object.values(benefits);
1520
1522
  return benefitsValues.reduce((acc, benefit) => {
1521
1523
  if (benefit.type === "DISCOUNT_PERCENTAGE" && benefit.discountPercentage) {
1522
- return applyBenefitByDiscountPercentage(benefit, acc, additionalInfo);
1524
+ return applyBenefitByDiscountPercentage(benefit, acc, shoppingCart);
1523
1525
  }
1524
1526
  if (benefit.type === "DISCOUNT_FIXED" && benefit.discountFixed) {
1525
1527
  return applyBenefitByDiscountFixed(benefit, acc, additionalInfo);
@@ -1527,13 +1529,23 @@ const applyBenefits = (additionalInfo, benefits, shoppingCartTotals) => {
1527
1529
  return acc;
1528
1530
  }, shoppingCartTotals);
1529
1531
  };
1530
- const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additionalInfo) => {
1532
+ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, shoppingCart) => {
1533
+ let taxValue = 0;
1534
+ const additionalInfo = shoppingCart["additional_info"];
1535
+ const { billTotal } = shoppingCart;
1536
+ const { NORMAL } = billTotal;
1537
+ const { discounts } = NORMAL != null ? NORMAL : {};
1538
+ discounts == null ? void 0 : discounts.forEach((discount) => {
1539
+ if (discount.taxValue) {
1540
+ taxValue += discount.taxValue;
1541
+ }
1542
+ });
1531
1543
  const { subtotal, total: prevTotal } = shoppingCartTotals;
1532
1544
  const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1533
1545
  const discountPercentage = benefit.discountPercentage * 0.01;
1534
1546
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1535
1547
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1536
- const totalDiscount2 = copayment * discountPercentage;
1548
+ const totalDiscount2 = copayment * discountPercentage + taxValue;
1537
1549
  const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1538
1550
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1539
1551
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
@@ -1541,8 +1553,7 @@ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additiona
1541
1553
  total: Number(newTotal2)
1542
1554
  });
1543
1555
  }
1544
- const newSubtotal = subtotal * discountPercentage;
1545
- const totalDiscount = newSubtotal;
1556
+ const totalDiscount = subtotal * discountPercentage + taxValue;
1546
1557
  const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1547
1558
  const newTotal = prevTotal - totalDiscount;
1548
1559
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {