@artisan-commerce/analytics-web 0.2.0-canary.68 → 0.2.0-canary.69

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.
@@ -41,7 +41,7 @@
41
41
 
42
42
  var name = "@artisan-commerce/analytics-web";
43
43
  var description = "Artisn commerce analytics web library";
44
- var version = "0.2.0-canary.67";
44
+ var version = "0.2.0-canary.68";
45
45
  var main = "./dist/bundle.cjs.js";
46
46
  var module = "./dist/bundle.esm.js";
47
47
  var types = "./dist/bundle.d.ts";
@@ -82,9 +82,9 @@
82
82
  "snake-case": "^3.0.4"
83
83
  };
84
84
  var devDependencies = {
85
- "@artisan-commerce/products": "0.9.0-canary.41",
86
- "@artisan-commerce/shopping-cart": "0.12.0-canary.64",
87
- "@artisan-commerce/types": "0.14.0-canary.32"
85
+ "@artisan-commerce/products": "0.9.0-canary.42",
86
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.65",
87
+ "@artisan-commerce/types": "0.14.0-canary.33"
88
88
  };
89
89
  var peerDependencies = {
90
90
  "@artisan-commerce/products": "*",
@@ -1616,7 +1616,7 @@ ${key}: ${value}`;
1616
1616
  total: acc.total + normal
1617
1617
  };
1618
1618
  }, initialValue);
1619
- const totalsWithBenefits = applyBenefits(shoppingCart == null ? void 0 : shoppingCart.additional_info, shoppingCart == null ? void 0 : shoppingCart.benefits, totals);
1619
+ const totalsWithBenefits = applyBenefits(shoppingCart, totals);
1620
1620
  const { shippingCost = shoppingCart.shippingCost } = config;
1621
1621
  if (!shippingCost) {
1622
1622
  return totalsWithBenefits;
@@ -1646,14 +1646,16 @@ ${key}: ${value}`;
1646
1646
  return [...acc, ...products];
1647
1647
  }, []);
1648
1648
  };
1649
- const applyBenefits = (additionalInfo, benefits, shoppingCartTotals) => {
1649
+ const applyBenefits = (shoppingCart, shoppingCartTotals) => {
1650
+ const additionalInfo = shoppingCart["additional_info"];
1651
+ const benefits = shoppingCart["benefits"];
1650
1652
  if (!benefits) {
1651
1653
  return shoppingCartTotals;
1652
1654
  }
1653
1655
  const benefitsValues = Object.values(benefits);
1654
1656
  return benefitsValues.reduce((acc, benefit) => {
1655
1657
  if (benefit.type === "DISCOUNT_PERCENTAGE" && benefit.discountPercentage) {
1656
- return applyBenefitByDiscountPercentage(benefit, acc, additionalInfo);
1658
+ return applyBenefitByDiscountPercentage(benefit, acc, shoppingCart);
1657
1659
  }
1658
1660
  if (benefit.type === "DISCOUNT_FIXED" && benefit.discountFixed) {
1659
1661
  return applyBenefitByDiscountFixed(benefit, acc, additionalInfo);
@@ -1661,13 +1663,23 @@ ${key}: ${value}`;
1661
1663
  return acc;
1662
1664
  }, shoppingCartTotals);
1663
1665
  };
1664
- const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additionalInfo) => {
1666
+ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, shoppingCart) => {
1667
+ let taxValue = 0;
1668
+ const additionalInfo = shoppingCart["additional_info"];
1669
+ const { billTotal } = shoppingCart;
1670
+ const { NORMAL } = billTotal;
1671
+ const { discounts } = NORMAL != null ? NORMAL : {};
1672
+ discounts == null ? void 0 : discounts.forEach((discount) => {
1673
+ if (discount.taxValue) {
1674
+ taxValue += discount.taxValue;
1675
+ }
1676
+ });
1665
1677
  const { subtotal, total: prevTotal } = shoppingCartTotals;
1666
1678
  const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1667
1679
  const discountPercentage = benefit.discountPercentage * 0.01;
1668
1680
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1669
1681
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1670
- const totalDiscount2 = copayment * discountPercentage;
1682
+ const totalDiscount2 = copayment * discountPercentage + taxValue;
1671
1683
  const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1672
1684
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1673
1685
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
@@ -1675,8 +1687,7 @@ ${key}: ${value}`;
1675
1687
  total: Number(newTotal2)
1676
1688
  });
1677
1689
  }
1678
- const newSubtotal = subtotal * discountPercentage;
1679
- const totalDiscount = newSubtotal;
1690
+ const totalDiscount = subtotal * discountPercentage + taxValue;
1680
1691
  const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1681
1692
  const newTotal = prevTotal - totalDiscount;
1682
1693
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {