@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
|
@@ -4,7 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.mjs';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-DfR13pDe.mjs';
|
|
8
8
|
import 'decimal.js';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-DfR13pDe.js';
|
|
8
8
|
import 'decimal.js';
|
|
9
9
|
|
|
10
10
|
interface ShopifyContextValue {
|
package/dist/provider/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var react = require('react');
|
|
|
4
4
|
var shopifySdk = require('@anker-in/shopify-sdk');
|
|
5
5
|
var Cookies5 = require('js-cookie');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
var
|
|
7
|
+
var Decimal3 = require('decimal.js');
|
|
8
8
|
var shopifyCore = require('@anker-in/shopify-core');
|
|
9
9
|
var useSWR = require('swr');
|
|
10
10
|
var useSWRMutation8 = require('swr/mutation');
|
|
@@ -13,7 +13,7 @@ var ahooks = require('ahooks');
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
15
|
var Cookies5__default = /*#__PURE__*/_interopDefault(Cookies5);
|
|
16
|
-
var
|
|
16
|
+
var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
|
|
17
17
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
18
18
|
var useSWRMutation8__default = /*#__PURE__*/_interopDefault(useSWRMutation8);
|
|
19
19
|
|
|
@@ -107,8 +107,6 @@ var CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
|
|
|
107
107
|
var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
108
108
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
109
109
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
110
|
-
|
|
111
|
-
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
112
110
|
function normalizeAddToCartLines(lines) {
|
|
113
111
|
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
114
112
|
const variant = line.variant;
|
|
@@ -116,8 +114,8 @@ function normalizeAddToCartLines(lines) {
|
|
|
116
114
|
const quantity = line.quantity || 1;
|
|
117
115
|
const originalPrice = variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
118
116
|
const finalPrice = variant.finalPrice?.amount === void 0 ? originalPrice : Number(variant.finalPrice?.amount);
|
|
119
|
-
const subtotalAmount = originalPrice
|
|
120
|
-
const totalAmount = finalPrice
|
|
117
|
+
const subtotalAmount = new Decimal3__default.default(originalPrice).times(quantity).toNumber();
|
|
118
|
+
const totalAmount = new Decimal3__default.default(finalPrice).times(quantity).toNumber();
|
|
121
119
|
return {
|
|
122
120
|
id: `temp-line-${index}-${variant.id}`,
|
|
123
121
|
// Temporary ID for pre-cart lines
|
|
@@ -125,6 +123,7 @@ function normalizeAddToCartLines(lines) {
|
|
|
125
123
|
quantity,
|
|
126
124
|
variantId: variant.id,
|
|
127
125
|
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
126
|
+
amountPerQuantity: finalPrice,
|
|
128
127
|
totalAmount,
|
|
129
128
|
subtotalAmount,
|
|
130
129
|
discountAllocations: [],
|
|
@@ -309,7 +308,7 @@ var formatScriptAutoFreeGift = ({
|
|
|
309
308
|
path: product?.handle || "",
|
|
310
309
|
variant,
|
|
311
310
|
totalAmount: 0,
|
|
312
|
-
subtotalAmount: new
|
|
311
|
+
subtotalAmount: new Decimal3__default.default(
|
|
313
312
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
314
313
|
).toNumber(),
|
|
315
314
|
options: [],
|
|
@@ -369,7 +368,7 @@ var formatFunctionAutoFreeGift = ({
|
|
|
369
368
|
path: product?.handle || "",
|
|
370
369
|
variant,
|
|
371
370
|
totalAmount: 0,
|
|
372
|
-
subtotalAmount: new
|
|
371
|
+
subtotalAmount: new Decimal3__default.default(
|
|
373
372
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
374
373
|
).toNumber(),
|
|
375
374
|
options: [],
|
|
@@ -596,7 +595,7 @@ var useScriptAutoFreeGift = ({
|
|
|
596
595
|
const breakpoints = react.useMemo(() => {
|
|
597
596
|
if (!isActivityAvailable) return [];
|
|
598
597
|
return (campaign?.breakpoints || []).map((item) => ({
|
|
599
|
-
breakpoint: new
|
|
598
|
+
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),
|
|
600
599
|
giveawayProducts: item.giveawayProducts || []
|
|
601
600
|
}));
|
|
602
601
|
}, [campaign, upgrade_multiple, upgrade_value]);
|
|
@@ -631,11 +630,11 @@ var useScriptAutoFreeGift = ({
|
|
|
631
630
|
});
|
|
632
631
|
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
633
632
|
const involvedSubTotal = react.useMemo(() => {
|
|
634
|
-
if (!isActivityAvailable) return new
|
|
633
|
+
if (!isActivityAvailable) return new Decimal3__default.default(0);
|
|
635
634
|
return involvedLines.reduce((prev, item) => {
|
|
636
635
|
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
637
|
-
return new
|
|
638
|
-
}, new
|
|
636
|
+
return new Decimal3__default.default(prev).plus(new Decimal3__default.default(amount || 0));
|
|
637
|
+
}, new Decimal3__default.default(0));
|
|
639
638
|
}, [involvedLines, isActivityAvailable]);
|
|
640
639
|
const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
|
|
641
640
|
if (!isActivityAvailable) return [null, null];
|
|
@@ -643,7 +642,7 @@ var useScriptAutoFreeGift = ({
|
|
|
643
642
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
644
643
|
);
|
|
645
644
|
const levelIndex = sortedLevels.findIndex(
|
|
646
|
-
(level) => involvedSubTotal.gte(new
|
|
645
|
+
(level) => involvedSubTotal.gte(new Decimal3__default.default(level.breakpoint)) && involvedLines.length > 0
|
|
647
646
|
);
|
|
648
647
|
if (levelIndex === -1) {
|
|
649
648
|
return [
|
|
@@ -881,8 +880,8 @@ function getCartBasicAttributes({
|
|
|
881
880
|
{
|
|
882
881
|
key: "_weight",
|
|
883
882
|
value: cart?.lineItems?.reduce((acc, item) => {
|
|
884
|
-
const itemWeight = new
|
|
885
|
-
return new
|
|
883
|
+
const itemWeight = new Decimal3__default.default(item.variant.weight ?? 0).times(item.quantity);
|
|
884
|
+
return new Decimal3__default.default(acc).plus(itemWeight).toNumber();
|
|
886
885
|
}, 0).toString()
|
|
887
886
|
}
|
|
888
887
|
];
|