@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/provider/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createContext, useMemo, useContext, useState, useCallback, useEffect, u
|
|
|
2
2
|
import { createShopifyClient, getCart, updateCartAttributes, updateCartLines, getProductsByHandles, getLocalStorage } from '@anker-in/shopify-sdk';
|
|
3
3
|
import Cookies5 from 'js-cookie';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
import
|
|
5
|
+
import Decimal3 from 'decimal.js';
|
|
6
6
|
import { btoaID, atobID } from '@anker-in/shopify-core';
|
|
7
7
|
import useSWR from 'swr';
|
|
8
8
|
import useSWRMutation8 from 'swr/mutation';
|
|
@@ -98,8 +98,6 @@ var CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
|
|
|
98
98
|
var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
99
99
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
100
100
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
101
|
-
|
|
102
|
-
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
103
101
|
function normalizeAddToCartLines(lines) {
|
|
104
102
|
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
105
103
|
const variant = line.variant;
|
|
@@ -107,8 +105,8 @@ function normalizeAddToCartLines(lines) {
|
|
|
107
105
|
const quantity = line.quantity || 1;
|
|
108
106
|
const originalPrice = variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
109
107
|
const finalPrice = variant.finalPrice?.amount === void 0 ? originalPrice : Number(variant.finalPrice?.amount);
|
|
110
|
-
const subtotalAmount = originalPrice
|
|
111
|
-
const totalAmount = finalPrice
|
|
108
|
+
const subtotalAmount = new Decimal3(originalPrice).times(quantity).toNumber();
|
|
109
|
+
const totalAmount = new Decimal3(finalPrice).times(quantity).toNumber();
|
|
112
110
|
return {
|
|
113
111
|
id: `temp-line-${index}-${variant.id}`,
|
|
114
112
|
// Temporary ID for pre-cart lines
|
|
@@ -116,6 +114,7 @@ function normalizeAddToCartLines(lines) {
|
|
|
116
114
|
quantity,
|
|
117
115
|
variantId: variant.id,
|
|
118
116
|
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
117
|
+
amountPerQuantity: finalPrice,
|
|
119
118
|
totalAmount,
|
|
120
119
|
subtotalAmount,
|
|
121
120
|
discountAllocations: [],
|
|
@@ -300,7 +299,7 @@ var formatScriptAutoFreeGift = ({
|
|
|
300
299
|
path: product?.handle || "",
|
|
301
300
|
variant,
|
|
302
301
|
totalAmount: 0,
|
|
303
|
-
subtotalAmount: new
|
|
302
|
+
subtotalAmount: new Decimal3(
|
|
304
303
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
305
304
|
).toNumber(),
|
|
306
305
|
options: [],
|
|
@@ -360,7 +359,7 @@ var formatFunctionAutoFreeGift = ({
|
|
|
360
359
|
path: product?.handle || "",
|
|
361
360
|
variant,
|
|
362
361
|
totalAmount: 0,
|
|
363
|
-
subtotalAmount: new
|
|
362
|
+
subtotalAmount: new Decimal3(
|
|
364
363
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
365
364
|
).toNumber(),
|
|
366
365
|
options: [],
|
|
@@ -587,7 +586,7 @@ var useScriptAutoFreeGift = ({
|
|
|
587
586
|
const breakpoints = useMemo(() => {
|
|
588
587
|
if (!isActivityAvailable) return [];
|
|
589
588
|
return (campaign?.breakpoints || []).map((item) => ({
|
|
590
|
-
breakpoint: new
|
|
589
|
+
breakpoint: new Decimal3(item.breakpoint).minus(new Decimal3(upgrade_value)).dividedBy(new Decimal3(upgrade_multiple)).toFixed(2, Decimal3.ROUND_DOWN),
|
|
591
590
|
giveawayProducts: item.giveawayProducts || []
|
|
592
591
|
}));
|
|
593
592
|
}, [campaign, upgrade_multiple, upgrade_value]);
|
|
@@ -622,11 +621,11 @@ var useScriptAutoFreeGift = ({
|
|
|
622
621
|
});
|
|
623
622
|
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
624
623
|
const involvedSubTotal = useMemo(() => {
|
|
625
|
-
if (!isActivityAvailable) return new
|
|
624
|
+
if (!isActivityAvailable) return new Decimal3(0);
|
|
626
625
|
return involvedLines.reduce((prev, item) => {
|
|
627
626
|
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
628
|
-
return new
|
|
629
|
-
}, new
|
|
627
|
+
return new Decimal3(prev).plus(new Decimal3(amount || 0));
|
|
628
|
+
}, new Decimal3(0));
|
|
630
629
|
}, [involvedLines, isActivityAvailable]);
|
|
631
630
|
const [freeGiftLevel, nextFreeGiftLevel] = useMemo(() => {
|
|
632
631
|
if (!isActivityAvailable) return [null, null];
|
|
@@ -634,7 +633,7 @@ var useScriptAutoFreeGift = ({
|
|
|
634
633
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
635
634
|
);
|
|
636
635
|
const levelIndex = sortedLevels.findIndex(
|
|
637
|
-
(level) => involvedSubTotal.gte(new
|
|
636
|
+
(level) => involvedSubTotal.gte(new Decimal3(level.breakpoint)) && involvedLines.length > 0
|
|
638
637
|
);
|
|
639
638
|
if (levelIndex === -1) {
|
|
640
639
|
return [
|
|
@@ -872,8 +871,8 @@ function getCartBasicAttributes({
|
|
|
872
871
|
{
|
|
873
872
|
key: "_weight",
|
|
874
873
|
value: cart?.lineItems?.reduce((acc, item) => {
|
|
875
|
-
const itemWeight = new
|
|
876
|
-
return new
|
|
874
|
+
const itemWeight = new Decimal3(item.variant.weight ?? 0).times(item.quantity);
|
|
875
|
+
return new Decimal3(acc).plus(itemWeight).toNumber();
|
|
877
876
|
}, 0).toString()
|
|
878
877
|
}
|
|
879
878
|
];
|