@anker-in/shopify-react 0.1.1-beta.41 → 0.1.1-beta.43
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 +112 -168
- package/dist/hooks/index.d.ts +112 -168
- package/dist/hooks/index.js +122 -310
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +122 -307
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +127 -311
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -308
- 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 +54 -55
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +54 -55
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-y1Wa95P3.d.mts → types-CMMWxyUF.d.mts} +5 -10
- package/dist/{types-y1Wa95P3.d.ts → types-CMMWxyUF.d.ts} +5 -10
- package/package.json +3 -3
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useMemo, useRef, useState, useEffect, useCallback, useContext } from 'react';
|
|
2
2
|
import useSWRMutation from 'swr/mutation';
|
|
3
|
-
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage
|
|
3
|
+
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, 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
6
|
import Decimal2 from 'decimal.js';
|
|
@@ -1189,24 +1189,31 @@ function useRemoveCartLines(options) {
|
|
|
1189
1189
|
);
|
|
1190
1190
|
return useSWRMutation("remove-cart-lines", removeLines, options);
|
|
1191
1191
|
}
|
|
1192
|
-
function useUpdateCartAttributes(
|
|
1192
|
+
function useUpdateCartAttributes({
|
|
1193
|
+
mutate,
|
|
1194
|
+
metafieldIdentifiers,
|
|
1195
|
+
disabled = false,
|
|
1196
|
+
swrOptions
|
|
1197
|
+
}) {
|
|
1193
1198
|
const { client, locale, cartCookieAdapter } = useShopify();
|
|
1194
1199
|
const updateAttributes = useCallback(
|
|
1195
1200
|
async (_key, { arg }) => {
|
|
1201
|
+
if (disabled || !cartCookieAdapter?.getCartId(locale)) {
|
|
1202
|
+
return void 0;
|
|
1203
|
+
}
|
|
1196
1204
|
const updatedCart = await updateCartAttributes(client, {
|
|
1197
1205
|
...arg,
|
|
1198
1206
|
metafieldIdentifiers,
|
|
1199
1207
|
cookieAdapter: cartCookieAdapter
|
|
1200
1208
|
});
|
|
1201
|
-
console.log("useUpdateCartAttributes updatedCart", updatedCart);
|
|
1202
1209
|
if (updatedCart) {
|
|
1203
1210
|
mutate(updatedCart);
|
|
1204
1211
|
}
|
|
1205
1212
|
return updatedCart;
|
|
1206
1213
|
},
|
|
1207
|
-
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
|
|
1214
|
+
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
|
|
1208
1215
|
);
|
|
1209
|
-
return useSWRMutation("update-cart-attributes", updateAttributes,
|
|
1216
|
+
return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
|
|
1210
1217
|
}
|
|
1211
1218
|
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
1212
1219
|
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
@@ -1444,36 +1451,46 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
|
|
|
1444
1451
|
isLoading: isCustomerLoading
|
|
1445
1452
|
};
|
|
1446
1453
|
};
|
|
1447
|
-
function
|
|
1454
|
+
function hasPlusMemberInCart({
|
|
1448
1455
|
memberSetting,
|
|
1449
1456
|
cart
|
|
1450
1457
|
}) {
|
|
1451
1458
|
const { plus_monthly_product, plus_annual_product } = memberSetting || {};
|
|
1452
|
-
|
|
1453
|
-
if (!cart?.lineItems) {
|
|
1454
|
-
return {
|
|
1455
|
-
hasPlusMember: false,
|
|
1456
|
-
hasMonthlyPlus: false,
|
|
1457
|
-
hasAnnualPlus: false
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
const monthlyPlusItem = cart.lineItems.find(
|
|
1461
|
-
(item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
|
|
1462
|
-
);
|
|
1463
|
-
const annualPlusItem = cart.lineItems.find(
|
|
1464
|
-
(item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
|
|
1465
|
-
);
|
|
1466
|
-
const hasMonthlyPlus = !!monthlyPlusItem;
|
|
1467
|
-
const hasAnnualPlus = !!annualPlusItem;
|
|
1468
|
-
const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
|
|
1459
|
+
if (!cart?.lineItems) {
|
|
1469
1460
|
return {
|
|
1470
|
-
hasPlusMember,
|
|
1471
|
-
hasMonthlyPlus,
|
|
1472
|
-
hasAnnualPlus
|
|
1473
|
-
monthlyPlusItem,
|
|
1474
|
-
annualPlusItem
|
|
1461
|
+
hasPlusMember: false,
|
|
1462
|
+
hasMonthlyPlus: false,
|
|
1463
|
+
hasAnnualPlus: false
|
|
1475
1464
|
};
|
|
1476
|
-
}
|
|
1465
|
+
}
|
|
1466
|
+
const monthlyPlusItem = cart.lineItems.find(
|
|
1467
|
+
(item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
|
|
1468
|
+
);
|
|
1469
|
+
const annualPlusItem = cart.lineItems.find(
|
|
1470
|
+
(item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
|
|
1471
|
+
);
|
|
1472
|
+
const hasMonthlyPlus = !!monthlyPlusItem;
|
|
1473
|
+
const hasAnnualPlus = !!annualPlusItem;
|
|
1474
|
+
const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
|
|
1475
|
+
return {
|
|
1476
|
+
hasPlusMember,
|
|
1477
|
+
hasMonthlyPlus,
|
|
1478
|
+
hasAnnualPlus,
|
|
1479
|
+
monthlyPlusItem,
|
|
1480
|
+
annualPlusItem
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
function useHasPlusMemberInCart({
|
|
1484
|
+
memberSetting,
|
|
1485
|
+
cart
|
|
1486
|
+
}) {
|
|
1487
|
+
return useMemo(
|
|
1488
|
+
() => hasPlusMemberInCart({
|
|
1489
|
+
memberSetting,
|
|
1490
|
+
cart
|
|
1491
|
+
}),
|
|
1492
|
+
[memberSetting, cart]
|
|
1493
|
+
);
|
|
1477
1494
|
}
|
|
1478
1495
|
var getReferralAttributes = () => {
|
|
1479
1496
|
const inviteCode = getLocalStorage("inviteCode") || Cookies5.get("inviteCode");
|
|
@@ -1570,7 +1587,7 @@ var useCartAttributes = ({
|
|
|
1570
1587
|
})
|
|
1571
1588
|
}
|
|
1572
1589
|
] : [];
|
|
1573
|
-
}, [cart]);
|
|
1590
|
+
}, [cart, customer]);
|
|
1574
1591
|
const presellAttributes = useMemo(() => {
|
|
1575
1592
|
return [
|
|
1576
1593
|
{
|
|
@@ -1634,9 +1651,7 @@ var useCartAttributes = ({
|
|
|
1634
1651
|
"_play_mode_id",
|
|
1635
1652
|
"_popup"
|
|
1636
1653
|
];
|
|
1637
|
-
return cart?.customAttributes?.filter(
|
|
1638
|
-
(item) => !commonAttributeKeys.includes(item.key)
|
|
1639
|
-
) || [];
|
|
1654
|
+
return cart?.customAttributes?.filter((item) => !commonAttributeKeys.includes(item.key)) || [];
|
|
1640
1655
|
}, [cart]);
|
|
1641
1656
|
return useMemo(
|
|
1642
1657
|
() => ({
|
|
@@ -2454,28 +2469,13 @@ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
|
|
|
2454
2469
|
return ShippingMethodMode2;
|
|
2455
2470
|
})(ShippingMethodMode || {});
|
|
2456
2471
|
var createInitialValue = () => ({
|
|
2457
|
-
zipCode: "",
|
|
2458
2472
|
plusMemberMetafields: {},
|
|
2459
|
-
setZipCode: () => {
|
|
2460
|
-
},
|
|
2461
|
-
allowNextDayDelivery: false,
|
|
2462
|
-
setAllowNextDayDelivery: () => {
|
|
2463
|
-
},
|
|
2464
|
-
allowThirdDayDelivery: false,
|
|
2465
|
-
setAllowThirdDayDelivery: () => {
|
|
2466
|
-
},
|
|
2467
2473
|
selectedPlusMemberMode: "free",
|
|
2468
2474
|
setSelectedPlusMemberMode: () => {
|
|
2469
2475
|
},
|
|
2470
|
-
showAreaCheckModal: false,
|
|
2471
|
-
setShowAreaCheckModal: () => {
|
|
2472
|
-
},
|
|
2473
2476
|
selectedShippingMethod: void 0,
|
|
2474
2477
|
setSelectedShippingMethod: () => {
|
|
2475
2478
|
},
|
|
2476
|
-
showTip: false,
|
|
2477
|
-
setShowTip: () => {
|
|
2478
|
-
},
|
|
2479
2479
|
showMoreShippingMethod: false,
|
|
2480
2480
|
setShowMoreShippingMethod: () => {
|
|
2481
2481
|
},
|
|
@@ -2490,48 +2490,49 @@ var createInitialValue = () => ({
|
|
|
2490
2490
|
tddCoupon: void 0,
|
|
2491
2491
|
isLoadingCoupon: false
|
|
2492
2492
|
},
|
|
2493
|
-
|
|
2494
|
-
plusMemberProducts: [],
|
|
2493
|
+
selectedPlusMemberVariant: void 0,
|
|
2495
2494
|
showPlusMemberBenefit: false,
|
|
2496
2495
|
setShowPlusMemberBenefit: () => {
|
|
2497
2496
|
},
|
|
2498
|
-
|
|
2499
|
-
setDeleteMarginBottom: () => {
|
|
2500
|
-
},
|
|
2501
|
-
profile: void 0,
|
|
2502
|
-
locale: void 0
|
|
2497
|
+
profile: void 0
|
|
2503
2498
|
});
|
|
2504
2499
|
var PlusMemberContext = createContext(createInitialValue());
|
|
2505
2500
|
function usePlusMemberContext() {
|
|
2506
2501
|
return useContext(PlusMemberContext);
|
|
2507
2502
|
}
|
|
2508
|
-
function
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
const
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
);
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2503
|
+
function usePlusMemberVariants({
|
|
2504
|
+
memberSetting
|
|
2505
|
+
}) {
|
|
2506
|
+
const plusMonthly = memberSetting?.plus_monthly_product;
|
|
2507
|
+
const plusAnnual = memberSetting?.plus_annual_product;
|
|
2508
|
+
const plusMemberHandles = useMemo(() => {
|
|
2509
|
+
return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
|
|
2510
|
+
}, [plusMonthly?.handle, plusAnnual?.handle]);
|
|
2511
|
+
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2512
|
+
handles: plusMemberHandles
|
|
2513
|
+
});
|
|
2514
|
+
const monthlyProduct = useMemo(() => {
|
|
2515
|
+
return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
|
|
2519
2516
|
}, [plusMemberProducts, plusMonthly]);
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
function usePlusAnnualProductVariant() {
|
|
2523
|
-
const { plusMemberProducts, plusMemberMetafields } = usePlusMemberContext();
|
|
2524
|
-
const plusAnnual = plusMemberMetafields?.plus_annual_product;
|
|
2525
|
-
const plusAnnualProductVariant = useMemo(() => {
|
|
2526
|
-
const product = plusMemberProducts?.find(
|
|
2527
|
-
(item) => item?.handle === plusAnnual?.handle
|
|
2528
|
-
);
|
|
2529
|
-
const productVariant = product?.variants?.find(
|
|
2530
|
-
(item) => item.sku === plusAnnual?.sku
|
|
2531
|
-
);
|
|
2532
|
-
return productVariant;
|
|
2517
|
+
const annualProduct = useMemo(() => {
|
|
2518
|
+
return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
|
|
2533
2519
|
}, [plusMemberProducts, plusAnnual]);
|
|
2534
|
-
|
|
2520
|
+
const monthlyVariant = useMemo(() => {
|
|
2521
|
+
return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
|
|
2522
|
+
}, [monthlyProduct, plusMonthly]);
|
|
2523
|
+
const annualVariant = useMemo(() => {
|
|
2524
|
+
return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
|
|
2525
|
+
}, [annualProduct, plusAnnual]);
|
|
2526
|
+
return {
|
|
2527
|
+
monthlyVariant: monthlyVariant ? {
|
|
2528
|
+
...monthlyVariant,
|
|
2529
|
+
product: monthlyProduct
|
|
2530
|
+
} : void 0,
|
|
2531
|
+
annualVariant: annualVariant ? {
|
|
2532
|
+
...annualVariant,
|
|
2533
|
+
product: annualProduct
|
|
2534
|
+
} : void 0
|
|
2535
|
+
};
|
|
2535
2536
|
}
|
|
2536
2537
|
var useAvailableDeliveryCoupon = ({
|
|
2537
2538
|
profile
|
|
@@ -2553,9 +2554,9 @@ var useAvailableDeliveryCoupon = ({
|
|
|
2553
2554
|
|
|
2554
2555
|
// src/hooks/member/plus/use-shipping-methods.ts
|
|
2555
2556
|
function useShippingMethods(options) {
|
|
2556
|
-
const { variant, plusMemberMetafields, selectedPlusMemberMode,
|
|
2557
|
+
const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
|
|
2558
|
+
const isPlus = profile?.isPlus || false;
|
|
2557
2559
|
const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
|
|
2558
|
-
console.log("nddCoupon", nddCoupon);
|
|
2559
2560
|
const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
|
|
2560
2561
|
const nddOverweight = useMemo(() => {
|
|
2561
2562
|
return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
|
|
@@ -2682,69 +2683,6 @@ function useShippingMethods(options) {
|
|
|
2682
2683
|
isLoadingCoupon: isLoading
|
|
2683
2684
|
};
|
|
2684
2685
|
}
|
|
2685
|
-
function useShippingMethodAvailableCheck() {
|
|
2686
|
-
const {
|
|
2687
|
-
zipCode,
|
|
2688
|
-
allowNextDayDelivery,
|
|
2689
|
-
allowThirdDayDelivery,
|
|
2690
|
-
selectedShippingMethod,
|
|
2691
|
-
setSelectedShippingMethod,
|
|
2692
|
-
setShowTip,
|
|
2693
|
-
shippingMethodsContext
|
|
2694
|
-
} = usePlusMemberContext();
|
|
2695
|
-
useEffect(() => {
|
|
2696
|
-
const freeShippingMethod = shippingMethodsContext.freeShippingMethods[0];
|
|
2697
|
-
const standardShippingMethod = shippingMethodsContext.freeShippingMethods?.find(
|
|
2698
|
-
(item) => item.__mode === "free" /* FREE */
|
|
2699
|
-
);
|
|
2700
|
-
const freeTDD = shippingMethodsContext.freeShippingMethods.find(
|
|
2701
|
-
(item) => item.__mode === "tdd" /* TDD */
|
|
2702
|
-
);
|
|
2703
|
-
const paymentTDD = shippingMethodsContext.paymentShippingMethods.find(
|
|
2704
|
-
(item) => item.__mode === "tdd" /* TDD */
|
|
2705
|
-
);
|
|
2706
|
-
if (zipCode) {
|
|
2707
|
-
console.log(
|
|
2708
|
-
"allowNextDayDelivery, allowThirdDayDelivery:",
|
|
2709
|
-
allowNextDayDelivery,
|
|
2710
|
-
allowThirdDayDelivery
|
|
2711
|
-
);
|
|
2712
|
-
if (!allowNextDayDelivery && !allowThirdDayDelivery) {
|
|
2713
|
-
setShowTip(true);
|
|
2714
|
-
setSelectedShippingMethod(standardShippingMethod);
|
|
2715
|
-
} else {
|
|
2716
|
-
if (selectedShippingMethod?.__mode === "ndd" /* NDD */ && !allowNextDayDelivery) {
|
|
2717
|
-
setShowTip(true);
|
|
2718
|
-
if (allowThirdDayDelivery) {
|
|
2719
|
-
if (selectedShippingMethod.useCoupon) {
|
|
2720
|
-
const method = freeTDD || freeShippingMethod;
|
|
2721
|
-
if (method) setSelectedShippingMethod(method);
|
|
2722
|
-
} else {
|
|
2723
|
-
const method = paymentTDD || freeShippingMethod;
|
|
2724
|
-
if (method) setSelectedShippingMethod(method);
|
|
2725
|
-
}
|
|
2726
|
-
} else {
|
|
2727
|
-
if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
|
|
2728
|
-
}
|
|
2729
|
-
} else if (
|
|
2730
|
-
// TDD 无法使用
|
|
2731
|
-
selectedShippingMethod?.__mode === "tdd" /* TDD */ && !allowThirdDayDelivery
|
|
2732
|
-
) {
|
|
2733
|
-
setShowTip(true);
|
|
2734
|
-
if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
}, [
|
|
2739
|
-
allowNextDayDelivery,
|
|
2740
|
-
allowThirdDayDelivery,
|
|
2741
|
-
zipCode,
|
|
2742
|
-
shippingMethodsContext,
|
|
2743
|
-
selectedShippingMethod,
|
|
2744
|
-
setSelectedShippingMethod,
|
|
2745
|
-
setShowTip
|
|
2746
|
-
]);
|
|
2747
|
-
}
|
|
2748
2686
|
var useReplaceCartPlusMember = () => {
|
|
2749
2687
|
const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
|
|
2750
2688
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
@@ -2776,129 +2714,45 @@ var useReplaceCartPlusMember = () => {
|
|
|
2776
2714
|
]);
|
|
2777
2715
|
return handler;
|
|
2778
2716
|
};
|
|
2779
|
-
var usePlusMemberDeliveryCodes = ({
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
return useMemo(
|
|
2783
|
-
() => deliveryData?.deliveryCustomData?.discount_code,
|
|
2784
|
-
[deliveryData]
|
|
2785
|
-
);
|
|
2786
|
-
};
|
|
2787
|
-
function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
|
|
2788
|
-
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2789
|
-
const updateDeliveryOptions = useCallback(
|
|
2790
|
-
async (_key, { arg }) => {
|
|
2791
|
-
const updatedCart = await updateCartDeliveryOptions(client, {
|
|
2792
|
-
...arg,
|
|
2793
|
-
metafieldIdentifiers,
|
|
2794
|
-
cookieAdapter: cartCookieAdapter
|
|
2795
|
-
});
|
|
2796
|
-
console.log("useUpdateCartDeliveryOptions updatedCart", updatedCart);
|
|
2797
|
-
if (updatedCart) {
|
|
2798
|
-
mutate(updatedCart);
|
|
2799
|
-
}
|
|
2800
|
-
return updatedCart;
|
|
2801
|
-
},
|
|
2802
|
-
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
|
|
2803
|
-
);
|
|
2804
|
-
return useSWRMutation("update-cart-delivery-options", updateDeliveryOptions, options);
|
|
2805
|
-
}
|
|
2806
|
-
|
|
2807
|
-
// src/hooks/member/plus/use-update-plus-member-delivery-options.ts
|
|
2808
|
-
var useUpdatePlusMemberDeliveryOptions = ({
|
|
2809
|
-
options
|
|
2810
|
-
} = {}) => {
|
|
2811
|
-
const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
|
|
2812
|
-
const { trigger: updateCartDeliveryOptions2 } = useUpdateCartDeliveryOptions(
|
|
2813
|
-
mutateCart,
|
|
2814
|
-
metafieldIdentifiers
|
|
2815
|
-
);
|
|
2816
|
-
const handler = useCallback(
|
|
2817
|
-
async (_, { arg }) => {
|
|
2818
|
-
const currentCart = arg?.cart || cartContextData;
|
|
2819
|
-
const { deliveryData } = arg;
|
|
2820
|
-
const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
|
|
2821
|
-
const deliveryGroupId = firstDeliveryGroup?.id;
|
|
2822
|
-
const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
|
|
2823
|
-
if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
|
|
2824
|
-
return null;
|
|
2825
|
-
}
|
|
2826
|
-
const deliveryGroup = currentCart?.deliveryGroups?.find(
|
|
2827
|
-
(group) => group?.id === deliveryGroupId
|
|
2828
|
-
);
|
|
2829
|
-
const matchedOption = deliveryGroup?.deliveryOptions?.find(
|
|
2830
|
-
(option) => option?.code === selectedOptionCode
|
|
2831
|
-
);
|
|
2832
|
-
if (!matchedOption?.handle) {
|
|
2833
|
-
return null;
|
|
2834
|
-
}
|
|
2835
|
-
const deliveryOptions = [
|
|
2836
|
-
{
|
|
2837
|
-
deliveryGroupId,
|
|
2838
|
-
deliveryOptionHandle: matchedOption.handle
|
|
2839
|
-
}
|
|
2840
|
-
];
|
|
2841
|
-
const updatedCart = await updateCartDeliveryOptions2({
|
|
2842
|
-
selectedDeliveryOptions: deliveryOptions,
|
|
2843
|
-
cartId: currentCart?.id
|
|
2844
|
-
});
|
|
2845
|
-
if (updatedCart && mutateCart) {
|
|
2846
|
-
mutateCart(updatedCart);
|
|
2847
|
-
}
|
|
2848
|
-
return updatedCart;
|
|
2849
|
-
},
|
|
2850
|
-
[cartContextData, updateCartDeliveryOptions2, mutateCart]
|
|
2851
|
-
);
|
|
2852
|
-
return useSWRMutation("update-cart-delivery-options", handler, options);
|
|
2853
|
-
};
|
|
2854
|
-
var usePlusMemberItemCustomAttributes = ({
|
|
2855
|
-
deliveryData
|
|
2856
|
-
}) => {
|
|
2857
|
-
const { deliveryCustomData } = deliveryData || {};
|
|
2858
|
-
return useMemo(() => {
|
|
2859
|
-
const itemCustomAttributes = [];
|
|
2860
|
-
if (deliveryCustomData?.is_presale) {
|
|
2861
|
-
itemCustomAttributes.push({
|
|
2862
|
-
key: "_is_presale",
|
|
2863
|
-
value: "true"
|
|
2864
|
-
});
|
|
2865
|
-
}
|
|
2866
|
-
return itemCustomAttributes;
|
|
2867
|
-
}, [deliveryCustomData]);
|
|
2717
|
+
var usePlusMemberDeliveryCodes = () => {
|
|
2718
|
+
const { selectedShippingMethod } = usePlusMemberContext();
|
|
2719
|
+
return useMemo(() => [selectedShippingMethod?.coupon], [selectedShippingMethod?.coupon]);
|
|
2868
2720
|
};
|
|
2869
2721
|
var usePlusMemberCheckoutCustomAttributes = ({
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
variant,
|
|
2873
|
-
isShowShippingBenefits
|
|
2722
|
+
disableShipping = false,
|
|
2723
|
+
isPresaleContains = false
|
|
2874
2724
|
}) => {
|
|
2875
|
-
const {
|
|
2876
|
-
const { profile } = usePlusMemberContext();
|
|
2725
|
+
const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
|
|
2877
2726
|
return useMemo(() => {
|
|
2878
2727
|
const checkoutCustomAttributes = [
|
|
2879
|
-
// _last_url: 付费会员结算完成之后 checkout 有一个继续购买的按钮, 用于跳转到继续购买的页面
|
|
2880
2728
|
{
|
|
2881
2729
|
key: "_last_url",
|
|
2882
2730
|
value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
|
|
2883
2731
|
}
|
|
2884
2732
|
];
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2733
|
+
checkoutCustomAttributes.push({
|
|
2734
|
+
key: "_checkout_delivery_custom",
|
|
2735
|
+
value: JSON.stringify({
|
|
2736
|
+
allow_nextday_delivery: true,
|
|
2737
|
+
allow_thirdday_delivery: true,
|
|
2738
|
+
selected_delivery_option: {
|
|
2739
|
+
code: selectedShippingMethod?.__code,
|
|
2740
|
+
mode: selectedShippingMethod?.__mode
|
|
2741
|
+
},
|
|
2742
|
+
is_presale: isPresaleContains,
|
|
2743
|
+
discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
|
|
2744
|
+
plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
|
|
2745
|
+
is_prime: profile?.isPlus
|
|
2746
|
+
})
|
|
2747
|
+
});
|
|
2748
|
+
if (disableShipping) {
|
|
2895
2749
|
checkoutCustomAttributes.push({
|
|
2896
2750
|
key: "_hide_shipping",
|
|
2897
2751
|
value: "true"
|
|
2898
2752
|
});
|
|
2899
2753
|
}
|
|
2900
2754
|
return checkoutCustomAttributes;
|
|
2901
|
-
}, [
|
|
2755
|
+
}, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
|
|
2902
2756
|
};
|
|
2903
2757
|
function useAutoRemovePlusMemberInCart({
|
|
2904
2758
|
cart,
|
|
@@ -2932,13 +2786,13 @@ function usePlusMemberNeedAddToCart({
|
|
|
2932
2786
|
cart,
|
|
2933
2787
|
profile
|
|
2934
2788
|
}) {
|
|
2935
|
-
const { selectedPlusMemberMode,
|
|
2789
|
+
const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
|
|
2936
2790
|
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2937
2791
|
memberSetting: plusMemberMetafields,
|
|
2938
2792
|
cart
|
|
2939
2793
|
});
|
|
2940
|
-
const
|
|
2941
|
-
if (!
|
|
2794
|
+
const plusMemberVariant = useMemo(() => {
|
|
2795
|
+
if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
|
|
2942
2796
|
return void 0;
|
|
2943
2797
|
}
|
|
2944
2798
|
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
@@ -2953,15 +2807,9 @@ function usePlusMemberNeedAddToCart({
|
|
|
2953
2807
|
if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
|
|
2954
2808
|
return void 0;
|
|
2955
2809
|
}
|
|
2956
|
-
return
|
|
2957
|
-
}, [
|
|
2958
|
-
|
|
2959
|
-
selectedPlusMemberProduct?.variant,
|
|
2960
|
-
selectedPlusMemberProduct?.product,
|
|
2961
|
-
hasMonthlyPlus,
|
|
2962
|
-
hasAnnualPlus
|
|
2963
|
-
]);
|
|
2964
|
-
return plusMemberProduct;
|
|
2810
|
+
return selectedPlusMemberVariant;
|
|
2811
|
+
}, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
|
|
2812
|
+
return plusMemberVariant;
|
|
2965
2813
|
}
|
|
2966
2814
|
var PlusMemberProvider = ({
|
|
2967
2815
|
variant,
|
|
@@ -2971,78 +2819,45 @@ var PlusMemberProvider = ({
|
|
|
2971
2819
|
profile,
|
|
2972
2820
|
children
|
|
2973
2821
|
}) => {
|
|
2974
|
-
const { locale } = useShopify();
|
|
2975
|
-
const [zipCode, setZipCode] = useState("");
|
|
2976
|
-
const [showTip, setShowTip] = useState(false);
|
|
2977
2822
|
const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
|
|
2978
2823
|
initialSelectedPlusMemberMode
|
|
2979
2824
|
);
|
|
2980
2825
|
const [selectedShippingMethod, setSelectedShippingMethod] = useState();
|
|
2981
|
-
const [allowNextDayDelivery, setAllowNextDayDelivery] = useState(false);
|
|
2982
|
-
const [allowThirdDayDelivery, setAllowThirdDayDelivery] = useState(false);
|
|
2983
|
-
const [showAreaCheckModal, setShowAreaCheckModal] = useState(false);
|
|
2984
2826
|
const [showMoreShippingMethod, setShowMoreShippingMethod] = useState(false);
|
|
2985
2827
|
const [showPlusMemberBenefit, setShowPlusMemberBenefit] = useState(false);
|
|
2986
|
-
const [deleteMarginBottom, setDeleteMarginBottom] = useState(false);
|
|
2987
2828
|
const shippingMethodsContext = useShippingMethods({
|
|
2988
2829
|
variant,
|
|
2989
2830
|
plusMemberMetafields: memberSetting,
|
|
2990
2831
|
selectedPlusMemberMode,
|
|
2991
|
-
profile
|
|
2992
|
-
isPlus: profile?.isPlus || false
|
|
2832
|
+
profile
|
|
2993
2833
|
});
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
return [
|
|
2997
|
-
memberSetting?.plus_monthly_product?.handle,
|
|
2998
|
-
memberSetting?.plus_annual_product?.handle
|
|
2999
|
-
].filter(Boolean);
|
|
3000
|
-
}, [memberSetting]);
|
|
3001
|
-
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
3002
|
-
handles: plusMemberHandles
|
|
2834
|
+
const { monthlyVariant, annualVariant } = usePlusMemberVariants({
|
|
2835
|
+
memberSetting
|
|
3003
2836
|
});
|
|
3004
|
-
const
|
|
2837
|
+
const selectedPlusMemberVariant = useMemo(() => {
|
|
3005
2838
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
3006
|
-
return
|
|
2839
|
+
return void 0;
|
|
3007
2840
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
3011
|
-
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
3012
|
-
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
3013
|
-
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2841
|
+
return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
|
|
2842
|
+
}, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
|
|
3014
2843
|
return /* @__PURE__ */ jsx(
|
|
3015
2844
|
PlusMemberContext.Provider,
|
|
3016
2845
|
{
|
|
3017
2846
|
value: {
|
|
3018
2847
|
variant,
|
|
3019
|
-
zipCode,
|
|
3020
|
-
setZipCode,
|
|
3021
|
-
allowNextDayDelivery,
|
|
3022
|
-
setAllowNextDayDelivery,
|
|
3023
|
-
allowThirdDayDelivery,
|
|
3024
|
-
setAllowThirdDayDelivery,
|
|
3025
2848
|
plusMemberMetafields: memberSetting,
|
|
3026
2849
|
selectedPlusMemberMode,
|
|
3027
2850
|
setSelectedPlusMemberMode,
|
|
3028
|
-
showAreaCheckModal,
|
|
3029
|
-
setShowAreaCheckModal,
|
|
3030
2851
|
selectedShippingMethod,
|
|
3031
2852
|
setSelectedShippingMethod,
|
|
3032
2853
|
shippingMethodsContext,
|
|
3033
|
-
showTip,
|
|
3034
|
-
setShowTip,
|
|
3035
2854
|
showMoreShippingMethod,
|
|
3036
2855
|
setShowMoreShippingMethod,
|
|
3037
|
-
|
|
3038
|
-
plusMemberProducts,
|
|
2856
|
+
selectedPlusMemberVariant,
|
|
3039
2857
|
product,
|
|
3040
2858
|
showPlusMemberBenefit,
|
|
3041
2859
|
setShowPlusMemberBenefit,
|
|
3042
|
-
|
|
3043
|
-
setDeleteMarginBottom,
|
|
3044
|
-
profile,
|
|
3045
|
-
locale
|
|
2860
|
+
profile
|
|
3046
2861
|
},
|
|
3047
2862
|
children
|
|
3048
2863
|
}
|
|
@@ -3228,6 +3043,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
3228
3043
|
}
|
|
3229
3044
|
}
|
|
3230
3045
|
|
|
3231
|
-
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection,
|
|
3046
|
+
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, hasPlusMemberInCart, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3232
3047
|
//# sourceMappingURL=index.mjs.map
|
|
3233
3048
|
//# sourceMappingURL=index.mjs.map
|