@artisan-commerce/analytics-web 0.2.0-canary.63 → 0.2.0-canary.64

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.2.0-canary.64](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-web@0.2.0-canary.63...@artisan-commerce/analytics-web@0.2.0-canary.64) (2022-02-03)
7
+
8
+ **Note:** Version bump only for package @artisan-commerce/analytics-web
9
+
10
+
11
+
12
+
13
+
6
14
  ## [0.2.0-canary.63](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-web@0.2.0-canary.62...@artisan-commerce/analytics-web@0.2.0-canary.63) (2022-01-29)
7
15
 
8
16
  **Note:** Version bump only for package @artisan-commerce/analytics-web
@@ -39,7 +39,7 @@ const getState$2 = () => {
39
39
 
40
40
  var name = "@artisan-commerce/analytics-web";
41
41
  var description = "Artisn commerce analytics web library";
42
- var version = "0.2.0-canary.62";
42
+ var version = "0.2.0-canary.63";
43
43
  var main = "./dist/bundle.cjs.js";
44
44
  var module$1 = "./dist/bundle.esm.js";
45
45
  var types = "./dist/bundle.d.ts";
@@ -81,7 +81,7 @@ var dependencies = {
81
81
  };
82
82
  var devDependencies = {
83
83
  "@artisan-commerce/products": "0.9.0-canary.40",
84
- "@artisan-commerce/shopping-cart": "0.12.0-canary.59",
84
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.60",
85
85
  "@artisan-commerce/types": "0.14.0-canary.31"
86
86
  };
87
87
  var peerDependencies = {
@@ -1649,13 +1649,16 @@ const applyBenefits = (additionalInfo, benefits, shoppingCartTotals) => {
1649
1649
  }
1650
1650
  const benefitsValues = Object.values(benefits);
1651
1651
  return benefitsValues.reduce((acc, benefit) => {
1652
- if (benefit.type === "DISCOUNT") {
1653
- return applyBenefitByDiscount(benefit, acc, additionalInfo);
1652
+ if (benefit.type === "DISCOUNT_PERCENTAGE" && benefit.discountPercentage) {
1653
+ return applyBenefitByDiscountPercentage(benefit, acc, additionalInfo);
1654
+ }
1655
+ if (benefit.type === "DISCOUNT_FIXED" && benefit.discountFixed) {
1656
+ return applyBenefitByDiscountFixed(benefit, acc, additionalInfo);
1654
1657
  }
1655
1658
  return acc;
1656
1659
  }, shoppingCartTotals);
1657
1660
  };
1658
- const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) => {
1661
+ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additionalInfo) => {
1659
1662
  const { subtotal, total: prevTotal } = shoppingCartTotals;
1660
1663
  const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1661
1664
  const discountPercentage = benefit.discountPercentage * 0.01;
@@ -1678,6 +1681,26 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1678
1681
  total: newTotal
1679
1682
  });
1680
1683
  };
1684
+ const applyBenefitByDiscountFixed = (benefit, shoppingCartTotals, additionalInfo) => {
1685
+ const { total: prevTotal } = shoppingCartTotals;
1686
+ const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1687
+ const discountFixed = Number(benefit.discountFixed);
1688
+ if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1689
+ const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1690
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + discountFixed : discountFixed;
1691
+ const newTotal2 = (copayment - discountFixed).toFixed(4);
1692
+ return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1693
+ totalDiscounts: newTotalDiscounts2,
1694
+ total: Number(newTotal2)
1695
+ });
1696
+ }
1697
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + discountFixed : discountFixed;
1698
+ const newTotal = prevTotal - discountFixed;
1699
+ return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1700
+ totalDiscounts: newTotalDiscounts,
1701
+ total: newTotal
1702
+ });
1703
+ };
1681
1704
 
1682
1705
  const isBaseProduct = (product) => {
1683
1706
  const { attributes, description, name } = product;