@anker-in/shopify-react 1.2.2-beta.6 → 1.2.2-beta.8
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/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +20 -20
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -19
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -20
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -1
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/index.js +14 -15
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +13 -14
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-Bzg8_e4k.d.mts → types-DfR13pDe.d.mts} +2 -1
- package/dist/{types-Bzg8_e4k.d.ts → types-DfR13pDe.d.ts} +2 -1
- package/package.json +5 -5
package/dist/hooks/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import useSWRMutation from 'swr/mutation';
|
|
|
3
3
|
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, removeCartLines, getLocalStorage, updateCartLines, updateCartAttributes, updateBuyerIdentity, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
4
4
|
import Cookies5 from 'js-cookie';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
import
|
|
6
|
+
import Decimal3 from 'decimal.js';
|
|
7
7
|
import { atobID, btoaID } from '@anker-in/shopify-core';
|
|
8
8
|
import useSWR from 'swr';
|
|
9
9
|
import { useRequest } from 'ahooks';
|
|
@@ -63,8 +63,6 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
63
63
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
64
64
|
var MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
|
|
65
65
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
66
|
-
|
|
67
|
-
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
68
66
|
function normalizeAddToCartLines(lines) {
|
|
69
67
|
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
70
68
|
const variant = line.variant;
|
|
@@ -72,8 +70,8 @@ function normalizeAddToCartLines(lines) {
|
|
|
72
70
|
const quantity = line.quantity || 1;
|
|
73
71
|
const originalPrice = variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
74
72
|
const finalPrice = variant.finalPrice?.amount === void 0 ? originalPrice : Number(variant.finalPrice?.amount);
|
|
75
|
-
const subtotalAmount = originalPrice
|
|
76
|
-
const totalAmount = finalPrice
|
|
73
|
+
const subtotalAmount = new Decimal3(originalPrice).times(quantity).toNumber();
|
|
74
|
+
const totalAmount = new Decimal3(finalPrice).times(quantity).toNumber();
|
|
77
75
|
return {
|
|
78
76
|
id: `temp-line-${index}-${variant.id}`,
|
|
79
77
|
// Temporary ID for pre-cart lines
|
|
@@ -81,6 +79,7 @@ function normalizeAddToCartLines(lines) {
|
|
|
81
79
|
quantity,
|
|
82
80
|
variantId: variant.id,
|
|
83
81
|
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
82
|
+
amountPerQuantity: finalPrice,
|
|
84
83
|
totalAmount,
|
|
85
84
|
subtotalAmount,
|
|
86
85
|
discountAllocations: [],
|
|
@@ -265,7 +264,7 @@ var formatScriptAutoFreeGift = ({
|
|
|
265
264
|
path: product?.handle || "",
|
|
266
265
|
variant,
|
|
267
266
|
totalAmount: 0,
|
|
268
|
-
subtotalAmount: new
|
|
267
|
+
subtotalAmount: new Decimal3(
|
|
269
268
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
270
269
|
).toNumber(),
|
|
271
270
|
options: [],
|
|
@@ -325,7 +324,7 @@ var formatFunctionAutoFreeGift = ({
|
|
|
325
324
|
path: product?.handle || "",
|
|
326
325
|
variant,
|
|
327
326
|
totalAmount: 0,
|
|
328
|
-
subtotalAmount: new
|
|
327
|
+
subtotalAmount: new Decimal3(
|
|
329
328
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
330
329
|
).toNumber(),
|
|
331
330
|
options: [],
|
|
@@ -555,7 +554,7 @@ var useScriptAutoFreeGift = ({
|
|
|
555
554
|
const breakpoints = useMemo(() => {
|
|
556
555
|
if (!isActivityAvailable) return [];
|
|
557
556
|
return (campaign?.breakpoints || []).map((item) => ({
|
|
558
|
-
breakpoint: new
|
|
557
|
+
breakpoint: new Decimal3(item.breakpoint).minus(new Decimal3(upgrade_value)).dividedBy(new Decimal3(upgrade_multiple)).toFixed(2, Decimal3.ROUND_DOWN),
|
|
559
558
|
giveawayProducts: item.giveawayProducts || []
|
|
560
559
|
}));
|
|
561
560
|
}, [campaign, upgrade_multiple, upgrade_value]);
|
|
@@ -590,11 +589,11 @@ var useScriptAutoFreeGift = ({
|
|
|
590
589
|
});
|
|
591
590
|
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
592
591
|
const involvedSubTotal = useMemo(() => {
|
|
593
|
-
if (!isActivityAvailable) return new
|
|
592
|
+
if (!isActivityAvailable) return new Decimal3(0);
|
|
594
593
|
return involvedLines.reduce((prev, item) => {
|
|
595
594
|
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
596
|
-
return new
|
|
597
|
-
}, new
|
|
595
|
+
return new Decimal3(prev).plus(new Decimal3(amount || 0));
|
|
596
|
+
}, new Decimal3(0));
|
|
598
597
|
}, [involvedLines, isActivityAvailable]);
|
|
599
598
|
const [freeGiftLevel, nextFreeGiftLevel] = useMemo(() => {
|
|
600
599
|
if (!isActivityAvailable) return [null, null];
|
|
@@ -602,7 +601,7 @@ var useScriptAutoFreeGift = ({
|
|
|
602
601
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
603
602
|
);
|
|
604
603
|
const levelIndex = sortedLevels.findIndex(
|
|
605
|
-
(level) => involvedSubTotal.gte(new
|
|
604
|
+
(level) => involvedSubTotal.gte(new Decimal3(level.breakpoint)) && involvedLines.length > 0
|
|
606
605
|
);
|
|
607
606
|
if (levelIndex === -1) {
|
|
608
607
|
return [
|
|
@@ -773,7 +772,7 @@ var trackAddToCartGA = ({
|
|
|
773
772
|
return;
|
|
774
773
|
}
|
|
775
774
|
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
776
|
-
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.
|
|
775
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.finalPrice?.amount || item.totalAmount || 0), new Decimal3(0)).toNumber();
|
|
777
776
|
gaTrack({
|
|
778
777
|
event: "ga4Event",
|
|
779
778
|
event_name: "add_to_cart",
|
|
@@ -811,7 +810,7 @@ var trackBuyNowGA = ({
|
|
|
811
810
|
return;
|
|
812
811
|
}
|
|
813
812
|
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
814
|
-
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.
|
|
813
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.totalAmount || 0), new Decimal3(0)).toNumber();
|
|
815
814
|
gaTrack({
|
|
816
815
|
event: "ga4Event",
|
|
817
816
|
event_name: "begin_checkout",
|
|
@@ -1029,7 +1028,7 @@ var initDiscountAttributes = ({ line }) => {
|
|
|
1029
1028
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
1030
1029
|
value: JSON.stringify({
|
|
1031
1030
|
is_gift: false,
|
|
1032
|
-
discounted_amount: new
|
|
1031
|
+
discounted_amount: new Decimal3(priceAmount).times(line.quantity || 1).toNumber()
|
|
1033
1032
|
})
|
|
1034
1033
|
}
|
|
1035
1034
|
]);
|
|
@@ -1053,11 +1052,11 @@ var initDiscountAttributes = ({ line }) => {
|
|
|
1053
1052
|
itemAttributes = itemAttributes.concat([
|
|
1054
1053
|
{
|
|
1055
1054
|
key: CODE_AMOUNT_KEY,
|
|
1056
|
-
value: new
|
|
1055
|
+
value: new Decimal3(coupon.amount).times(line.quantity || 1).toString()
|
|
1057
1056
|
},
|
|
1058
1057
|
{
|
|
1059
1058
|
key: SCRIPT_CODE_AMOUNT_KEY,
|
|
1060
|
-
value: new
|
|
1059
|
+
value: new Decimal3(coupon.amount).times(line.quantity || 1).toString()
|
|
1061
1060
|
}
|
|
1062
1061
|
]);
|
|
1063
1062
|
}
|
|
@@ -1515,8 +1514,8 @@ function getCartBasicAttributes({
|
|
|
1515
1514
|
{
|
|
1516
1515
|
key: "_weight",
|
|
1517
1516
|
value: cart?.lineItems?.reduce((acc, item) => {
|
|
1518
|
-
const itemWeight = new
|
|
1519
|
-
return new
|
|
1517
|
+
const itemWeight = new Decimal3(item.variant.weight ?? 0).times(item.quantity);
|
|
1518
|
+
return new Decimal3(acc).plus(itemWeight).toNumber();
|
|
1520
1519
|
}, 0).toString()
|
|
1521
1520
|
}
|
|
1522
1521
|
];
|
|
@@ -2378,6 +2377,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
2378
2377
|
}
|
|
2379
2378
|
return {
|
|
2380
2379
|
...cartLine,
|
|
2380
|
+
finalPrice: inputLine.variant?.finalPrice,
|
|
2381
2381
|
quantity: inputLine.quantity,
|
|
2382
2382
|
gtmParams: inputLine.gtmParams
|
|
2383
2383
|
};
|