@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.js
CHANGED
|
@@ -1198,24 +1198,31 @@ function useRemoveCartLines(options) {
|
|
|
1198
1198
|
);
|
|
1199
1199
|
return useSWRMutation__default.default("remove-cart-lines", removeLines, options);
|
|
1200
1200
|
}
|
|
1201
|
-
function useUpdateCartAttributes(
|
|
1201
|
+
function useUpdateCartAttributes({
|
|
1202
|
+
mutate,
|
|
1203
|
+
metafieldIdentifiers,
|
|
1204
|
+
disabled = false,
|
|
1205
|
+
swrOptions
|
|
1206
|
+
}) {
|
|
1202
1207
|
const { client, locale, cartCookieAdapter } = useShopify();
|
|
1203
1208
|
const updateAttributes = react.useCallback(
|
|
1204
1209
|
async (_key, { arg }) => {
|
|
1210
|
+
if (disabled || !cartCookieAdapter?.getCartId(locale)) {
|
|
1211
|
+
return void 0;
|
|
1212
|
+
}
|
|
1205
1213
|
const updatedCart = await shopifySdk.updateCartAttributes(client, {
|
|
1206
1214
|
...arg,
|
|
1207
1215
|
metafieldIdentifiers,
|
|
1208
1216
|
cookieAdapter: cartCookieAdapter
|
|
1209
1217
|
});
|
|
1210
|
-
console.log("useUpdateCartAttributes updatedCart", updatedCart);
|
|
1211
1218
|
if (updatedCart) {
|
|
1212
1219
|
mutate(updatedCart);
|
|
1213
1220
|
}
|
|
1214
1221
|
return updatedCart;
|
|
1215
1222
|
},
|
|
1216
|
-
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
|
|
1223
|
+
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
|
|
1217
1224
|
);
|
|
1218
|
-
return useSWRMutation__default.default("update-cart-attributes", updateAttributes,
|
|
1225
|
+
return useSWRMutation__default.default("update-cart-attributes", updateAttributes, swrOptions);
|
|
1219
1226
|
}
|
|
1220
1227
|
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
1221
1228
|
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
@@ -1453,36 +1460,46 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
|
|
|
1453
1460
|
isLoading: isCustomerLoading
|
|
1454
1461
|
};
|
|
1455
1462
|
};
|
|
1456
|
-
function
|
|
1463
|
+
function hasPlusMemberInCart({
|
|
1457
1464
|
memberSetting,
|
|
1458
1465
|
cart
|
|
1459
1466
|
}) {
|
|
1460
1467
|
const { plus_monthly_product, plus_annual_product } = memberSetting || {};
|
|
1461
|
-
|
|
1462
|
-
if (!cart?.lineItems) {
|
|
1463
|
-
return {
|
|
1464
|
-
hasPlusMember: false,
|
|
1465
|
-
hasMonthlyPlus: false,
|
|
1466
|
-
hasAnnualPlus: false
|
|
1467
|
-
};
|
|
1468
|
-
}
|
|
1469
|
-
const monthlyPlusItem = cart.lineItems.find(
|
|
1470
|
-
(item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
|
|
1471
|
-
);
|
|
1472
|
-
const annualPlusItem = cart.lineItems.find(
|
|
1473
|
-
(item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
|
|
1474
|
-
);
|
|
1475
|
-
const hasMonthlyPlus = !!monthlyPlusItem;
|
|
1476
|
-
const hasAnnualPlus = !!annualPlusItem;
|
|
1477
|
-
const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
|
|
1468
|
+
if (!cart?.lineItems) {
|
|
1478
1469
|
return {
|
|
1479
|
-
hasPlusMember,
|
|
1480
|
-
hasMonthlyPlus,
|
|
1481
|
-
hasAnnualPlus
|
|
1482
|
-
monthlyPlusItem,
|
|
1483
|
-
annualPlusItem
|
|
1470
|
+
hasPlusMember: false,
|
|
1471
|
+
hasMonthlyPlus: false,
|
|
1472
|
+
hasAnnualPlus: false
|
|
1484
1473
|
};
|
|
1485
|
-
}
|
|
1474
|
+
}
|
|
1475
|
+
const monthlyPlusItem = cart.lineItems.find(
|
|
1476
|
+
(item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
|
|
1477
|
+
);
|
|
1478
|
+
const annualPlusItem = cart.lineItems.find(
|
|
1479
|
+
(item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
|
|
1480
|
+
);
|
|
1481
|
+
const hasMonthlyPlus = !!monthlyPlusItem;
|
|
1482
|
+
const hasAnnualPlus = !!annualPlusItem;
|
|
1483
|
+
const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
|
|
1484
|
+
return {
|
|
1485
|
+
hasPlusMember,
|
|
1486
|
+
hasMonthlyPlus,
|
|
1487
|
+
hasAnnualPlus,
|
|
1488
|
+
monthlyPlusItem,
|
|
1489
|
+
annualPlusItem
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
function useHasPlusMemberInCart({
|
|
1493
|
+
memberSetting,
|
|
1494
|
+
cart
|
|
1495
|
+
}) {
|
|
1496
|
+
return react.useMemo(
|
|
1497
|
+
() => hasPlusMemberInCart({
|
|
1498
|
+
memberSetting,
|
|
1499
|
+
cart
|
|
1500
|
+
}),
|
|
1501
|
+
[memberSetting, cart]
|
|
1502
|
+
);
|
|
1486
1503
|
}
|
|
1487
1504
|
var getReferralAttributes = () => {
|
|
1488
1505
|
const inviteCode = shopifySdk.getLocalStorage("inviteCode") || Cookies5__default.default.get("inviteCode");
|
|
@@ -1579,7 +1596,7 @@ var useCartAttributes = ({
|
|
|
1579
1596
|
})
|
|
1580
1597
|
}
|
|
1581
1598
|
] : [];
|
|
1582
|
-
}, [cart]);
|
|
1599
|
+
}, [cart, customer]);
|
|
1583
1600
|
const presellAttributes = react.useMemo(() => {
|
|
1584
1601
|
return [
|
|
1585
1602
|
{
|
|
@@ -1643,9 +1660,7 @@ var useCartAttributes = ({
|
|
|
1643
1660
|
"_play_mode_id",
|
|
1644
1661
|
"_popup"
|
|
1645
1662
|
];
|
|
1646
|
-
return cart?.customAttributes?.filter(
|
|
1647
|
-
(item) => !commonAttributeKeys.includes(item.key)
|
|
1648
|
-
) || [];
|
|
1663
|
+
return cart?.customAttributes?.filter((item) => !commonAttributeKeys.includes(item.key)) || [];
|
|
1649
1664
|
}, [cart]);
|
|
1650
1665
|
return react.useMemo(
|
|
1651
1666
|
() => ({
|
|
@@ -2463,28 +2478,13 @@ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
|
|
|
2463
2478
|
return ShippingMethodMode2;
|
|
2464
2479
|
})(ShippingMethodMode || {});
|
|
2465
2480
|
var createInitialValue = () => ({
|
|
2466
|
-
zipCode: "",
|
|
2467
2481
|
plusMemberMetafields: {},
|
|
2468
|
-
setZipCode: () => {
|
|
2469
|
-
},
|
|
2470
|
-
allowNextDayDelivery: false,
|
|
2471
|
-
setAllowNextDayDelivery: () => {
|
|
2472
|
-
},
|
|
2473
|
-
allowThirdDayDelivery: false,
|
|
2474
|
-
setAllowThirdDayDelivery: () => {
|
|
2475
|
-
},
|
|
2476
2482
|
selectedPlusMemberMode: "free",
|
|
2477
2483
|
setSelectedPlusMemberMode: () => {
|
|
2478
2484
|
},
|
|
2479
|
-
showAreaCheckModal: false,
|
|
2480
|
-
setShowAreaCheckModal: () => {
|
|
2481
|
-
},
|
|
2482
2485
|
selectedShippingMethod: void 0,
|
|
2483
2486
|
setSelectedShippingMethod: () => {
|
|
2484
2487
|
},
|
|
2485
|
-
showTip: false,
|
|
2486
|
-
setShowTip: () => {
|
|
2487
|
-
},
|
|
2488
2488
|
showMoreShippingMethod: false,
|
|
2489
2489
|
setShowMoreShippingMethod: () => {
|
|
2490
2490
|
},
|
|
@@ -2499,48 +2499,49 @@ var createInitialValue = () => ({
|
|
|
2499
2499
|
tddCoupon: void 0,
|
|
2500
2500
|
isLoadingCoupon: false
|
|
2501
2501
|
},
|
|
2502
|
-
|
|
2503
|
-
plusMemberProducts: [],
|
|
2502
|
+
selectedPlusMemberVariant: void 0,
|
|
2504
2503
|
showPlusMemberBenefit: false,
|
|
2505
2504
|
setShowPlusMemberBenefit: () => {
|
|
2506
2505
|
},
|
|
2507
|
-
|
|
2508
|
-
setDeleteMarginBottom: () => {
|
|
2509
|
-
},
|
|
2510
|
-
profile: void 0,
|
|
2511
|
-
locale: void 0
|
|
2506
|
+
profile: void 0
|
|
2512
2507
|
});
|
|
2513
2508
|
var PlusMemberContext = react.createContext(createInitialValue());
|
|
2514
2509
|
function usePlusMemberContext() {
|
|
2515
2510
|
return react.useContext(PlusMemberContext);
|
|
2516
2511
|
}
|
|
2517
|
-
function
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
const
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
);
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2512
|
+
function usePlusMemberVariants({
|
|
2513
|
+
memberSetting
|
|
2514
|
+
}) {
|
|
2515
|
+
const plusMonthly = memberSetting?.plus_monthly_product;
|
|
2516
|
+
const plusAnnual = memberSetting?.plus_annual_product;
|
|
2517
|
+
const plusMemberHandles = react.useMemo(() => {
|
|
2518
|
+
return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
|
|
2519
|
+
}, [plusMonthly?.handle, plusAnnual?.handle]);
|
|
2520
|
+
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2521
|
+
handles: plusMemberHandles
|
|
2522
|
+
});
|
|
2523
|
+
const monthlyProduct = react.useMemo(() => {
|
|
2524
|
+
return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
|
|
2528
2525
|
}, [plusMemberProducts, plusMonthly]);
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
function usePlusAnnualProductVariant() {
|
|
2532
|
-
const { plusMemberProducts, plusMemberMetafields } = usePlusMemberContext();
|
|
2533
|
-
const plusAnnual = plusMemberMetafields?.plus_annual_product;
|
|
2534
|
-
const plusAnnualProductVariant = react.useMemo(() => {
|
|
2535
|
-
const product = plusMemberProducts?.find(
|
|
2536
|
-
(item) => item?.handle === plusAnnual?.handle
|
|
2537
|
-
);
|
|
2538
|
-
const productVariant = product?.variants?.find(
|
|
2539
|
-
(item) => item.sku === plusAnnual?.sku
|
|
2540
|
-
);
|
|
2541
|
-
return productVariant;
|
|
2526
|
+
const annualProduct = react.useMemo(() => {
|
|
2527
|
+
return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
|
|
2542
2528
|
}, [plusMemberProducts, plusAnnual]);
|
|
2543
|
-
|
|
2529
|
+
const monthlyVariant = react.useMemo(() => {
|
|
2530
|
+
return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
|
|
2531
|
+
}, [monthlyProduct, plusMonthly]);
|
|
2532
|
+
const annualVariant = react.useMemo(() => {
|
|
2533
|
+
return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
|
|
2534
|
+
}, [annualProduct, plusAnnual]);
|
|
2535
|
+
return {
|
|
2536
|
+
monthlyVariant: monthlyVariant ? {
|
|
2537
|
+
...monthlyVariant,
|
|
2538
|
+
product: monthlyProduct
|
|
2539
|
+
} : void 0,
|
|
2540
|
+
annualVariant: annualVariant ? {
|
|
2541
|
+
...annualVariant,
|
|
2542
|
+
product: annualProduct
|
|
2543
|
+
} : void 0
|
|
2544
|
+
};
|
|
2544
2545
|
}
|
|
2545
2546
|
var useAvailableDeliveryCoupon = ({
|
|
2546
2547
|
profile
|
|
@@ -2562,9 +2563,9 @@ var useAvailableDeliveryCoupon = ({
|
|
|
2562
2563
|
|
|
2563
2564
|
// src/hooks/member/plus/use-shipping-methods.ts
|
|
2564
2565
|
function useShippingMethods(options) {
|
|
2565
|
-
const { variant, plusMemberMetafields, selectedPlusMemberMode,
|
|
2566
|
+
const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
|
|
2567
|
+
const isPlus = profile?.isPlus || false;
|
|
2566
2568
|
const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
|
|
2567
|
-
console.log("nddCoupon", nddCoupon);
|
|
2568
2569
|
const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
|
|
2569
2570
|
const nddOverweight = react.useMemo(() => {
|
|
2570
2571
|
return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
|
|
@@ -2691,69 +2692,6 @@ function useShippingMethods(options) {
|
|
|
2691
2692
|
isLoadingCoupon: isLoading
|
|
2692
2693
|
};
|
|
2693
2694
|
}
|
|
2694
|
-
function useShippingMethodAvailableCheck() {
|
|
2695
|
-
const {
|
|
2696
|
-
zipCode,
|
|
2697
|
-
allowNextDayDelivery,
|
|
2698
|
-
allowThirdDayDelivery,
|
|
2699
|
-
selectedShippingMethod,
|
|
2700
|
-
setSelectedShippingMethod,
|
|
2701
|
-
setShowTip,
|
|
2702
|
-
shippingMethodsContext
|
|
2703
|
-
} = usePlusMemberContext();
|
|
2704
|
-
react.useEffect(() => {
|
|
2705
|
-
const freeShippingMethod = shippingMethodsContext.freeShippingMethods[0];
|
|
2706
|
-
const standardShippingMethod = shippingMethodsContext.freeShippingMethods?.find(
|
|
2707
|
-
(item) => item.__mode === "free" /* FREE */
|
|
2708
|
-
);
|
|
2709
|
-
const freeTDD = shippingMethodsContext.freeShippingMethods.find(
|
|
2710
|
-
(item) => item.__mode === "tdd" /* TDD */
|
|
2711
|
-
);
|
|
2712
|
-
const paymentTDD = shippingMethodsContext.paymentShippingMethods.find(
|
|
2713
|
-
(item) => item.__mode === "tdd" /* TDD */
|
|
2714
|
-
);
|
|
2715
|
-
if (zipCode) {
|
|
2716
|
-
console.log(
|
|
2717
|
-
"allowNextDayDelivery, allowThirdDayDelivery:",
|
|
2718
|
-
allowNextDayDelivery,
|
|
2719
|
-
allowThirdDayDelivery
|
|
2720
|
-
);
|
|
2721
|
-
if (!allowNextDayDelivery && !allowThirdDayDelivery) {
|
|
2722
|
-
setShowTip(true);
|
|
2723
|
-
setSelectedShippingMethod(standardShippingMethod);
|
|
2724
|
-
} else {
|
|
2725
|
-
if (selectedShippingMethod?.__mode === "ndd" /* NDD */ && !allowNextDayDelivery) {
|
|
2726
|
-
setShowTip(true);
|
|
2727
|
-
if (allowThirdDayDelivery) {
|
|
2728
|
-
if (selectedShippingMethod.useCoupon) {
|
|
2729
|
-
const method = freeTDD || freeShippingMethod;
|
|
2730
|
-
if (method) setSelectedShippingMethod(method);
|
|
2731
|
-
} else {
|
|
2732
|
-
const method = paymentTDD || freeShippingMethod;
|
|
2733
|
-
if (method) setSelectedShippingMethod(method);
|
|
2734
|
-
}
|
|
2735
|
-
} else {
|
|
2736
|
-
if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
|
|
2737
|
-
}
|
|
2738
|
-
} else if (
|
|
2739
|
-
// TDD 无法使用
|
|
2740
|
-
selectedShippingMethod?.__mode === "tdd" /* TDD */ && !allowThirdDayDelivery
|
|
2741
|
-
) {
|
|
2742
|
-
setShowTip(true);
|
|
2743
|
-
if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
}, [
|
|
2748
|
-
allowNextDayDelivery,
|
|
2749
|
-
allowThirdDayDelivery,
|
|
2750
|
-
zipCode,
|
|
2751
|
-
shippingMethodsContext,
|
|
2752
|
-
selectedShippingMethod,
|
|
2753
|
-
setSelectedShippingMethod,
|
|
2754
|
-
setShowTip
|
|
2755
|
-
]);
|
|
2756
|
-
}
|
|
2757
2695
|
var useReplaceCartPlusMember = () => {
|
|
2758
2696
|
const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
|
|
2759
2697
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
@@ -2785,129 +2723,45 @@ var useReplaceCartPlusMember = () => {
|
|
|
2785
2723
|
]);
|
|
2786
2724
|
return handler;
|
|
2787
2725
|
};
|
|
2788
|
-
var usePlusMemberDeliveryCodes = ({
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
return react.useMemo(
|
|
2792
|
-
() => deliveryData?.deliveryCustomData?.discount_code,
|
|
2793
|
-
[deliveryData]
|
|
2794
|
-
);
|
|
2795
|
-
};
|
|
2796
|
-
function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
|
|
2797
|
-
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2798
|
-
const updateDeliveryOptions = react.useCallback(
|
|
2799
|
-
async (_key, { arg }) => {
|
|
2800
|
-
const updatedCart = await shopifySdk.updateCartDeliveryOptions(client, {
|
|
2801
|
-
...arg,
|
|
2802
|
-
metafieldIdentifiers,
|
|
2803
|
-
cookieAdapter: cartCookieAdapter
|
|
2804
|
-
});
|
|
2805
|
-
console.log("useUpdateCartDeliveryOptions updatedCart", updatedCart);
|
|
2806
|
-
if (updatedCart) {
|
|
2807
|
-
mutate(updatedCart);
|
|
2808
|
-
}
|
|
2809
|
-
return updatedCart;
|
|
2810
|
-
},
|
|
2811
|
-
[client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
|
|
2812
|
-
);
|
|
2813
|
-
return useSWRMutation__default.default("update-cart-delivery-options", updateDeliveryOptions, options);
|
|
2814
|
-
}
|
|
2815
|
-
|
|
2816
|
-
// src/hooks/member/plus/use-update-plus-member-delivery-options.ts
|
|
2817
|
-
var useUpdatePlusMemberDeliveryOptions = ({
|
|
2818
|
-
options
|
|
2819
|
-
} = {}) => {
|
|
2820
|
-
const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
|
|
2821
|
-
const { trigger: updateCartDeliveryOptions2 } = useUpdateCartDeliveryOptions(
|
|
2822
|
-
mutateCart,
|
|
2823
|
-
metafieldIdentifiers
|
|
2824
|
-
);
|
|
2825
|
-
const handler = react.useCallback(
|
|
2826
|
-
async (_, { arg }) => {
|
|
2827
|
-
const currentCart = arg?.cart || cartContextData;
|
|
2828
|
-
const { deliveryData } = arg;
|
|
2829
|
-
const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
|
|
2830
|
-
const deliveryGroupId = firstDeliveryGroup?.id;
|
|
2831
|
-
const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
|
|
2832
|
-
if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
|
|
2833
|
-
return null;
|
|
2834
|
-
}
|
|
2835
|
-
const deliveryGroup = currentCart?.deliveryGroups?.find(
|
|
2836
|
-
(group) => group?.id === deliveryGroupId
|
|
2837
|
-
);
|
|
2838
|
-
const matchedOption = deliveryGroup?.deliveryOptions?.find(
|
|
2839
|
-
(option) => option?.code === selectedOptionCode
|
|
2840
|
-
);
|
|
2841
|
-
if (!matchedOption?.handle) {
|
|
2842
|
-
return null;
|
|
2843
|
-
}
|
|
2844
|
-
const deliveryOptions = [
|
|
2845
|
-
{
|
|
2846
|
-
deliveryGroupId,
|
|
2847
|
-
deliveryOptionHandle: matchedOption.handle
|
|
2848
|
-
}
|
|
2849
|
-
];
|
|
2850
|
-
const updatedCart = await updateCartDeliveryOptions2({
|
|
2851
|
-
selectedDeliveryOptions: deliveryOptions,
|
|
2852
|
-
cartId: currentCart?.id
|
|
2853
|
-
});
|
|
2854
|
-
if (updatedCart && mutateCart) {
|
|
2855
|
-
mutateCart(updatedCart);
|
|
2856
|
-
}
|
|
2857
|
-
return updatedCart;
|
|
2858
|
-
},
|
|
2859
|
-
[cartContextData, updateCartDeliveryOptions2, mutateCart]
|
|
2860
|
-
);
|
|
2861
|
-
return useSWRMutation__default.default("update-cart-delivery-options", handler, options);
|
|
2862
|
-
};
|
|
2863
|
-
var usePlusMemberItemCustomAttributes = ({
|
|
2864
|
-
deliveryData
|
|
2865
|
-
}) => {
|
|
2866
|
-
const { deliveryCustomData } = deliveryData || {};
|
|
2867
|
-
return react.useMemo(() => {
|
|
2868
|
-
const itemCustomAttributes = [];
|
|
2869
|
-
if (deliveryCustomData?.is_presale) {
|
|
2870
|
-
itemCustomAttributes.push({
|
|
2871
|
-
key: "_is_presale",
|
|
2872
|
-
value: "true"
|
|
2873
|
-
});
|
|
2874
|
-
}
|
|
2875
|
-
return itemCustomAttributes;
|
|
2876
|
-
}, [deliveryCustomData]);
|
|
2726
|
+
var usePlusMemberDeliveryCodes = () => {
|
|
2727
|
+
const { selectedShippingMethod } = usePlusMemberContext();
|
|
2728
|
+
return react.useMemo(() => [selectedShippingMethod?.coupon], [selectedShippingMethod?.coupon]);
|
|
2877
2729
|
};
|
|
2878
2730
|
var usePlusMemberCheckoutCustomAttributes = ({
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
variant,
|
|
2882
|
-
isShowShippingBenefits
|
|
2731
|
+
disableShipping = false,
|
|
2732
|
+
isPresaleContains = false
|
|
2883
2733
|
}) => {
|
|
2884
|
-
const {
|
|
2885
|
-
const { profile } = usePlusMemberContext();
|
|
2734
|
+
const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
|
|
2886
2735
|
return react.useMemo(() => {
|
|
2887
2736
|
const checkoutCustomAttributes = [
|
|
2888
|
-
// _last_url: 付费会员结算完成之后 checkout 有一个继续购买的按钮, 用于跳转到继续购买的页面
|
|
2889
2737
|
{
|
|
2890
2738
|
key: "_last_url",
|
|
2891
2739
|
value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
|
|
2892
2740
|
}
|
|
2893
2741
|
];
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2742
|
+
checkoutCustomAttributes.push({
|
|
2743
|
+
key: "_checkout_delivery_custom",
|
|
2744
|
+
value: JSON.stringify({
|
|
2745
|
+
allow_nextday_delivery: true,
|
|
2746
|
+
allow_thirdday_delivery: true,
|
|
2747
|
+
selected_delivery_option: {
|
|
2748
|
+
code: selectedShippingMethod?.__code,
|
|
2749
|
+
mode: selectedShippingMethod?.__mode
|
|
2750
|
+
},
|
|
2751
|
+
is_presale: isPresaleContains,
|
|
2752
|
+
discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
|
|
2753
|
+
plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
|
|
2754
|
+
is_prime: profile?.isPlus
|
|
2755
|
+
})
|
|
2756
|
+
});
|
|
2757
|
+
if (disableShipping) {
|
|
2904
2758
|
checkoutCustomAttributes.push({
|
|
2905
2759
|
key: "_hide_shipping",
|
|
2906
2760
|
value: "true"
|
|
2907
2761
|
});
|
|
2908
2762
|
}
|
|
2909
2763
|
return checkoutCustomAttributes;
|
|
2910
|
-
}, [
|
|
2764
|
+
}, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
|
|
2911
2765
|
};
|
|
2912
2766
|
function useAutoRemovePlusMemberInCart({
|
|
2913
2767
|
cart,
|
|
@@ -2941,13 +2795,13 @@ function usePlusMemberNeedAddToCart({
|
|
|
2941
2795
|
cart,
|
|
2942
2796
|
profile
|
|
2943
2797
|
}) {
|
|
2944
|
-
const { selectedPlusMemberMode,
|
|
2798
|
+
const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
|
|
2945
2799
|
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2946
2800
|
memberSetting: plusMemberMetafields,
|
|
2947
2801
|
cart
|
|
2948
2802
|
});
|
|
2949
|
-
const
|
|
2950
|
-
if (!
|
|
2803
|
+
const plusMemberVariant = react.useMemo(() => {
|
|
2804
|
+
if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
|
|
2951
2805
|
return void 0;
|
|
2952
2806
|
}
|
|
2953
2807
|
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
@@ -2962,15 +2816,9 @@ function usePlusMemberNeedAddToCart({
|
|
|
2962
2816
|
if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
|
|
2963
2817
|
return void 0;
|
|
2964
2818
|
}
|
|
2965
|
-
return
|
|
2966
|
-
}, [
|
|
2967
|
-
|
|
2968
|
-
selectedPlusMemberProduct?.variant,
|
|
2969
|
-
selectedPlusMemberProduct?.product,
|
|
2970
|
-
hasMonthlyPlus,
|
|
2971
|
-
hasAnnualPlus
|
|
2972
|
-
]);
|
|
2973
|
-
return plusMemberProduct;
|
|
2819
|
+
return selectedPlusMemberVariant;
|
|
2820
|
+
}, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
|
|
2821
|
+
return plusMemberVariant;
|
|
2974
2822
|
}
|
|
2975
2823
|
var PlusMemberProvider = ({
|
|
2976
2824
|
variant,
|
|
@@ -2980,78 +2828,45 @@ var PlusMemberProvider = ({
|
|
|
2980
2828
|
profile,
|
|
2981
2829
|
children
|
|
2982
2830
|
}) => {
|
|
2983
|
-
const { locale } = useShopify();
|
|
2984
|
-
const [zipCode, setZipCode] = react.useState("");
|
|
2985
|
-
const [showTip, setShowTip] = react.useState(false);
|
|
2986
2831
|
const [selectedPlusMemberMode, setSelectedPlusMemberMode] = react.useState(
|
|
2987
2832
|
initialSelectedPlusMemberMode
|
|
2988
2833
|
);
|
|
2989
2834
|
const [selectedShippingMethod, setSelectedShippingMethod] = react.useState();
|
|
2990
|
-
const [allowNextDayDelivery, setAllowNextDayDelivery] = react.useState(false);
|
|
2991
|
-
const [allowThirdDayDelivery, setAllowThirdDayDelivery] = react.useState(false);
|
|
2992
|
-
const [showAreaCheckModal, setShowAreaCheckModal] = react.useState(false);
|
|
2993
2835
|
const [showMoreShippingMethod, setShowMoreShippingMethod] = react.useState(false);
|
|
2994
2836
|
const [showPlusMemberBenefit, setShowPlusMemberBenefit] = react.useState(false);
|
|
2995
|
-
const [deleteMarginBottom, setDeleteMarginBottom] = react.useState(false);
|
|
2996
2837
|
const shippingMethodsContext = useShippingMethods({
|
|
2997
2838
|
variant,
|
|
2998
2839
|
plusMemberMetafields: memberSetting,
|
|
2999
2840
|
selectedPlusMemberMode,
|
|
3000
|
-
profile
|
|
3001
|
-
isPlus: profile?.isPlus || false
|
|
2841
|
+
profile
|
|
3002
2842
|
});
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
return [
|
|
3006
|
-
memberSetting?.plus_monthly_product?.handle,
|
|
3007
|
-
memberSetting?.plus_annual_product?.handle
|
|
3008
|
-
].filter(Boolean);
|
|
3009
|
-
}, [memberSetting]);
|
|
3010
|
-
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
3011
|
-
handles: plusMemberHandles
|
|
2843
|
+
const { monthlyVariant, annualVariant } = usePlusMemberVariants({
|
|
2844
|
+
memberSetting
|
|
3012
2845
|
});
|
|
3013
|
-
const
|
|
2846
|
+
const selectedPlusMemberVariant = react.useMemo(() => {
|
|
3014
2847
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
3015
|
-
return
|
|
2848
|
+
return void 0;
|
|
3016
2849
|
}
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
3020
|
-
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
3021
|
-
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
3022
|
-
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2850
|
+
return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
|
|
2851
|
+
}, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
|
|
3023
2852
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3024
2853
|
PlusMemberContext.Provider,
|
|
3025
2854
|
{
|
|
3026
2855
|
value: {
|
|
3027
2856
|
variant,
|
|
3028
|
-
zipCode,
|
|
3029
|
-
setZipCode,
|
|
3030
|
-
allowNextDayDelivery,
|
|
3031
|
-
setAllowNextDayDelivery,
|
|
3032
|
-
allowThirdDayDelivery,
|
|
3033
|
-
setAllowThirdDayDelivery,
|
|
3034
2857
|
plusMemberMetafields: memberSetting,
|
|
3035
2858
|
selectedPlusMemberMode,
|
|
3036
2859
|
setSelectedPlusMemberMode,
|
|
3037
|
-
showAreaCheckModal,
|
|
3038
|
-
setShowAreaCheckModal,
|
|
3039
2860
|
selectedShippingMethod,
|
|
3040
2861
|
setSelectedShippingMethod,
|
|
3041
2862
|
shippingMethodsContext,
|
|
3042
|
-
showTip,
|
|
3043
|
-
setShowTip,
|
|
3044
2863
|
showMoreShippingMethod,
|
|
3045
2864
|
setShowMoreShippingMethod,
|
|
3046
|
-
|
|
3047
|
-
plusMemberProducts,
|
|
2865
|
+
selectedPlusMemberVariant,
|
|
3048
2866
|
product,
|
|
3049
2867
|
showPlusMemberBenefit,
|
|
3050
2868
|
setShowPlusMemberBenefit,
|
|
3051
|
-
|
|
3052
|
-
setDeleteMarginBottom,
|
|
3053
|
-
profile,
|
|
3054
|
-
locale
|
|
2869
|
+
profile
|
|
3055
2870
|
},
|
|
3056
2871
|
children
|
|
3057
2872
|
}
|
|
@@ -3268,6 +3083,7 @@ exports.getDiscountEnvAttributeValue = getDiscountEnvAttributeValue;
|
|
|
3268
3083
|
exports.getMatchedMainProductSubTotal = getMatchedMainProductSubTotal;
|
|
3269
3084
|
exports.getQuery = getQuery;
|
|
3270
3085
|
exports.getReferralAttributes = getReferralAttributes;
|
|
3086
|
+
exports.hasPlusMemberInCart = hasPlusMemberInCart;
|
|
3271
3087
|
exports.normalizeAddToCartLines = normalizeAddToCartLines;
|
|
3272
3088
|
exports.preCheck = preCheck;
|
|
3273
3089
|
exports.safeParse = safeParse;
|
|
@@ -3296,13 +3112,11 @@ exports.useExposure = useExposure;
|
|
|
3296
3112
|
exports.useGeoLocation = useGeoLocation;
|
|
3297
3113
|
exports.useHasPlusMemberInCart = useHasPlusMemberInCart;
|
|
3298
3114
|
exports.useIntersection = useIntersection;
|
|
3299
|
-
exports.usePlusAnnualProductVariant = usePlusAnnualProductVariant;
|
|
3300
3115
|
exports.usePlusMemberCheckoutCustomAttributes = usePlusMemberCheckoutCustomAttributes;
|
|
3301
3116
|
exports.usePlusMemberContext = usePlusMemberContext;
|
|
3302
3117
|
exports.usePlusMemberDeliveryCodes = usePlusMemberDeliveryCodes;
|
|
3303
|
-
exports.usePlusMemberItemCustomAttributes = usePlusMemberItemCustomAttributes;
|
|
3304
3118
|
exports.usePlusMemberNeedAddToCart = usePlusMemberNeedAddToCart;
|
|
3305
|
-
exports.
|
|
3119
|
+
exports.usePlusMemberVariants = usePlusMemberVariants;
|
|
3306
3120
|
exports.usePrice = usePrice;
|
|
3307
3121
|
exports.useProduct = useProduct;
|
|
3308
3122
|
exports.useProductUrl = useProductUrl;
|
|
@@ -3313,13 +3127,11 @@ exports.useReplaceCartPlusMember = useReplaceCartPlusMember;
|
|
|
3313
3127
|
exports.useScriptAutoFreeGift = useScriptAutoFreeGift;
|
|
3314
3128
|
exports.useSearch = useSearch;
|
|
3315
3129
|
exports.useSelectedOptions = useSelectedOptions;
|
|
3316
|
-
exports.useShippingMethodAvailableCheck = useShippingMethodAvailableCheck;
|
|
3317
3130
|
exports.useShippingMethods = useShippingMethods;
|
|
3318
3131
|
exports.useSite = useSite;
|
|
3319
3132
|
exports.useUpdateCartAttributes = useUpdateCartAttributes;
|
|
3320
3133
|
exports.useUpdateCartLines = useUpdateCartLines;
|
|
3321
3134
|
exports.useUpdateLineCodeAmountAttributes = useUpdateLineCodeAmountAttributes;
|
|
3322
|
-
exports.useUpdatePlusMemberDeliveryOptions = useUpdatePlusMemberDeliveryOptions;
|
|
3323
3135
|
exports.useUpdateVariantQuery = useUpdateVariantQuery;
|
|
3324
3136
|
exports.useVariant = useVariant;
|
|
3325
3137
|
exports.useVariantMedia = useVariantMedia;
|