@anker-in/shopify-react 0.1.1-beta.42 → 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.
@@ -1460,36 +1460,46 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1460
1460
  isLoading: isCustomerLoading
1461
1461
  };
1462
1462
  };
1463
- function useHasPlusMemberInCart({
1463
+ function hasPlusMemberInCart({
1464
1464
  memberSetting,
1465
1465
  cart
1466
1466
  }) {
1467
1467
  const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1468
- return react.useMemo(() => {
1469
- if (!cart?.lineItems) {
1470
- return {
1471
- hasPlusMember: false,
1472
- hasMonthlyPlus: false,
1473
- hasAnnualPlus: false
1474
- };
1475
- }
1476
- const monthlyPlusItem = cart.lineItems.find(
1477
- (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
1478
- );
1479
- const annualPlusItem = cart.lineItems.find(
1480
- (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
1481
- );
1482
- const hasMonthlyPlus = !!monthlyPlusItem;
1483
- const hasAnnualPlus = !!annualPlusItem;
1484
- const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1468
+ if (!cart?.lineItems) {
1485
1469
  return {
1486
- hasPlusMember,
1487
- hasMonthlyPlus,
1488
- hasAnnualPlus,
1489
- monthlyPlusItem,
1490
- annualPlusItem
1470
+ hasPlusMember: false,
1471
+ hasMonthlyPlus: false,
1472
+ hasAnnualPlus: false
1491
1473
  };
1492
- }, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
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
+ );
1493
1503
  }
1494
1504
  var getReferralAttributes = () => {
1495
1505
  const inviteCode = shopifySdk.getLocalStorage("inviteCode") || Cookies5__default.default.get("inviteCode");
@@ -2468,28 +2478,13 @@ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
2468
2478
  return ShippingMethodMode2;
2469
2479
  })(ShippingMethodMode || {});
2470
2480
  var createInitialValue = () => ({
2471
- zipCode: "",
2472
2481
  plusMemberMetafields: {},
2473
- setZipCode: () => {
2474
- },
2475
- allowNextDayDelivery: false,
2476
- setAllowNextDayDelivery: () => {
2477
- },
2478
- allowThirdDayDelivery: false,
2479
- setAllowThirdDayDelivery: () => {
2480
- },
2481
2482
  selectedPlusMemberMode: "free",
2482
2483
  setSelectedPlusMemberMode: () => {
2483
2484
  },
2484
- showAreaCheckModal: false,
2485
- setShowAreaCheckModal: () => {
2486
- },
2487
2485
  selectedShippingMethod: void 0,
2488
2486
  setSelectedShippingMethod: () => {
2489
2487
  },
2490
- showTip: false,
2491
- setShowTip: () => {
2492
- },
2493
2488
  showMoreShippingMethod: false,
2494
2489
  setShowMoreShippingMethod: () => {
2495
2490
  },
@@ -2505,16 +2500,10 @@ var createInitialValue = () => ({
2505
2500
  isLoadingCoupon: false
2506
2501
  },
2507
2502
  selectedPlusMemberVariant: void 0,
2508
- monthlyVariant: void 0,
2509
- annualVariant: void 0,
2510
2503
  showPlusMemberBenefit: false,
2511
2504
  setShowPlusMemberBenefit: () => {
2512
2505
  },
2513
- deleteMarginBottom: false,
2514
- setDeleteMarginBottom: () => {
2515
- },
2516
- profile: void 0,
2517
- locale: void 0
2506
+ profile: void 0
2518
2507
  });
2519
2508
  var PlusMemberContext = react.createContext(createInitialValue());
2520
2509
  function usePlusMemberContext() {
@@ -2574,9 +2563,9 @@ var useAvailableDeliveryCoupon = ({
2574
2563
 
2575
2564
  // src/hooks/member/plus/use-shipping-methods.ts
2576
2565
  function useShippingMethods(options) {
2577
- const { variant, plusMemberMetafields, selectedPlusMemberMode, isPlus = false, profile } = options;
2566
+ const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
2567
+ const isPlus = profile?.isPlus || false;
2578
2568
  const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
2579
- console.log("nddCoupon", nddCoupon);
2580
2569
  const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
2581
2570
  const nddOverweight = react.useMemo(() => {
2582
2571
  return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
@@ -2703,69 +2692,6 @@ function useShippingMethods(options) {
2703
2692
  isLoadingCoupon: isLoading
2704
2693
  };
2705
2694
  }
2706
- function useShippingMethodAvailableCheck() {
2707
- const {
2708
- zipCode,
2709
- allowNextDayDelivery,
2710
- allowThirdDayDelivery,
2711
- selectedShippingMethod,
2712
- setSelectedShippingMethod,
2713
- setShowTip,
2714
- shippingMethodsContext
2715
- } = usePlusMemberContext();
2716
- react.useEffect(() => {
2717
- const freeShippingMethod = shippingMethodsContext.freeShippingMethods[0];
2718
- const standardShippingMethod = shippingMethodsContext.freeShippingMethods?.find(
2719
- (item) => item.__mode === "free" /* FREE */
2720
- );
2721
- const freeTDD = shippingMethodsContext.freeShippingMethods.find(
2722
- (item) => item.__mode === "tdd" /* TDD */
2723
- );
2724
- const paymentTDD = shippingMethodsContext.paymentShippingMethods.find(
2725
- (item) => item.__mode === "tdd" /* TDD */
2726
- );
2727
- if (zipCode) {
2728
- console.log(
2729
- "allowNextDayDelivery, allowThirdDayDelivery:",
2730
- allowNextDayDelivery,
2731
- allowThirdDayDelivery
2732
- );
2733
- if (!allowNextDayDelivery && !allowThirdDayDelivery) {
2734
- setShowTip(true);
2735
- setSelectedShippingMethod(standardShippingMethod);
2736
- } else {
2737
- if (selectedShippingMethod?.__mode === "ndd" /* NDD */ && !allowNextDayDelivery) {
2738
- setShowTip(true);
2739
- if (allowThirdDayDelivery) {
2740
- if (selectedShippingMethod.useCoupon) {
2741
- const method = freeTDD || freeShippingMethod;
2742
- if (method) setSelectedShippingMethod(method);
2743
- } else {
2744
- const method = paymentTDD || freeShippingMethod;
2745
- if (method) setSelectedShippingMethod(method);
2746
- }
2747
- } else {
2748
- if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
2749
- }
2750
- } else if (
2751
- // TDD 无法使用
2752
- selectedShippingMethod?.__mode === "tdd" /* TDD */ && !allowThirdDayDelivery
2753
- ) {
2754
- setShowTip(true);
2755
- if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
2756
- }
2757
- }
2758
- }
2759
- }, [
2760
- allowNextDayDelivery,
2761
- allowThirdDayDelivery,
2762
- zipCode,
2763
- shippingMethodsContext,
2764
- selectedShippingMethod,
2765
- setSelectedShippingMethod,
2766
- setShowTip
2767
- ]);
2768
- }
2769
2695
  var useReplaceCartPlusMember = () => {
2770
2696
  const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
2771
2697
  const { trigger: removeCartLines2 } = useRemoveCartLines();
@@ -2797,129 +2723,45 @@ var useReplaceCartPlusMember = () => {
2797
2723
  ]);
2798
2724
  return handler;
2799
2725
  };
2800
- var usePlusMemberDeliveryCodes = ({
2801
- deliveryData
2802
- }) => {
2803
- return react.useMemo(
2804
- () => deliveryData?.deliveryCustomData?.discount_code,
2805
- [deliveryData]
2806
- );
2807
- };
2808
- function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
2809
- const { client, locale, cartCookieAdapter } = useShopify();
2810
- const updateDeliveryOptions = react.useCallback(
2811
- async (_key, { arg }) => {
2812
- const updatedCart = await shopifySdk.updateCartDeliveryOptions(client, {
2813
- ...arg,
2814
- metafieldIdentifiers,
2815
- cookieAdapter: cartCookieAdapter
2816
- });
2817
- console.log("useUpdateCartDeliveryOptions updatedCart", updatedCart);
2818
- if (updatedCart) {
2819
- mutate(updatedCart);
2820
- }
2821
- return updatedCart;
2822
- },
2823
- [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
2824
- );
2825
- return useSWRMutation__default.default("update-cart-delivery-options", updateDeliveryOptions, options);
2826
- }
2827
-
2828
- // src/hooks/member/plus/use-update-plus-member-delivery-options.ts
2829
- var useUpdatePlusMemberDeliveryOptions = ({
2830
- options
2831
- } = {}) => {
2832
- const { cart: cartContextData, mutateCart, metafieldIdentifiers } = useCartContext();
2833
- const { trigger: updateCartDeliveryOptions2 } = useUpdateCartDeliveryOptions(
2834
- mutateCart,
2835
- metafieldIdentifiers
2836
- );
2837
- const handler = react.useCallback(
2838
- async (_, { arg }) => {
2839
- const currentCart = arg?.cart || cartContextData;
2840
- const { deliveryData } = arg;
2841
- const firstDeliveryGroup = currentCart?.deliveryGroups?.[0];
2842
- const deliveryGroupId = firstDeliveryGroup?.id;
2843
- const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
2844
- if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
2845
- return null;
2846
- }
2847
- const deliveryGroup = currentCart?.deliveryGroups?.find(
2848
- (group) => group?.id === deliveryGroupId
2849
- );
2850
- const matchedOption = deliveryGroup?.deliveryOptions?.find(
2851
- (option) => option?.code === selectedOptionCode
2852
- );
2853
- if (!matchedOption?.handle) {
2854
- return null;
2855
- }
2856
- const deliveryOptions = [
2857
- {
2858
- deliveryGroupId,
2859
- deliveryOptionHandle: matchedOption.handle
2860
- }
2861
- ];
2862
- const updatedCart = await updateCartDeliveryOptions2({
2863
- selectedDeliveryOptions: deliveryOptions,
2864
- cartId: currentCart?.id
2865
- });
2866
- if (updatedCart && mutateCart) {
2867
- mutateCart(updatedCart);
2868
- }
2869
- return updatedCart;
2870
- },
2871
- [cartContextData, updateCartDeliveryOptions2, mutateCart]
2872
- );
2873
- return useSWRMutation__default.default("update-cart-delivery-options", handler, options);
2874
- };
2875
- var usePlusMemberItemCustomAttributes = ({
2876
- deliveryData
2877
- }) => {
2878
- const { deliveryCustomData } = deliveryData || {};
2879
- return react.useMemo(() => {
2880
- const itemCustomAttributes = [];
2881
- if (deliveryCustomData?.is_presale) {
2882
- itemCustomAttributes.push({
2883
- key: "_is_presale",
2884
- value: "true"
2885
- });
2886
- }
2887
- return itemCustomAttributes;
2888
- }, [deliveryCustomData]);
2726
+ var usePlusMemberDeliveryCodes = () => {
2727
+ const { selectedShippingMethod } = usePlusMemberContext();
2728
+ return react.useMemo(() => [selectedShippingMethod?.coupon], [selectedShippingMethod?.coupon]);
2889
2729
  };
2890
2730
  var usePlusMemberCheckoutCustomAttributes = ({
2891
- deliveryData,
2892
- product,
2893
- variant,
2894
- isShowShippingBenefits
2731
+ disableShipping = false,
2732
+ isPresaleContains = false
2895
2733
  }) => {
2896
- const { deliveryCustomData } = deliveryData || {};
2897
- const { profile } = usePlusMemberContext();
2734
+ const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
2898
2735
  return react.useMemo(() => {
2899
2736
  const checkoutCustomAttributes = [
2900
- // _last_url: 付费会员结算完成之后 checkout 有一个继续购买的按钮, 用于跳转到继续购买的页面
2901
2737
  {
2902
2738
  key: "_last_url",
2903
2739
  value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2904
2740
  }
2905
2741
  ];
2906
- if (deliveryCustomData) {
2907
- checkoutCustomAttributes.push({
2908
- key: "_checkout_delivery_custom",
2909
- value: JSON.stringify({
2910
- ...deliveryCustomData,
2911
- is_prime: profile?.isPlus
2912
- })
2913
- });
2914
- }
2915
- if (isShowShippingBenefits && !isShowShippingBenefits({ variant, product, setting: {} })) {
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) {
2916
2758
  checkoutCustomAttributes.push({
2917
2759
  key: "_hide_shipping",
2918
2760
  value: "true"
2919
2761
  });
2920
2762
  }
2921
2763
  return checkoutCustomAttributes;
2922
- }, [deliveryCustomData, product, profile, variant, isShowShippingBenefits]);
2764
+ }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
2923
2765
  };
2924
2766
  function useAutoRemovePlusMemberInCart({
2925
2767
  cart,
@@ -2986,25 +2828,17 @@ var PlusMemberProvider = ({
2986
2828
  profile,
2987
2829
  children
2988
2830
  }) => {
2989
- const { locale } = useShopify();
2990
- const [zipCode, setZipCode] = react.useState("");
2991
- const [showTip, setShowTip] = react.useState(false);
2992
2831
  const [selectedPlusMemberMode, setSelectedPlusMemberMode] = react.useState(
2993
2832
  initialSelectedPlusMemberMode
2994
2833
  );
2995
2834
  const [selectedShippingMethod, setSelectedShippingMethod] = react.useState();
2996
- const [allowNextDayDelivery, setAllowNextDayDelivery] = react.useState(false);
2997
- const [allowThirdDayDelivery, setAllowThirdDayDelivery] = react.useState(false);
2998
- const [showAreaCheckModal, setShowAreaCheckModal] = react.useState(false);
2999
2835
  const [showMoreShippingMethod, setShowMoreShippingMethod] = react.useState(false);
3000
2836
  const [showPlusMemberBenefit, setShowPlusMemberBenefit] = react.useState(false);
3001
- const [deleteMarginBottom, setDeleteMarginBottom] = react.useState(false);
3002
2837
  const shippingMethodsContext = useShippingMethods({
3003
2838
  variant,
3004
2839
  plusMemberMetafields: memberSetting,
3005
2840
  selectedPlusMemberMode,
3006
- profile,
3007
- isPlus: profile?.isPlus || false
2841
+ profile
3008
2842
  });
3009
2843
  const { monthlyVariant, annualVariant } = usePlusMemberVariants({
3010
2844
  memberSetting
@@ -3020,34 +2854,19 @@ var PlusMemberProvider = ({
3020
2854
  {
3021
2855
  value: {
3022
2856
  variant,
3023
- zipCode,
3024
- setZipCode,
3025
- allowNextDayDelivery,
3026
- setAllowNextDayDelivery,
3027
- allowThirdDayDelivery,
3028
- setAllowThirdDayDelivery,
3029
2857
  plusMemberMetafields: memberSetting,
3030
2858
  selectedPlusMemberMode,
3031
2859
  setSelectedPlusMemberMode,
3032
- showAreaCheckModal,
3033
- setShowAreaCheckModal,
3034
2860
  selectedShippingMethod,
3035
2861
  setSelectedShippingMethod,
3036
2862
  shippingMethodsContext,
3037
- showTip,
3038
- setShowTip,
3039
2863
  showMoreShippingMethod,
3040
2864
  setShowMoreShippingMethod,
3041
2865
  selectedPlusMemberVariant,
3042
- monthlyVariant,
3043
- annualVariant,
3044
2866
  product,
3045
2867
  showPlusMemberBenefit,
3046
2868
  setShowPlusMemberBenefit,
3047
- deleteMarginBottom,
3048
- setDeleteMarginBottom,
3049
- profile,
3050
- locale
2869
+ profile
3051
2870
  },
3052
2871
  children
3053
2872
  }
@@ -3264,6 +3083,7 @@ exports.getDiscountEnvAttributeValue = getDiscountEnvAttributeValue;
3264
3083
  exports.getMatchedMainProductSubTotal = getMatchedMainProductSubTotal;
3265
3084
  exports.getQuery = getQuery;
3266
3085
  exports.getReferralAttributes = getReferralAttributes;
3086
+ exports.hasPlusMemberInCart = hasPlusMemberInCart;
3267
3087
  exports.normalizeAddToCartLines = normalizeAddToCartLines;
3268
3088
  exports.preCheck = preCheck;
3269
3089
  exports.safeParse = safeParse;
@@ -3295,7 +3115,6 @@ exports.useIntersection = useIntersection;
3295
3115
  exports.usePlusMemberCheckoutCustomAttributes = usePlusMemberCheckoutCustomAttributes;
3296
3116
  exports.usePlusMemberContext = usePlusMemberContext;
3297
3117
  exports.usePlusMemberDeliveryCodes = usePlusMemberDeliveryCodes;
3298
- exports.usePlusMemberItemCustomAttributes = usePlusMemberItemCustomAttributes;
3299
3118
  exports.usePlusMemberNeedAddToCart = usePlusMemberNeedAddToCart;
3300
3119
  exports.usePlusMemberVariants = usePlusMemberVariants;
3301
3120
  exports.usePrice = usePrice;
@@ -3308,13 +3127,11 @@ exports.useReplaceCartPlusMember = useReplaceCartPlusMember;
3308
3127
  exports.useScriptAutoFreeGift = useScriptAutoFreeGift;
3309
3128
  exports.useSearch = useSearch;
3310
3129
  exports.useSelectedOptions = useSelectedOptions;
3311
- exports.useShippingMethodAvailableCheck = useShippingMethodAvailableCheck;
3312
3130
  exports.useShippingMethods = useShippingMethods;
3313
3131
  exports.useSite = useSite;
3314
3132
  exports.useUpdateCartAttributes = useUpdateCartAttributes;
3315
3133
  exports.useUpdateCartLines = useUpdateCartLines;
3316
3134
  exports.useUpdateLineCodeAmountAttributes = useUpdateLineCodeAmountAttributes;
3317
- exports.useUpdatePlusMemberDeliveryOptions = useUpdatePlusMemberDeliveryOptions;
3318
3135
  exports.useUpdateVariantQuery = useUpdateVariantQuery;
3319
3136
  exports.useVariant = useVariant;
3320
3137
  exports.useVariantMedia = useVariantMedia;