@anker-in/shopify-react 1.2.2-beta.6 → 1.2.2-beta.7

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.
@@ -5,7 +5,7 @@ var useSWRMutation = require('swr/mutation');
5
5
  var shopifySdk = require('@anker-in/shopify-sdk');
6
6
  var Cookies5 = require('js-cookie');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
- var Decimal2 = require('decimal.js');
8
+ var Decimal3 = require('decimal.js');
9
9
  var shopifyCore = require('@anker-in/shopify-core');
10
10
  var useSWR = require('swr');
11
11
  var ahooks = require('ahooks');
@@ -14,7 +14,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
16
16
  var Cookies5__default = /*#__PURE__*/_interopDefault(Cookies5);
17
- var Decimal2__default = /*#__PURE__*/_interopDefault(Decimal2);
17
+ var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
18
18
  var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
19
19
 
20
20
  // src/hooks/cart/use-create-cart.ts
@@ -72,8 +72,6 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
72
72
  var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
73
73
  var MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
74
74
  var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
75
-
76
- // src/hooks/cart/utils/normalize-add-to-cart-lines.ts
77
75
  function normalizeAddToCartLines(lines) {
78
76
  return lines.filter((line) => line.variant?.id).map((line, index) => {
79
77
  const variant = line.variant;
@@ -81,8 +79,8 @@ function normalizeAddToCartLines(lines) {
81
79
  const quantity = line.quantity || 1;
82
80
  const originalPrice = variant.price?.amount ? Number(variant.price.amount) : 0;
83
81
  const finalPrice = variant.finalPrice?.amount === void 0 ? originalPrice : Number(variant.finalPrice?.amount);
84
- const subtotalAmount = originalPrice * quantity;
85
- const totalAmount = finalPrice * quantity;
82
+ const subtotalAmount = new Decimal3__default.default(originalPrice).times(quantity).toNumber();
83
+ const totalAmount = new Decimal3__default.default(finalPrice).times(quantity).toNumber();
86
84
  return {
87
85
  id: `temp-line-${index}-${variant.id}`,
88
86
  // Temporary ID for pre-cart lines
@@ -90,6 +88,7 @@ function normalizeAddToCartLines(lines) {
90
88
  quantity,
91
89
  variantId: variant.id,
92
90
  productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
91
+ amountPerQuantity: finalPrice,
93
92
  totalAmount,
94
93
  subtotalAmount,
95
94
  discountAllocations: [],
@@ -274,7 +273,7 @@ var formatScriptAutoFreeGift = ({
274
273
  path: product?.handle || "",
275
274
  variant,
276
275
  totalAmount: 0,
277
- subtotalAmount: new Decimal2__default.default(
276
+ subtotalAmount: new Decimal3__default.default(
278
277
  typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
279
278
  ).toNumber(),
280
279
  options: [],
@@ -334,7 +333,7 @@ var formatFunctionAutoFreeGift = ({
334
333
  path: product?.handle || "",
335
334
  variant,
336
335
  totalAmount: 0,
337
- subtotalAmount: new Decimal2__default.default(
336
+ subtotalAmount: new Decimal3__default.default(
338
337
  typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
339
338
  ).toNumber(),
340
339
  options: [],
@@ -564,7 +563,7 @@ var useScriptAutoFreeGift = ({
564
563
  const breakpoints = react.useMemo(() => {
565
564
  if (!isActivityAvailable) return [];
566
565
  return (campaign?.breakpoints || []).map((item) => ({
567
- breakpoint: new Decimal2__default.default(item.breakpoint).minus(new Decimal2__default.default(upgrade_value)).dividedBy(new Decimal2__default.default(upgrade_multiple)).toFixed(2, Decimal2__default.default.ROUND_DOWN),
566
+ breakpoint: new Decimal3__default.default(item.breakpoint).minus(new Decimal3__default.default(upgrade_value)).dividedBy(new Decimal3__default.default(upgrade_multiple)).toFixed(2, Decimal3__default.default.ROUND_DOWN),
568
567
  giveawayProducts: item.giveawayProducts || []
569
568
  }));
570
569
  }, [campaign, upgrade_multiple, upgrade_value]);
@@ -599,11 +598,11 @@ var useScriptAutoFreeGift = ({
599
598
  });
600
599
  }, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
601
600
  const involvedSubTotal = react.useMemo(() => {
602
- if (!isActivityAvailable) return new Decimal2__default.default(0);
601
+ if (!isActivityAvailable) return new Decimal3__default.default(0);
603
602
  return involvedLines.reduce((prev, item) => {
604
603
  const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
605
- return new Decimal2__default.default(prev).plus(new Decimal2__default.default(amount || 0));
606
- }, new Decimal2__default.default(0));
604
+ return new Decimal3__default.default(prev).plus(new Decimal3__default.default(amount || 0));
605
+ }, new Decimal3__default.default(0));
607
606
  }, [involvedLines, isActivityAvailable]);
608
607
  const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
609
608
  if (!isActivityAvailable) return [null, null];
@@ -611,7 +610,7 @@ var useScriptAutoFreeGift = ({
611
610
  (a, b) => Number(b.breakpoint) - Number(a.breakpoint)
612
611
  );
613
612
  const levelIndex = sortedLevels.findIndex(
614
- (level) => involvedSubTotal.gte(new Decimal2__default.default(level.breakpoint)) && involvedLines.length > 0
613
+ (level) => involvedSubTotal.gte(new Decimal3__default.default(level.breakpoint)) && involvedLines.length > 0
615
614
  );
616
615
  if (levelIndex === -1) {
617
616
  return [
@@ -782,7 +781,7 @@ var trackAddToCartGA = ({
782
781
  return;
783
782
  }
784
783
  const currencyCode = lineItems[0].product?.price?.currencyCode;
785
- const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2__default.default(0)).toNumber();
784
+ const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.totalAmount || 0), new Decimal3__default.default(0)).toNumber();
786
785
  gaTrack({
787
786
  event: "ga4Event",
788
787
  event_name: "add_to_cart",
@@ -820,7 +819,7 @@ var trackBuyNowGA = ({
820
819
  return;
821
820
  }
822
821
  const currencyCode = lineItems[0].product?.price?.currencyCode;
823
- const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.variant.price || 0), new Decimal2__default.default(0)).toNumber();
822
+ const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.totalAmount || 0), new Decimal3__default.default(0)).toNumber();
824
823
  gaTrack({
825
824
  event: "ga4Event",
826
825
  event_name: "begin_checkout",
@@ -1038,7 +1037,7 @@ var initDiscountAttributes = ({ line }) => {
1038
1037
  key: CUSTOMER_ATTRIBUTE_KEY,
1039
1038
  value: JSON.stringify({
1040
1039
  is_gift: false,
1041
- discounted_amount: new Decimal2__default.default(priceAmount).times(line.quantity || 1).toNumber()
1040
+ discounted_amount: new Decimal3__default.default(priceAmount).times(line.quantity || 1).toNumber()
1042
1041
  })
1043
1042
  }
1044
1043
  ]);
@@ -1062,11 +1061,11 @@ var initDiscountAttributes = ({ line }) => {
1062
1061
  itemAttributes = itemAttributes.concat([
1063
1062
  {
1064
1063
  key: CODE_AMOUNT_KEY,
1065
- value: new Decimal2__default.default(coupon.amount).times(line.quantity || 1).toString()
1064
+ value: new Decimal3__default.default(coupon.amount).times(line.quantity || 1).toString()
1066
1065
  },
1067
1066
  {
1068
1067
  key: SCRIPT_CODE_AMOUNT_KEY,
1069
- value: new Decimal2__default.default(coupon.amount).times(line.quantity || 1).toString()
1068
+ value: new Decimal3__default.default(coupon.amount).times(line.quantity || 1).toString()
1070
1069
  }
1071
1070
  ]);
1072
1071
  }
@@ -1524,8 +1523,8 @@ function getCartBasicAttributes({
1524
1523
  {
1525
1524
  key: "_weight",
1526
1525
  value: cart?.lineItems?.reduce((acc, item) => {
1527
- const itemWeight = new Decimal2__default.default(item.variant.weight ?? 0).times(item.quantity);
1528
- return new Decimal2__default.default(acc).plus(itemWeight).toNumber();
1526
+ const itemWeight = new Decimal3__default.default(item.variant.weight ?? 0).times(item.quantity);
1527
+ return new Decimal3__default.default(acc).plus(itemWeight).toNumber();
1529
1528
  }, 0).toString()
1530
1529
  }
1531
1530
  ];