@tapcart/mobile-components 0.8.51 → 0.8.53
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/dist/lib/cart.util.d.ts.map +1 -1
- package/dist/lib/cart.util.js +12 -11
- package/dist/lib/cart.util.test.js +1 -1
- package/dist/lib/variablesCart.util.d.ts +3 -3
- package/dist/lib/variablesCart.util.d.ts.map +1 -1
- package/dist/lib/variablesCart.util.js +59 -26
- package/dist/styles.css +0 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAE7B,cAAc,EACf,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,eAAe;cAKhB,MAAM;aACP,cAAc;;0BAEH;YAChB,gBAAgB,CAAC,EAAE;gBACjB,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,cAAc,CAAC,EAAE;gBACf,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;SACF,EAAE;;;;;;;CAgCN,CAAA;
|
|
1
|
+
{"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAE7B,cAAc,EACf,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,eAAe;cAKhB,MAAM;aACP,cAAc;;0BAEH;YAChB,gBAAgB,CAAC,EAAE;gBACjB,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,cAAc,CAAC,EAAE;gBACf,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;SACF,EAAE;;;;;;;CAgCN,CAAA;AAuCD,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAMpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAMlE,CAAA;AAoHD,MAAM,MAAM,cAAc,GAAG;IAC3B,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAUrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,KAAG,cA8B1D,CAAA;AAGD,eAAO,MAAM,mBAAmB;eACnB,MAAM;;;;;aAEG,MAAM;eAAS,MAAM;;;;oBAIN,MAAM;0BAAgB,MAAM;;;eAElD,MAAM;;;;;gBAML,MAAM;cACR,MAAM;;cAEN,MAAM;;;0BAIM;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE;oBAC9C,MAAM;;;;YAsCzB,CAAA"}
|
package/dist/lib/cart.util.js
CHANGED
|
@@ -45,9 +45,7 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
45
45
|
name: `Discount - ${code}`,
|
|
46
46
|
type: "ORDER_LEVEL",
|
|
47
47
|
}))
|
|
48
|
-
.filter((discount) => cart.discounts
|
|
49
|
-
.map((d) => d.toUpperCase())
|
|
50
|
-
.includes(discount.id.toUpperCase()));
|
|
48
|
+
.filter((discount) => { var _a, _b; return (_b = (_a = cart.discounts) === null || _a === void 0 ? void 0 : _a.map((d) => d)) === null || _b === void 0 ? void 0 : _b.includes(discount === null || discount === void 0 ? void 0 : discount.id); });
|
|
51
49
|
};
|
|
52
50
|
const getShippingDiscounts = (cart) => {
|
|
53
51
|
var _a;
|
|
@@ -72,11 +70,14 @@ export const isLineItemDiscount = (code, cart) => {
|
|
|
72
70
|
};
|
|
73
71
|
const getAppliedGiftCards = (cart) => {
|
|
74
72
|
var _a;
|
|
75
|
-
return (_a = cart.appliedGiftCards) === null || _a === void 0 ? void 0 : _a.map((giftCard) =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
return (_a = cart.appliedGiftCards) === null || _a === void 0 ? void 0 : _a.map((giftCard) => {
|
|
74
|
+
var _a;
|
|
75
|
+
return ({
|
|
76
|
+
id: giftCard === null || giftCard === void 0 ? void 0 : giftCard.id,
|
|
77
|
+
amount: +((_a = giftCard === null || giftCard === void 0 ? void 0 : giftCard.amountUsed) === null || _a === void 0 ? void 0 : _a.amount) || 0,
|
|
78
|
+
name: `Gift Card - ${giftCard === null || giftCard === void 0 ? void 0 : giftCard.lastCharacters}`,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
80
81
|
};
|
|
81
82
|
const getSalesAmount = (cart) => {
|
|
82
83
|
var _a;
|
|
@@ -93,8 +94,8 @@ const getSalesAmount = (cart) => {
|
|
|
93
94
|
}, 0);
|
|
94
95
|
};
|
|
95
96
|
const getLineItemDiscounts = (cart) => {
|
|
96
|
-
var _a
|
|
97
|
-
const discountMap = (
|
|
97
|
+
var _a;
|
|
98
|
+
const discountMap = ((cart === null || cart === void 0 ? void 0 : cart.items) || []).reduce((acc, item) => {
|
|
98
99
|
var _a;
|
|
99
100
|
(_a = item === null || item === void 0 ? void 0 : item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
|
|
100
101
|
const code = discount === null || discount === void 0 ? void 0 : discount.code;
|
|
@@ -113,7 +114,7 @@ const getLineItemDiscounts = (cart) => {
|
|
|
113
114
|
}, {});
|
|
114
115
|
if (!discountMap)
|
|
115
116
|
return [];
|
|
116
|
-
return (
|
|
117
|
+
return (_a = Object.entries(discountMap)) === null || _a === void 0 ? void 0 : _a.map(([code, { amount, type, readOnly }]) => ({
|
|
117
118
|
id: code,
|
|
118
119
|
name: `Discount - ${code}`,
|
|
119
120
|
amount,
|
|
@@ -145,7 +145,7 @@ describe("cart-provider.util", () => {
|
|
|
145
145
|
], deliveryGroups: [] });
|
|
146
146
|
const result = getCalculatedCartData(mockCart);
|
|
147
147
|
// 100 (compare) - 10 (discount) - 20 (sale) - 5 (gift card) = 65
|
|
148
|
-
expect(result.totalDiscountedPrice).toBe(
|
|
148
|
+
expect(result.totalDiscountedPrice).toBe(135);
|
|
149
149
|
});
|
|
150
150
|
it("should never return negative or NaN values for totalDiscountedPrice", () => {
|
|
151
151
|
// Test case 1: Normal case with valid data
|
|
@@ -17,8 +17,8 @@ export declare const getVariablesVariantPrice: ({ variantPrice, variantCompareAt
|
|
|
17
17
|
currency: string;
|
|
18
18
|
isSale: boolean;
|
|
19
19
|
};
|
|
20
|
-
export declare const isVariablesOrderLevelDiscount: (code: string, cart: CartState) => boolean;
|
|
21
|
-
export declare const isVariablesLineItemDiscount: (code: string, cart: CartState) => boolean;
|
|
20
|
+
export declare const isVariablesOrderLevelDiscount: (code: string, cart: CartState | null) => boolean;
|
|
21
|
+
export declare const isVariablesLineItemDiscount: (code: string, cart: CartState | null) => boolean;
|
|
22
22
|
export type VariablesCalculatedData = {
|
|
23
23
|
orderAndLineItemDiscounts: CartCalculatedDiscount[];
|
|
24
24
|
appliedGiftCards: CartCalculatedAppliedGiftCard[];
|
|
@@ -31,5 +31,5 @@ export type VariablesCalculatedData = {
|
|
|
31
31
|
totalSavedAmount: number;
|
|
32
32
|
};
|
|
33
33
|
export declare const DEFAULT_VARIABLES_CALCULATED_DATA: VariablesCalculatedData;
|
|
34
|
-
export declare const getVariablesCalculatedCartData: (cart: CartState) => VariablesCalculatedData;
|
|
34
|
+
export declare const getVariablesCalculatedCartData: (cart: CartState | null) => VariablesCalculatedData;
|
|
35
35
|
//# sourceMappingURL=variablesCart.util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variablesCart.util.d.ts","sourceRoot":"","sources":["../../lib/variablesCart.util.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6BAA6B,EAO9B,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,wBAAwB;kBAOrB,MAAM;2BACG,MAAM;cACnB,MAAM;kBACF,MAAM;;0BAEA;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;;CA4BN,CAAA;
|
|
1
|
+
{"version":3,"file":"variablesCart.util.d.ts","sourceRoot":"","sources":["../../lib/variablesCart.util.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6BAA6B,EAO9B,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,wBAAwB;kBAOrB,MAAM;2BACG,MAAM;cACnB,MAAM;kBACF,MAAM;;0BAEA;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;;CA4BN,CAAA;AAyED,eAAO,MAAM,6BAA6B,SAClC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAED,eAAO,MAAM,2BAA2B,SAChC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AA2KD,MAAM,MAAM,uBAAuB,GAAG;IACpC,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,iCAAiC,EAAE,uBAU/C,CAAA;AAED,eAAO,MAAM,8BAA8B,SACnC,SAAS,GAAG,IAAI,KACrB,uBAmCF,CAAA"}
|
|
@@ -25,6 +25,9 @@ export const getVariablesVariantPrice = ({ variantPrice, variantCompareAtPrice,
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
const getOrderLevelDiscounts = (cart) => {
|
|
28
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
29
|
+
if (!cart)
|
|
30
|
+
return [];
|
|
28
31
|
// CartState doesn't have discountAllocations directly
|
|
29
32
|
// Need to check if cart has discountAllocations property
|
|
30
33
|
const discountAllocations = cart === null || cart === void 0 ? void 0 : cart.discountAllocations;
|
|
@@ -33,21 +36,21 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
33
36
|
const discountMap = discountAllocations
|
|
34
37
|
.filter((discount) => discount.targetType !== DiscountApplicationTargetType.ShippingLine)
|
|
35
38
|
.reduce((acc, discount) => {
|
|
36
|
-
var _a, _b, _c;
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
40
|
// Handle both traditional format and new format with kind.manual.code
|
|
38
41
|
let code = "unknown";
|
|
39
42
|
if (discount.code) {
|
|
40
|
-
code = discount.code.toUpperCase();
|
|
43
|
+
code = ((discount === null || discount === void 0 ? void 0 : discount.code) || "").toUpperCase();
|
|
41
44
|
}
|
|
42
45
|
else if ((_b = (_a = discount.kind) === null || _a === void 0 ? void 0 : _a.manual) === null || _b === void 0 ? void 0 : _b.code) {
|
|
43
|
-
code = discount.kind.manual.code.toUpperCase();
|
|
46
|
+
code = (((_d = (_c = discount === null || discount === void 0 ? void 0 : discount.kind) === null || _c === void 0 ? void 0 : _c.manual) === null || _d === void 0 ? void 0 : _d.code) || "").toUpperCase();
|
|
44
47
|
}
|
|
45
48
|
if (!acc[code]) {
|
|
46
49
|
acc[code] = 0;
|
|
47
50
|
}
|
|
48
51
|
// Handle both formats for amount
|
|
49
|
-
if ((
|
|
50
|
-
acc[code] += parseFloat(discount.discountedAmount.amount || "0");
|
|
52
|
+
if ((_e = discount.discountedAmount) === null || _e === void 0 ? void 0 : _e.amount) {
|
|
53
|
+
acc[code] += parseFloat(((_f = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _f === void 0 ? void 0 : _f.amount) || "0");
|
|
51
54
|
}
|
|
52
55
|
else if (discount.amount) {
|
|
53
56
|
acc[code] += parseFloat(String(discount.amount));
|
|
@@ -56,20 +59,19 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
56
59
|
}, {});
|
|
57
60
|
if (!discountMap)
|
|
58
61
|
return [];
|
|
59
|
-
return Object.entries(discountMap)
|
|
60
|
-
.map(([code, amount]) => ({
|
|
62
|
+
return Object.entries(discountMap).map(([code, amount]) => ({
|
|
61
63
|
id: code,
|
|
62
64
|
amount: amount,
|
|
63
65
|
name: `Discount - ${code}`,
|
|
64
66
|
type: "ORDER_LEVEL",
|
|
65
|
-
}))
|
|
66
|
-
.filter((discount) => cart.discounts
|
|
67
|
-
.map((d) => d.toUpperCase())
|
|
68
|
-
.includes(discount.id.toUpperCase()));
|
|
67
|
+
}));
|
|
69
68
|
};
|
|
70
69
|
const getShippingDiscounts = (cart) => {
|
|
70
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
71
|
+
if (!cart)
|
|
72
|
+
return [];
|
|
71
73
|
// CartState doesn't have discountAllocations directly
|
|
72
|
-
const discountAllocations = cart.discountAllocations;
|
|
74
|
+
const discountAllocations = cart === null || cart === void 0 ? void 0 : cart.discountAllocations;
|
|
73
75
|
if (!discountAllocations)
|
|
74
76
|
return [];
|
|
75
77
|
return discountAllocations
|
|
@@ -84,36 +86,53 @@ const getShippingDiscounts = (cart) => {
|
|
|
84
86
|
});
|
|
85
87
|
};
|
|
86
88
|
export const isVariablesOrderLevelDiscount = (code, cart) => {
|
|
89
|
+
// Handle null cart gracefully - return false if cart is null
|
|
90
|
+
if (!cart)
|
|
91
|
+
return false;
|
|
87
92
|
const orderLevelDiscounts = getOrderLevelDiscounts(cart);
|
|
88
93
|
return orderLevelDiscounts.some((discount) => (discount.id || "").toUpperCase() === (code || "").toUpperCase());
|
|
89
94
|
};
|
|
90
95
|
export const isVariablesLineItemDiscount = (code, cart) => {
|
|
96
|
+
// Handle null cart gracefully - return false if cart is null
|
|
97
|
+
if (!cart)
|
|
98
|
+
return false;
|
|
91
99
|
const lineItemDiscounts = getLineItemDiscounts(cart);
|
|
92
100
|
return lineItemDiscounts.some((discount) => (discount.id || "").toUpperCase() === (code || "").toUpperCase());
|
|
93
101
|
};
|
|
94
102
|
const getAppliedGiftCards = (cart) => {
|
|
103
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
104
|
+
if (!cart)
|
|
105
|
+
return [];
|
|
95
106
|
// Access appliedGiftCards directly from CartState
|
|
96
107
|
const appliedGiftCards = cart === null || cart === void 0 ? void 0 : cart.appliedGiftCards;
|
|
97
108
|
if (!appliedGiftCards ||
|
|
98
109
|
!Array.isArray(appliedGiftCards) ||
|
|
99
110
|
appliedGiftCards.length === 0)
|
|
100
111
|
return [];
|
|
101
|
-
return appliedGiftCards.map((giftCard) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
return appliedGiftCards.map((giftCard) => {
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
return ({
|
|
115
|
+
id: giftCard === null || giftCard === void 0 ? void 0 : giftCard.id,
|
|
116
|
+
amount: (_b = +((_a = giftCard === null || giftCard === void 0 ? void 0 : giftCard.amountUsed) === null || _a === void 0 ? void 0 : _a.amount)) !== null && _b !== void 0 ? _b : 0,
|
|
117
|
+
name: `Gift Card - ${(_c = giftCard === null || giftCard === void 0 ? void 0 : giftCard.lastCharacters) !== null && _c !== void 0 ? _c : "xxxx"}`,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
106
120
|
};
|
|
107
121
|
const getSalesAmount = (cart) => {
|
|
108
|
-
|
|
122
|
+
var _a;
|
|
123
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
124
|
+
if (!cart)
|
|
125
|
+
return 0;
|
|
126
|
+
return (_a = cart === null || cart === void 0 ? void 0 : cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
|
|
127
|
+
var _a, _b;
|
|
109
128
|
// Get price and compareAtPrice directly from the CartItem
|
|
110
|
-
const itemPrice = parseFloat((item.price || 0).toString());
|
|
111
|
-
const itemCompareAtPrice = parseFloat((item.compareAtPrice || 0).toString());
|
|
129
|
+
const itemPrice = parseFloat(((item === null || item === void 0 ? void 0 : item.price) || 0).toString());
|
|
130
|
+
const itemCompareAtPrice = parseFloat(((item === null || item === void 0 ? void 0 : item.compareAtPrice) || 0).toString());
|
|
112
131
|
// Create a custom sellingPlanAllocation if the item has one
|
|
113
132
|
let customSellingPlanAllocation;
|
|
114
|
-
if (item.sellingPlanAllocation) {
|
|
133
|
+
if (item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) {
|
|
115
134
|
customSellingPlanAllocation = {
|
|
116
|
-
priceAdjustments: item.sellingPlanAllocation.priceAdjustments.map((adj) => ({
|
|
135
|
+
priceAdjustments: (_b = (_a = item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) === null || _a === void 0 ? void 0 : _a.priceAdjustments) === null || _b === void 0 ? void 0 : _b.map((adj) => ({
|
|
117
136
|
price: parseFloat(adj.price.amount),
|
|
118
137
|
compareAtPrice: adj.compareAtPrice
|
|
119
138
|
? parseFloat(adj.compareAtPrice.amount)
|
|
@@ -125,10 +144,10 @@ const getSalesAmount = (cart) => {
|
|
|
125
144
|
};
|
|
126
145
|
}
|
|
127
146
|
const { compareAtPrice, price } = getVariablesVariantPrice({
|
|
128
|
-
quantity: item.quantity || 1,
|
|
147
|
+
quantity: (item === null || item === void 0 ? void 0 : item.quantity) || 1,
|
|
129
148
|
variantPrice: itemPrice,
|
|
130
149
|
variantCompareAtPrice: itemCompareAtPrice,
|
|
131
|
-
currencyCode: item.currencyCode || "USD",
|
|
150
|
+
currencyCode: (item === null || item === void 0 ? void 0 : item.currencyCode) || "USD",
|
|
132
151
|
sellingPlanAllocation: customSellingPlanAllocation,
|
|
133
152
|
});
|
|
134
153
|
if (compareAtPrice && compareAtPrice > price) {
|
|
@@ -139,7 +158,10 @@ const getSalesAmount = (cart) => {
|
|
|
139
158
|
};
|
|
140
159
|
const getLineItemDiscounts = (cart) => {
|
|
141
160
|
var _a;
|
|
142
|
-
|
|
161
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
162
|
+
if (!cart)
|
|
163
|
+
return [];
|
|
164
|
+
const discountMap = ((cart === null || cart === void 0 ? void 0 : cart.items) || []).reduce((acc, item) => {
|
|
143
165
|
var _a;
|
|
144
166
|
(_a = item === null || item === void 0 ? void 0 : item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
|
|
145
167
|
const code = discount === null || discount === void 0 ? void 0 : discount.code;
|
|
@@ -173,7 +195,11 @@ const getGiftCardsTotalAmount = (appliedGiftCards) => {
|
|
|
173
195
|
return appliedGiftCards === null || appliedGiftCards === void 0 ? void 0 : appliedGiftCards.reduce((acc, giftCard) => acc + +giftCard.amount, 0);
|
|
174
196
|
};
|
|
175
197
|
const getTotalCompareAtPrice = (cart) => {
|
|
176
|
-
|
|
198
|
+
var _a;
|
|
199
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
200
|
+
if (!cart)
|
|
201
|
+
return 0;
|
|
202
|
+
return (_a = cart === null || cart === void 0 ? void 0 : cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
|
|
177
203
|
// Get compareAtPrice directly from the CartItem
|
|
178
204
|
const itemCompareAtPrice = item.compareAtPrice ||
|
|
179
205
|
(item.price ? parseFloat(item.price.toString()) : 0);
|
|
@@ -195,6 +221,9 @@ const getTotalDiscountedPrice = (totalCompareAtPrice, discountsTotalAmount, sale
|
|
|
195
221
|
return isNaN(total) ? 0 : Math.max(0, total);
|
|
196
222
|
};
|
|
197
223
|
const getTotalSavedAmount = (cart) => {
|
|
224
|
+
// Handle null cart gracefully - the shopping cart state can be null sometimes
|
|
225
|
+
if (!cart)
|
|
226
|
+
return 0;
|
|
198
227
|
const salesAmount = getSalesAmount(cart);
|
|
199
228
|
const totalDiscountsAmount = getDiscountsTotalAmount(getOrderLevelDiscounts(cart).concat(getLineItemDiscounts(cart)));
|
|
200
229
|
const totalGiftCardsAmount = getGiftCardsTotalAmount(getAppliedGiftCards(cart));
|
|
@@ -213,6 +242,10 @@ export const DEFAULT_VARIABLES_CALCULATED_DATA = {
|
|
|
213
242
|
totalSavedAmount: 0,
|
|
214
243
|
};
|
|
215
244
|
export const getVariablesCalculatedCartData = (cart) => {
|
|
245
|
+
// Handle null cart gracefully - return default data to prevent crashes
|
|
246
|
+
if (!cart) {
|
|
247
|
+
return DEFAULT_VARIABLES_CALCULATED_DATA;
|
|
248
|
+
}
|
|
216
249
|
const orderAndLineItemDiscounts = getOrderLevelDiscounts(cart).concat(getLineItemDiscounts(cart));
|
|
217
250
|
const appliedGiftCards = getAppliedGiftCards(cart);
|
|
218
251
|
const isFreeShipping = getShippingDiscounts(cart).length > 0;
|
package/dist/styles.css
CHANGED
|
@@ -2189,10 +2189,6 @@ video {
|
|
|
2189
2189
|
.text-textColors-strikethroughPriceText {
|
|
2190
2190
|
color: var(--textColors-strikethroughPriceText);
|
|
2191
2191
|
}
|
|
2192
|
-
.text-white {
|
|
2193
|
-
--tw-text-opacity: 1;
|
|
2194
|
-
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
|
2195
|
-
}
|
|
2196
2192
|
.underline {
|
|
2197
2193
|
text-decoration-line: underline;
|
|
2198
2194
|
}
|