@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.
- package/CHANGELOG.md +8 -0
- package/dist/bundle.cjs.js +22 -11
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.esm.js +22 -11
- package/dist/bundle.esm.js.map +1 -1
- package/dist/bundle.umd.js +22 -11
- package/dist/bundle.umd.js.map +1 -1
- package/package.json +5 -5
package/dist/bundle.esm.js
CHANGED
|
@@ -35,7 +35,7 @@ const getState$2 = () => {
|
|
|
35
35
|
|
|
36
36
|
var name = "@artisan-commerce/analytics-web";
|
|
37
37
|
var description = "Artisn commerce analytics web library";
|
|
38
|
-
var version = "0.2.0-canary.
|
|
38
|
+
var version = "0.2.0-canary.68";
|
|
39
39
|
var main = "./dist/bundle.cjs.js";
|
|
40
40
|
var module = "./dist/bundle.esm.js";
|
|
41
41
|
var types = "./dist/bundle.d.ts";
|
|
@@ -76,9 +76,9 @@ var dependencies = {
|
|
|
76
76
|
"snake-case": "^3.0.4"
|
|
77
77
|
};
|
|
78
78
|
var devDependencies = {
|
|
79
|
-
"@artisan-commerce/products": "0.9.0-canary.
|
|
80
|
-
"@artisan-commerce/shopping-cart": "0.12.0-canary.
|
|
81
|
-
"@artisan-commerce/types": "0.14.0-canary.
|
|
79
|
+
"@artisan-commerce/products": "0.9.0-canary.42",
|
|
80
|
+
"@artisan-commerce/shopping-cart": "0.12.0-canary.65",
|
|
81
|
+
"@artisan-commerce/types": "0.14.0-canary.33"
|
|
82
82
|
};
|
|
83
83
|
var peerDependencies = {
|
|
84
84
|
"@artisan-commerce/products": "*",
|
|
@@ -1610,7 +1610,7 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
|
|
|
1610
1610
|
total: acc.total + normal
|
|
1611
1611
|
};
|
|
1612
1612
|
}, initialValue);
|
|
1613
|
-
const totalsWithBenefits = applyBenefits(shoppingCart
|
|
1613
|
+
const totalsWithBenefits = applyBenefits(shoppingCart, totals);
|
|
1614
1614
|
const { shippingCost = shoppingCart.shippingCost } = config;
|
|
1615
1615
|
if (!shippingCost) {
|
|
1616
1616
|
return totalsWithBenefits;
|
|
@@ -1640,14 +1640,16 @@ const getShoppingCartProducts = (shoppingCart, storeId) => {
|
|
|
1640
1640
|
return [...acc, ...products];
|
|
1641
1641
|
}, []);
|
|
1642
1642
|
};
|
|
1643
|
-
const applyBenefits = (
|
|
1643
|
+
const applyBenefits = (shoppingCart, shoppingCartTotals) => {
|
|
1644
|
+
const additionalInfo = shoppingCart["additional_info"];
|
|
1645
|
+
const benefits = shoppingCart["benefits"];
|
|
1644
1646
|
if (!benefits) {
|
|
1645
1647
|
return shoppingCartTotals;
|
|
1646
1648
|
}
|
|
1647
1649
|
const benefitsValues = Object.values(benefits);
|
|
1648
1650
|
return benefitsValues.reduce((acc, benefit) => {
|
|
1649
1651
|
if (benefit.type === "DISCOUNT_PERCENTAGE" && benefit.discountPercentage) {
|
|
1650
|
-
return applyBenefitByDiscountPercentage(benefit, acc,
|
|
1652
|
+
return applyBenefitByDiscountPercentage(benefit, acc, shoppingCart);
|
|
1651
1653
|
}
|
|
1652
1654
|
if (benefit.type === "DISCOUNT_FIXED" && benefit.discountFixed) {
|
|
1653
1655
|
return applyBenefitByDiscountFixed(benefit, acc, additionalInfo);
|
|
@@ -1655,13 +1657,23 @@ const applyBenefits = (additionalInfo, benefits, shoppingCartTotals) => {
|
|
|
1655
1657
|
return acc;
|
|
1656
1658
|
}, shoppingCartTotals);
|
|
1657
1659
|
};
|
|
1658
|
-
const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals,
|
|
1660
|
+
const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, shoppingCart) => {
|
|
1661
|
+
let taxValue = 0;
|
|
1662
|
+
const additionalInfo = shoppingCart["additional_info"];
|
|
1663
|
+
const { billTotal } = shoppingCart;
|
|
1664
|
+
const { NORMAL } = billTotal;
|
|
1665
|
+
const { discounts } = NORMAL != null ? NORMAL : {};
|
|
1666
|
+
discounts == null ? void 0 : discounts.forEach((discount) => {
|
|
1667
|
+
if (discount.taxValue) {
|
|
1668
|
+
taxValue += discount.taxValue;
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1659
1671
|
const { subtotal, total: prevTotal } = shoppingCartTotals;
|
|
1660
1672
|
const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
|
|
1661
1673
|
const discountPercentage = benefit.discountPercentage * 0.01;
|
|
1662
1674
|
if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
|
|
1663
1675
|
const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
|
|
1664
|
-
const totalDiscount2 = copayment * discountPercentage;
|
|
1676
|
+
const totalDiscount2 = copayment * discountPercentage + taxValue;
|
|
1665
1677
|
const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
|
|
1666
1678
|
const newTotal2 = (copayment - totalDiscount2).toFixed(4);
|
|
1667
1679
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|
|
@@ -1669,8 +1681,7 @@ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additiona
|
|
|
1669
1681
|
total: Number(newTotal2)
|
|
1670
1682
|
});
|
|
1671
1683
|
}
|
|
1672
|
-
const
|
|
1673
|
-
const totalDiscount = newSubtotal;
|
|
1684
|
+
const totalDiscount = subtotal * discountPercentage + taxValue;
|
|
1674
1685
|
const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
|
|
1675
1686
|
const newTotal = prevTotal - totalDiscount;
|
|
1676
1687
|
return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
|