@tapcart/mobile-components 0.12.0 → 0.12.1
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.
|
@@ -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,2BAA2B;;cAM5B,MAAM;;0BAEI;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;CAyBN,CAAA;AA4FD,eAAO,MAAM,6BAA6B,SAClC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAED,eAAO,MAAM,2BAA2B,SAChC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,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,2BAA2B;;cAM5B,MAAM;;0BAEI;YAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;YACzB,KAAK,EAAE,MAAM,CAAA;YACb,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,EAAE;;;;;;CAyBN,CAAA;AA4FD,eAAO,MAAM,6BAA6B,SAClC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAED,eAAO,MAAM,2BAA2B,SAChC,MAAM,QACN,SAAS,GAAG,IAAI,YAUvB,CAAA;AAoMD,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"}
|
|
@@ -139,6 +139,7 @@ const getCompareAtPriceDifference = (cart) => {
|
|
|
139
139
|
*/
|
|
140
140
|
let itemPrice = (item === null || item === void 0 ? void 0 : item.price) || 0;
|
|
141
141
|
let itemCompareAtPrice = (item === null || item === void 0 ? void 0 : item.compareAtPrice) || 0;
|
|
142
|
+
const quantity = (item === null || item === void 0 ? void 0 : item.quantity) || 1;
|
|
142
143
|
/**
|
|
143
144
|
* Subscription price details
|
|
144
145
|
*/
|
|
@@ -147,16 +148,24 @@ const getCompareAtPriceDifference = (cart) => {
|
|
|
147
148
|
((_e = (_d = (_c = item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) === null || _c === void 0 ? void 0 : _c.priceAdjustments[0]) === null || _d === void 0 ? void 0 : _d.perDeliveryPrice) === null || _e === void 0 ? void 0 : _e.amount) ||
|
|
148
149
|
((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) === null || _f === void 0 ? void 0 : _f.priceAdjustments[0]) === null || _g === void 0 ? void 0 : _g.price) === null || _h === void 0 ? void 0 : _h.amount) ||
|
|
149
150
|
0;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
// Only use selling plan's compareAtPrice if variant doesn't have one
|
|
152
|
+
// This ensures we show savings vs the original retail price, not vs the subscription price
|
|
153
|
+
if (!itemCompareAtPrice) {
|
|
154
|
+
const { compareAtPrice } = getSubscriptionPriceDetails({
|
|
155
|
+
quantity,
|
|
156
|
+
sellingPlanAllocation: item === null || item === void 0 ? void 0 : item.sellingPlanAllocation,
|
|
157
|
+
});
|
|
158
|
+
// getSubscriptionPriceDetails returns a total (already multiplied by quantity)
|
|
159
|
+
// So we need to calculate the savings directly without multiplying again
|
|
160
|
+
if (compareAtPrice && compareAtPrice > itemPrice * quantity) {
|
|
161
|
+
return acc + (compareAtPrice - itemPrice * quantity);
|
|
162
|
+
}
|
|
163
|
+
return acc;
|
|
156
164
|
}
|
|
157
165
|
}
|
|
166
|
+
// For variant compareAtPrice, it's a unit price, so multiply by quantity
|
|
158
167
|
if (itemPrice && itemCompareAtPrice && itemCompareAtPrice > itemPrice) {
|
|
159
|
-
return
|
|
168
|
+
return acc + (itemCompareAtPrice * quantity - itemPrice * quantity);
|
|
160
169
|
}
|
|
161
170
|
return acc;
|
|
162
171
|
}, 0);
|
|
@@ -216,14 +225,21 @@ const getTotalCompareAtPrice = (cart) => {
|
|
|
216
225
|
* Subscription price details
|
|
217
226
|
*/
|
|
218
227
|
if (((_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.length) > 0) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
228
|
+
// Only use selling plan's compareAtPrice if variant doesn't have one
|
|
229
|
+
// This ensures we show savings vs the original retail price, not vs the subscription price
|
|
230
|
+
if (!(item === null || item === void 0 ? void 0 : item.compareAtPrice)) {
|
|
231
|
+
const { compareAtPrice } = getSubscriptionPriceDetails({
|
|
232
|
+
quantity,
|
|
233
|
+
sellingPlanAllocation: item === null || item === void 0 ? void 0 : item.sellingPlanAllocation,
|
|
234
|
+
});
|
|
235
|
+
// getSubscriptionPriceDetails returns a total (already multiplied by quantity)
|
|
236
|
+
// So return it directly without multiplying again
|
|
237
|
+
if (compareAtPrice) {
|
|
238
|
+
return acc + compareAtPrice;
|
|
239
|
+
}
|
|
225
240
|
}
|
|
226
241
|
}
|
|
242
|
+
// For variant compareAtPrice, it's a unit price, so multiply by quantity
|
|
227
243
|
return acc + itemCompareAtPrice * quantity;
|
|
228
244
|
}, 0);
|
|
229
245
|
};
|
|
@@ -597,8 +597,8 @@ describe("cart-provider.util", () => {
|
|
|
597
597
|
},
|
|
598
598
|
] });
|
|
599
599
|
const result = getVariablesCalculatedCartData(subscriptionCart);
|
|
600
|
-
expect(result.totalCompareAtPrice).toBe(
|
|
601
|
-
expect(result.salesAmount).toBe(
|
|
600
|
+
expect(result.totalCompareAtPrice).toBe(15); // Using variant's compareAtPrice (15) instead of selling plan's compareAtPrice (10)
|
|
601
|
+
expect(result.salesAmount).toBe(6.5); // (15-8.5) * 1 = 6.5 - savings vs variant's retail price
|
|
602
602
|
});
|
|
603
603
|
it("should handle mixed discounts and gift cards", () => {
|
|
604
604
|
const mixedCart = Object.assign(Object.assign({}, baseCartData), { items: [
|
package/dist/styles.css
CHANGED