@anker-in/shopify-react 0.1.1-beta.43 → 0.1.1-beta.45

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.
@@ -9,7 +9,7 @@ import * as swr from 'swr';
9
9
  import swr__default, { SWRConfiguration } from 'swr';
10
10
  import * as swr__internal from 'swr/_internal';
11
11
  import * as React$1 from 'react';
12
- import { PropsWithChildren, Dispatch, SetStateAction, RefObject } from 'react';
12
+ import { Dispatch, SetStateAction, PropsWithChildren, RefObject } from 'react';
13
13
  import * as react_jsx_runtime from 'react/jsx-runtime';
14
14
 
15
15
  interface CreateCartInput {
@@ -57,7 +57,10 @@ interface CreateCartInput {
57
57
  * })
58
58
  * ```
59
59
  */
60
- declare function useCreateCart(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'create-cart', CreateCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "create-cart", CreateCartInput>;
60
+ declare function useCreateCart({ updateCookie, options, }: {
61
+ updateCookie?: boolean;
62
+ options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'create-cart', CreateCartInput>;
63
+ }): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "create-cart", CreateCartInput>;
61
64
 
62
65
  interface AddCartLinesInput {
63
66
  /** Cart ID (optional, will create new cart if not provided) */
@@ -585,6 +588,7 @@ interface Campaign {
585
588
  }>;
586
589
  includeTags?: string[];
587
590
  useTotalAmount?: boolean;
591
+ requireLogin?: boolean;
588
592
  }
589
593
  interface UseScriptAutoFreeGiftResult {
590
594
  involvedLines: NormalizedLineItem[];
@@ -595,12 +599,13 @@ interface UseScriptAutoFreeGiftResult {
595
599
  involvedSubTotal: Decimal;
596
600
  giftProductsResult?: NormalizedProduct[];
597
601
  }
598
- declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, }: {
602
+ declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
599
603
  campaign: Campaign | null;
600
604
  _giveaway: string;
601
605
  cart: NormalizedCart | undefined;
602
606
  locale?: string;
603
607
  lines?: AddToCartLineItem[];
608
+ profile?: any;
604
609
  }) => UseScriptAutoFreeGiftResult;
605
610
 
606
611
  interface UseCalcGiftsFromLinesOptions {
@@ -685,910 +690,589 @@ interface OrderDiscountResult {
685
690
  */
686
691
  declare const useCalcOrderDiscount: (cart: any, orderDiscountConfig?: OrderDiscountConfig[], customer?: any) => OrderDiscountResult;
687
692
 
688
- interface ShippingMethodsContext {
689
- freeShippingMethods: PlusMemberShippingMethodConfig[];
690
- paymentShippingMethods: PlusMemberShippingMethodConfig[];
691
- nddOverweight: boolean;
692
- tddOverweight: boolean;
693
- nddCoupon?: string;
694
- tddCoupon?: string;
695
- isLoadingCoupon: boolean;
696
- }
697
- interface PlusMemberContextValue<TProduct = any, TVariant = any, TProfile extends {
698
- isPlus?: boolean;
699
- } = any> {
700
- plusMemberMetafields: PlusMemberSettingsMetafields;
701
- selectedPlusMemberMode: DeliveryPlusType;
702
- setSelectedPlusMemberMode: (value: DeliveryPlusType) => void;
703
- selectedShippingMethod?: PlusMemberShippingMethodConfig;
704
- setSelectedShippingMethod: (value: PlusMemberShippingMethodConfig) => void;
705
- showMoreShippingMethod: boolean;
706
- setShowMoreShippingMethod: (value: boolean) => void;
707
- variant: TVariant;
708
- product: TProduct;
709
- shippingMethodsContext: ShippingMethodsContext;
710
- selectedPlusMemberVariant: SelectedPlusMemberVariant;
711
- showPlusMemberBenefit: boolean;
712
- setShowPlusMemberBenefit: (value: boolean) => void;
713
- profile?: TProfile;
693
+ declare const getReferralAttributes: () => {
694
+ key: string;
695
+ value: any;
696
+ }[];
697
+ /**
698
+ * Get user type based on customer information
699
+ */
700
+ declare const getUserType: (customer?: any) => string;
701
+ interface GetCartAttributesProps {
702
+ profile?: any;
703
+ customer?: any;
704
+ cart?: NormalizedCart;
705
+ memberType?: string;
706
+ currentUrl?: string;
714
707
  }
715
- declare const PlusMemberContext: React$1.Context<PlusMemberContextValue<any, any, any>>;
716
-
717
708
  /**
718
- * Hook to access Plus Member Context
709
+ * Get cart attributes (pure function version)
719
710
  */
720
- declare function usePlusMemberContext<TProfile extends {
721
- isPlus?: boolean;
722
- } = any>(): PlusMemberContextValue<any, any, any>;
723
-
711
+ declare function getCartAttributes({ profile, customer, cart, memberType, currentUrl, }: GetCartAttributesProps): Array<{
712
+ key: string;
713
+ value: any;
714
+ }>;
724
715
  /**
725
- * Hook to get Plus Member Product Variants (Monthly and Annual)
716
+ * Hook to get cart attributes
726
717
  */
718
+ declare const useCartAttributes: ({ profile, customer, cart, memberType, }: {
719
+ profile: any;
720
+ customer: any;
721
+ cart?: NormalizedCart;
722
+ memberType?: string;
723
+ }) => {
724
+ attributes: Array<{
725
+ key: string;
726
+ value: any;
727
+ }>;
728
+ };
727
729
 
728
- interface UsePlusMemberVariantsOptions {
729
- /** Plus member metafields configuration */
730
- memberSetting: PlusMemberSettingsMetafields;
731
- }
732
- interface UsePlusMemberVariantsResult {
733
- monthlyVariant?: NormalizedProductVariant & {
734
- product: NormalizedProduct | undefined;
735
- };
736
- annualVariant?: NormalizedProductVariant & {
737
- product: NormalizedProduct | undefined;
730
+ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
731
+ cart?: NormalizedCart;
732
+ cartItem: NormalizedLineItem;
733
+ config: {
734
+ handle: Record<string, {
735
+ min: number;
736
+ max: number;
737
+ }>;
738
+ sku: Record<string, {
739
+ min: number;
740
+ max: number;
741
+ }>;
738
742
  };
739
- }
743
+ }) => {
744
+ min: number;
745
+ max: number;
746
+ };
747
+
740
748
  /**
741
- * Get Plus Member product variants (monthly and annual)
742
- *
743
- * @param options - Configuration options
744
- * @returns Monthly and annual variants
745
- *
746
- * @example
747
- * ```tsx
748
- * const { monthlyVariant, annualVariant } = usePlusMemberVariants({
749
- * plusMemberMetafields
750
- * })
751
- * ```
749
+ * 更新购物车中各个 item 的折后价相关的属性
752
750
  */
753
- declare function usePlusMemberVariants({ memberSetting, }: UsePlusMemberVariantsOptions): UsePlusMemberVariantsResult;
751
+ declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
752
+ cart?: NormalizedCart;
753
+ mutateCart: (cart: NormalizedCart | undefined) => void;
754
+ isCartLoading: boolean;
755
+ setLoadingState: React.Dispatch<React.SetStateAction<any>>;
756
+ metafieldIdentifiers?: {
757
+ variant: HasMetafieldsIdentifier[];
758
+ product: HasMetafieldsIdentifier[];
759
+ };
760
+ }) => void;
761
+
762
+ declare const currencyCodeMapping: Record<string, string>;
763
+ declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
764
+ throwOnError?: boolean;
765
+ };
766
+ declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
767
+ declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
768
+ declare const CODE_AMOUNT_KEY = "_sku_code_money";
769
+ declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
770
+ declare const MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
771
+ declare const MAIN_PRODUCT_CODE: string[];
754
772
 
755
773
  /**
756
- * Hook to calculate available shipping methods based on product weight and member status
774
+ * Normalize AddToCartLineItem[] to NormalizedLineItem[] format
775
+ * This is used to calculate gifts from lines before they are added to cart
757
776
  */
777
+ declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
778
+ /**
779
+ * Create a mock cart structure from AddToCartLineItem[]
780
+ * This is useful for calculating gifts before actual cart operations
781
+ */
782
+ declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
758
783
 
759
- interface UseShippingMethodsOptions<TVariant = any, TProfile extends {
760
- isPlus?: boolean;
761
- } = any> {
762
- /** Product variant with weight information */
763
- variant: TVariant;
764
- /** Plus member metafields configuration */
765
- plusMemberMetafields: PlusMemberSettingsMetafields;
766
- /** Selected plus member mode */
767
- selectedPlusMemberMode: DeliveryPlusType;
768
- profile?: TProfile;
769
- }
770
- interface UseShippingMethodsResult {
771
- freeShippingMethods: PlusMemberShippingMethodConfig[];
772
- paymentShippingMethods: PlusMemberShippingMethodConfig[];
773
- nddOverweight: boolean;
774
- tddOverweight: boolean;
775
- nddCoupon?: string;
776
- tddCoupon?: string;
777
- isLoadingCoupon: boolean;
784
+ declare const getQuery: () => Record<string, string>;
785
+
786
+ declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
787
+ declare const safeParse: (str: string) => any;
788
+ declare const getDiscountEnvAttributeValue: (attributes?: {
789
+ key: string;
790
+ value: string;
791
+ }[]) => any;
792
+ declare const checkAttributesUpdateNeeded: (oldAttributes: NormalizedAttribute[], newAttributes: NormalizedAttribute[], customAttributesNeedRemove: {
793
+ key: string;
794
+ }[]) => boolean;
795
+ declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
796
+ declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
797
+ scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
798
+ gradient_gifts: any;
799
+ locale: string;
800
+ }) => any[];
801
+ declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
802
+ locale: string;
803
+ qualifyingGift?: FormattedGift | null;
804
+ giftProductsResult?: NormalizedProduct[] | [];
805
+ }) => any[];
806
+
807
+ interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
808
+ handle?: string;
809
+ metafieldIdentifiers?: Array<{
810
+ namespace: string;
811
+ key: string;
812
+ }>;
778
813
  }
779
814
  /**
780
- * Calculate available shipping methods based on product weight, member status, and available coupons
815
+ * Hook to fetch a single product by handle
781
816
  *
782
- * @param options - Configuration options
783
- * @returns Shipping methods categorized by free/payment and overweight status
817
+ * @param options - Hook options including handle and SWR configuration
818
+ * @returns SWR response with product data
784
819
  *
785
820
  * @example
786
- * ```tsx
787
- * const { freeShippingMethods, paymentShippingMethods, nddOverweight, tddOverweight } = useShippingMethods({
788
- * variant,
789
- * plusMemberMetafields,
790
- * selectedPlusMemberMode,
791
- * })
821
+ * ```typescript
822
+ * function ProductPage() {
823
+ * const { data: product, error, isLoading } = useProduct({
824
+ * handle: 'my-product'
825
+ * })
826
+ *
827
+ * if (isLoading) return <div>Loading...</div>
828
+ * if (error) return <div>Error loading product</div>
829
+ * if (!product) return <div>Product not found</div>
830
+ *
831
+ * return (
832
+ * <div>
833
+ * <h1>{product.title}</h1>
834
+ * <p>{product.description}</p>
835
+ * <p>${product.price.amount}</p>
836
+ * </div>
837
+ * )
838
+ * }
792
839
  * ```
793
840
  */
794
- declare function useShippingMethods<TVariant extends {
795
- weight?: number;
796
- } = any>(options: UseShippingMethodsOptions<TVariant>): UseShippingMethodsResult;
841
+ declare function useProduct(options?: UseProductOptions): swr.SWRResponse<NormalizedProduct | undefined, any, SWRConfiguration<NormalizedProduct | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>)> | undefined>;
797
842
 
843
+ interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
844
+ first?: number;
845
+ query?: string;
846
+ sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
847
+ reverse?: boolean;
848
+ metafieldIdentifiers?: Array<{
849
+ namespace: string;
850
+ key: string;
851
+ }>;
852
+ }
798
853
  /**
799
- * Hook to replace cart plus member product
854
+ * Hook to fetch all products
800
855
  *
801
- * When adding a monthly membership while an annual membership exists in cart,
802
- * the annual membership will be replaced and vice versa.
856
+ * This hook automatically handles pagination and fetches all products.
857
+ * Use with caution on stores with many products.
803
858
  *
804
- * @returns Handler function to replace conflicting membership products
859
+ * @param options - Hook options including query parameters and SWR configuration
860
+ * @returns SWR response with products array
805
861
  *
806
862
  * @example
807
- * ```tsx
808
- * const replaceCartPlusMember = useReplaceCartPlusMember()
863
+ * ```typescript
864
+ * function ProductList() {
865
+ * const { data: products, error, isLoading } = useAllProducts({
866
+ * sortKey: 'TITLE',
867
+ * reverse: false
868
+ * })
809
869
  *
810
- * // Call before adding new membership product
811
- * await replaceCartPlusMember()
870
+ * if (isLoading) return <div>Loading...</div>
871
+ * if (error) return <div>Error loading products</div>
872
+ *
873
+ * return (
874
+ * <div>
875
+ * {products?.map(product => (
876
+ * <div key={product.id}>
877
+ * <h2>{product.title}</h2>
878
+ * <p>${product.price.amount}</p>
879
+ * </div>
880
+ * ))}
881
+ * </div>
882
+ * )
883
+ * }
812
884
  * ```
813
885
  */
814
- declare const useReplaceCartPlusMember: () => () => Promise<void>;
886
+ declare function useAllProducts(options?: UseAllProductsOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
815
887
 
816
- /**
817
- * Hook to get delivery discount codes from delivery data
818
- *
819
- * Extracts and returns the discount codes from the delivery custom data.
820
- *
821
- * @returns Array of discount codes or undefined
888
+ interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
889
+ handles?: string[];
890
+ metafieldIdentifiers?: {
891
+ product: HasMetafieldsIdentifier[];
892
+ variant: HasMetafieldsIdentifier[];
893
+ };
894
+ }
895
+ /**
896
+ * Hook to fetch multiple products by their handles
897
+ *
898
+ * @param options - Hook options including handles array and SWR configuration
899
+ * @returns SWR response with products array
822
900
  *
823
901
  * @example
824
- * ```tsx
825
- * const deliveryCodes = usePlusMemberDeliveryCodes()
902
+ * ```typescript
903
+ * function FeaturedProducts() {
904
+ * const { data: products, error, isLoading } = useProductsByHandles({
905
+ * handles: ['product-1', 'product-2', 'product-3']
906
+ * })
907
+ *
908
+ * if (isLoading) return <div>Loading...</div>
909
+ * if (error) return <div>Error loading products</div>
910
+ *
911
+ * return (
912
+ * <div>
913
+ * {products?.map(product => (
914
+ * <div key={product.id}>
915
+ * <h2>{product.title}</h2>
916
+ * <p>${product.price.amount}</p>
917
+ * </div>
918
+ * ))}
919
+ * </div>
920
+ * )
921
+ * }
826
922
  * ```
827
923
  */
828
- declare const usePlusMemberDeliveryCodes: () => (string | undefined)[];
829
-
830
- declare const usePlusMemberCheckoutCustomAttributes: ({ disableShipping, isPresaleContains, }: {
831
- disableShipping?: boolean;
832
- isPresaleContains?: boolean;
833
- }) => NormalizedAttribute[];
924
+ declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
834
925
 
835
926
  /**
836
- * useAutoRemovePlusMemberInCart Hook
837
- * 付费会员身份自动移除购物车中的会员产品
838
- * 年费会员删除月费会员产品,月费会员删除年费会员产品
927
+ * useVariant Hook
928
+ *
929
+ * Client-side hook to get the selected variant based on selected options
839
930
  */
840
931
 
841
- interface UseAutoRemovePlusMemberInCartProps {
842
- profile: any;
843
- cart?: NormalizedCart;
844
- memberSetting: PlusMemberSettingsMetafields;
845
- }
932
+ type Options = Record<string, string>;
846
933
  /**
847
- * 自动移除购物车中的会员产品
934
+ * Hook to manage variant selection based on selected options
848
935
  *
849
- * @param props - Hook 参数
850
- * @param props.memberSetting - Plus Member 配置
851
- * @param props.isMonthlyPlus - 用户是否是月费会员
852
- * @param props.isAnnualPlus - 用户是否是年费会员
936
+ * @param product - The product object
937
+ * @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
938
+ * @returns The matching variant
853
939
  *
854
940
  * @example
855
- * ```tsx
856
- * const { profile } = useProfile()
941
+ * ```typescript
942
+ * function ProductDetail() {
943
+ * const { data: product } = useProduct({ handle: 'my-product' })
944
+ * const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
945
+ * const variant = useVariant({ product, selectedOptions })
857
946
  *
858
- * useAutoRemovePlusMemberInCart({
859
- * cart,
860
- * profile,
861
- * })
947
+ * return (
948
+ * <div>
949
+ * <h1>{product.title}</h1>
950
+ * <p>Selected: {variant.title}</p>
951
+ * <p>Price: ${variant.price.amount}</p>
952
+ * <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
953
+ * </div>
954
+ * )
955
+ * }
862
956
  * ```
863
957
  */
864
- declare function useAutoRemovePlusMemberInCart({ cart, profile, memberSetting, }: UseAutoRemovePlusMemberInCartProps): void;
958
+ declare function useVariant({ product, selectedOptions, }: {
959
+ product?: NormalizedProduct;
960
+ selectedOptions: Options;
961
+ }): NormalizedProductVariant | undefined;
865
962
 
866
963
  /**
867
- * Has Plus Member In Cart
868
- * 判断购物车中是否包含年费会员或月费会员产品
964
+ * usePrice Hook
965
+ *
966
+ * Client-side hook to format price for display
869
967
  */
870
-
871
- interface HasPlusMemberInCartProps {
872
- /** Plus Member 配置 */
873
- memberSetting?: PlusMemberSettingsMetafields;
874
- /** 购物车数据 */
875
- cart?: NormalizedCart;
968
+ interface UsePriceOptions {
969
+ amount: number;
970
+ baseAmount?: number;
971
+ currencyCode: string;
972
+ soldOutDescription?: string;
973
+ maximumFractionDigits?: number;
974
+ minimumFractionDigits?: number;
975
+ removeTrailingZeros?: boolean;
876
976
  }
877
- interface HasPlusMemberInCartResult {
878
- /** 购物车中是否有任何会员产品 */
879
- hasPlusMember: boolean;
880
- /** 购物车中是否有月费会员产品 */
881
- hasMonthlyPlus: boolean;
882
- /** 购物车中是否有年费会员产品 */
883
- hasAnnualPlus: boolean;
884
- /** 月费会员产品的 line item */
885
- monthlyPlusItem?: {
886
- id: string;
887
- quantity: number;
888
- handle?: string;
889
- sku?: string;
890
- };
891
- /** 年费会员产品的 line item */
892
- annualPlusItem?: {
893
- id: string;
894
- quantity: number;
895
- handle?: string;
896
- sku?: string;
897
- };
977
+ interface UsePriceResult {
978
+ price: string;
979
+ basePrice?: string;
980
+ free: boolean;
898
981
  }
899
982
  /**
900
- * 判断购物车中是否包含年费会员或月费会员产品(纯函数版本)
983
+ * Hook to format price for display
901
984
  *
902
- * @param props - 函数参数
903
- * @param props.memberSetting - Plus Member 配置
904
- * @param props.cart - 购物车数据
905
- * @returns 会员产品信息
985
+ * @param options - Price formatting options
986
+ * @returns Formatted price object
906
987
  *
907
988
  * @example
908
- * ```tsx
909
- * const {
910
- * hasPlusMember,
911
- * hasMonthlyPlus,
912
- * hasAnnualPlus,
913
- * monthlyPlusItem,
914
- * annualPlusItem,
915
- * } = hasPlusMemberInCart({
916
- * memberSetting: plusMemberSettings,
917
- * cart: currentCart,
918
- * })
989
+ * ```typescript
990
+ * function ProductPrice({ variant }) {
991
+ * const { price, basePrice, free } = usePrice({
992
+ * amount: variant.price.amount,
993
+ * baseAmount: variant.compareAtPrice?.amount,
994
+ * currencyCode: variant.price.currencyCode
995
+ * })
919
996
  *
920
- * if (hasPlusMember) {
921
- * console.log('购物车中有会员产品')
997
+ * return (
998
+ * <div>
999
+ * {free ? (
1000
+ * <span>Free</span>
1001
+ * ) : (
1002
+ * <>
1003
+ * <span className="price">{price}</span>
1004
+ * {basePrice && <span className="original">{basePrice}</span>}
1005
+ * </>
1006
+ * )}
1007
+ * </div>
1008
+ * )
922
1009
  * }
923
1010
  * ```
924
1011
  */
925
- declare function hasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1012
+ declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
1013
+
926
1014
  /**
927
- * 判断购物车中是否包含年费会员或月费会员产品(Hook 版本)
1015
+ * useSelectedOptions Hook
928
1016
  *
929
- * 内部使用 hasPlusMemberInCart 纯函数,并通过 useMemo 优化性能
1017
+ * Client-side hook to manage selected product options
1018
+ */
1019
+
1020
+ type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
1021
+ /**
1022
+ * Hook to manage selected product options based on URL query or SKU
930
1023
  *
931
- * @param props - Hook 参数
932
- * @param props.memberSetting - Plus Member 配置
933
- * @param props.cart - 购物车数据
934
- * @returns 会员产品信息
1024
+ * @param product - The product object
1025
+ * @param sku - Optional SKU to match variant
1026
+ * @returns Tuple of [options, setOptions]
935
1027
  *
936
1028
  * @example
937
- * ```tsx
938
- * const {
939
- * hasPlusMember,
940
- * hasMonthlyPlus,
941
- * hasAnnualPlus,
942
- * monthlyPlusItem,
943
- * annualPlusItem,
944
- * } = useHasPlusMemberInCart({
945
- * memberSetting: plusMemberSettings,
946
- * cart: currentCart,
947
- * })
1029
+ * ```typescript
1030
+ * function ProductDetail() {
1031
+ * const { data: product } = useProduct({ handle: 'my-product' })
1032
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1033
+ * const variant = useVariant({ product, selectedOptions })
948
1034
  *
949
- * if (hasPlusMember) {
950
- * console.log('购物车中有会员产品')
1035
+ * const handleOptionChange = (name: string, value: string) => {
1036
+ * setSelectedOptions(prev => ({ ...prev, [name]: value }))
1037
+ * }
1038
+ *
1039
+ * return (
1040
+ * <div>
1041
+ * {product?.options.map(option => (
1042
+ * <select
1043
+ * key={option.id}
1044
+ * value={selectedOptions[option.name] || ''}
1045
+ * onChange={(e) => handleOptionChange(option.name, e.target.value)}
1046
+ * >
1047
+ * {option.values.map(value => (
1048
+ * <option key={value.label} value={value.label}>
1049
+ * {value.label}
1050
+ * </option>
1051
+ * ))}
1052
+ * </select>
1053
+ * ))}
1054
+ * <p>Selected: {variant?.title}</p>
1055
+ * </div>
1056
+ * )
951
1057
  * }
952
1058
  * ```
953
1059
  */
954
- declare function useHasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1060
+ declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
955
1061
 
956
1062
  /**
957
- * 返回需要添加到购物车的 Plus Member 产品
1063
+ * useProductUrl Hook
958
1064
  *
959
- * hook 会根据用户选择的会员模式和购物车现有状态,
960
- * 返回需要添加的会员产品。如果不需要添加会员产品,则返回 undefined。
1065
+ * Hook to generate product URLs with variant query params
1066
+ * Requires routerAdapter to be configured in ShopifyProvider
1067
+ */
1068
+
1069
+ /**
1070
+ * Hook to generate product URLs
961
1071
  *
962
- * @param props - Hook 参数
963
- * @param props.cart - 购物车数据
964
- * @returns Plus Member 产品对象或 undefined
1072
+ * @param otherQuery - Additional query parameters to include
1073
+ * @returns Function to generate product URL
965
1074
  *
966
1075
  * @example
967
- * ```tsx
968
- * const plusMemberVariant = usePlusMemberNeedAddToCart({
969
- * cart,
970
- * })
1076
+ * ```typescript
1077
+ * function ProductCard({ product, variant }) {
1078
+ * const getProductUrl = useProductUrl()
971
1079
  *
972
- * ```
973
- */
974
- declare function usePlusMemberNeedAddToCart({ cart, profile, }: {
975
- cart: NormalizedCart;
976
- profile?: any;
977
- }): (_anker_in_shopify_sdk.NormalizedProductVariant & {
978
- product: _anker_in_shopify_sdk.NormalizedProduct | undefined;
979
- }) | undefined;
980
-
981
- interface UseAvailableDeliveryCouponResult {
982
- nddCoupon?: string;
983
- tddCoupon?: string;
984
- isLoading: boolean;
985
- }
986
- declare const useAvailableDeliveryCoupon: ({ profile, }: {
987
- profile?: any;
988
- }) => UseAvailableDeliveryCouponResult;
989
-
990
- interface PlusMemberProviderProps<TProduct = any, TVariant = any, TProfile extends {
991
- isPlus?: boolean;
992
- } = any> {
993
- variant: TVariant;
994
- product: TProduct;
995
- memberSetting: PlusMemberSettingsMetafields;
996
- initialSelectedPlusMemberMode?: DeliveryPlusType;
997
- profile?: TProfile;
998
- }
999
- /**
1000
- * Plus Member Provider Component
1080
+ * const url = getProductUrl({ product, variant })
1001
1081
  *
1002
- * Provides Plus Member context and state management to child components.
1082
+ * return (
1083
+ * <a href={url}>
1084
+ * <h2>{product.title}</h2>
1085
+ * <p>{variant.title}</p>
1086
+ * </a>
1087
+ * )
1088
+ * }
1089
+ * ```
1003
1090
  *
1004
- * @param variant - Product variant
1005
- * @param product - Product
1006
- * @param metafields - Plus member settings from metafields
1007
- * @param initialSelectedPlusMemberMode - Initial selected mode (default: 'free')
1008
- * @param profile - User profile
1009
- * @param locale - Locale code
1010
- * @param children - Child components
1091
+ * @example With additional query params
1092
+ * ```typescript
1093
+ * function ProductCard({ product, variant }) {
1094
+ * const getProductUrl = useProductUrl({ utm_source: 'email' })
1011
1095
  *
1012
- * @example
1013
- * ```tsx
1014
- * <PlusMemberProvider
1015
- * variant={variant}
1016
- * product={product}
1017
- * memberSetting={memberSetting}
1018
- * profile={profile}
1019
- * >
1020
- * <YourComponent />
1021
- * </PlusMemberProvider>
1096
+ * const url = getProductUrl({ product, variant })
1097
+ * // URL will include: ?variant=123&utm_source=email
1098
+ *
1099
+ * return <a href={url}>{product.title}</a>
1100
+ * }
1022
1101
  * ```
1023
1102
  */
1024
- declare const PlusMemberProvider: <TProduct = any, TVariant extends {
1025
- weight?: number;
1026
- } = any, TProfile extends {
1027
- isPlus?: boolean;
1028
- } = any>({ variant, product, memberSetting, initialSelectedPlusMemberMode, profile, children, }: PropsWithChildren<PlusMemberProviderProps<TProduct, TVariant, TProfile>>) => react_jsx_runtime.JSX.Element;
1029
-
1030
- declare const getReferralAttributes: () => {
1031
- key: string;
1032
- value: any;
1033
- }[];
1034
- declare const useCartAttributes: ({ profile, customer, cart, memberSetting, }: {
1035
- profile: any;
1036
- customer: any;
1037
- cart?: NormalizedCart;
1038
- memberSetting?: PlusMemberSettingsMetafields;
1039
- }) => {
1040
- attributes: Array<{
1041
- key: string;
1042
- value: any;
1043
- }>;
1044
- };
1045
-
1046
- declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
1047
- cart?: NormalizedCart;
1048
- cartItem: NormalizedLineItem;
1049
- config: {
1050
- handle: Record<string, {
1051
- min: number;
1052
- max: number;
1053
- }>;
1054
- sku: Record<string, {
1055
- min: number;
1056
- max: number;
1057
- }>;
1058
- };
1059
- }) => {
1060
- min: number;
1061
- max: number;
1062
- };
1063
-
1064
- /**
1065
- * 更新购物车中各个 item 的折后价相关的属性
1066
- */
1067
- declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
1068
- cart?: NormalizedCart;
1069
- mutateCart: (cart: NormalizedCart | undefined) => void;
1070
- isCartLoading: boolean;
1071
- setLoadingState: React.Dispatch<React.SetStateAction<any>>;
1072
- metafieldIdentifiers?: {
1073
- variant: HasMetafieldsIdentifier[];
1074
- product: HasMetafieldsIdentifier[];
1075
- };
1076
- }) => void;
1077
-
1078
- declare const currencyCodeMapping: Record<string, string>;
1079
- declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
1080
- throwOnError?: boolean;
1081
- };
1082
- declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
1083
- declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
1084
- declare const CODE_AMOUNT_KEY = "_sku_code_money";
1085
- declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
1086
- declare const MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
1087
- declare const MAIN_PRODUCT_CODE: string[];
1103
+ declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
1104
+ product?: NormalizedProduct;
1105
+ variant?: NormalizedProductVariant;
1106
+ }) => string;
1088
1107
 
1089
1108
  /**
1090
- * Normalize AddToCartLineItem[] to NormalizedLineItem[] format
1091
- * This is used to calculate gifts from lines before they are added to cart
1092
- */
1093
- declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
1094
- /**
1095
- * Create a mock cart structure from AddToCartLineItem[]
1096
- * This is useful for calculating gifts before actual cart operations
1109
+ * useUpdateVariantQuery Hook
1110
+ *
1111
+ * Hook to automatically update URL query string when variant changes
1097
1112
  */
1098
- declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
1099
-
1100
- declare const getQuery: () => Record<string, string>;
1101
-
1102
- declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
1103
- declare const safeParse: (str: string) => any;
1104
- declare const getDiscountEnvAttributeValue: (attributes?: {
1105
- key: string;
1106
- value: string;
1107
- }[]) => any;
1108
- declare const checkAttributesUpdateNeeded: (oldAttributes: NormalizedAttribute[], newAttributes: NormalizedAttribute[], customAttributesNeedRemove: {
1109
- key: string;
1110
- }[]) => boolean;
1111
- declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
1112
- declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
1113
- scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
1114
- gradient_gifts: any;
1115
- locale: string;
1116
- }) => any[];
1117
- declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
1118
- locale: string;
1119
- qualifyingGift?: FormattedGift | null;
1120
- giftProductsResult?: NormalizedProduct[] | [];
1121
- }) => any[];
1122
1113
 
1123
- interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
1124
- handle?: string;
1125
- metafieldIdentifiers?: Array<{
1126
- namespace: string;
1127
- key: string;
1128
- }>;
1129
- }
1130
1114
  /**
1131
- * Hook to fetch a single product by handle
1115
+ * Hook to update URL query string when variant changes
1132
1116
  *
1133
- * @param options - Hook options including handle and SWR configuration
1134
- * @returns SWR response with product data
1117
+ * This hook automatically updates the browser URL with the selected variant ID
1118
+ * without causing a page reload. Useful for shareable URLs and browser history.
1119
+ *
1120
+ * @param variant - The selected variant
1135
1121
  *
1136
1122
  * @example
1137
1123
  * ```typescript
1138
- * function ProductPage() {
1139
- * const { data: product, error, isLoading } = useProduct({
1140
- * handle: 'my-product'
1141
- * })
1124
+ * function ProductDetail() {
1125
+ * const { data: product } = useProduct({ handle: 'my-product' })
1126
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1127
+ * const variant = useVariant({ product, selectedOptions })
1142
1128
  *
1143
- * if (isLoading) return <div>Loading...</div>
1144
- * if (error) return <div>Error loading product</div>
1145
- * if (!product) return <div>Product not found</div>
1129
+ * // Automatically updates URL when variant changes
1130
+ * useUpdateVariantQuery(variant)
1146
1131
  *
1147
1132
  * return (
1148
1133
  * <div>
1149
- * <h1>{product.title}</h1>
1150
- * <p>{product.description}</p>
1151
- * <p>${product.price.amount}</p>
1134
+ * <h1>{product?.title}</h1>
1135
+ * <p>Current variant: {variant?.title}</p>
1136
+ * {/* URL will be: /products/my-product?variant=123456 *\/}
1152
1137
  * </div>
1153
1138
  * )
1154
1139
  * }
1155
1140
  * ```
1156
1141
  */
1157
- declare function useProduct(options?: UseProductOptions): swr.SWRResponse<NormalizedProduct | undefined, any, SWRConfiguration<NormalizedProduct | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>)> | undefined>;
1142
+ declare function useUpdateVariantQuery(variant?: NormalizedProductVariant): void;
1158
1143
 
1159
- interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
1160
- first?: number;
1161
- query?: string;
1162
- sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
1163
- reverse?: boolean;
1164
- metafieldIdentifiers?: Array<{
1165
- namespace: string;
1166
- key: string;
1167
- }>;
1168
- }
1169
1144
  /**
1170
- * Hook to fetch all products
1145
+ * useVariantMedia Hook
1171
1146
  *
1172
- * This hook automatically handles pagination and fetches all products.
1173
- * Use with caution on stores with many products.
1147
+ * Hook to get media (images and videos) for the selected variant
1148
+ */
1149
+
1150
+ type ImageMedia = Media & {
1151
+ mediaContentType: 'IMAGE';
1152
+ };
1153
+ type VideoMedia = Media & {
1154
+ mediaContentType: 'VIDEO' | 'EXTERNAL_VIDEO';
1155
+ };
1156
+ interface VariantMedia {
1157
+ productList: ImageMedia[];
1158
+ sceneList: ImageMedia[];
1159
+ videoList: VideoMedia[];
1160
+ }
1161
+ /**
1162
+ * Hook to get media for the selected variant
1174
1163
  *
1175
- * @param options - Hook options including query parameters and SWR configuration
1176
- * @returns SWR response with products array
1164
+ * @param product - The product object
1165
+ * @param variant - The selected variant
1166
+ * @returns Object with productList (first image), sceneList (other images), videoList
1177
1167
  *
1178
1168
  * @example
1179
1169
  * ```typescript
1180
- * function ProductList() {
1181
- * const { data: products, error, isLoading } = useAllProducts({
1182
- * sortKey: 'TITLE',
1183
- * reverse: false
1184
- * })
1185
- *
1186
- * if (isLoading) return <div>Loading...</div>
1187
- * if (error) return <div>Error loading products</div>
1170
+ * function ProductGallery() {
1171
+ * const { data: product } = useProduct({ handle: 'my-product' })
1172
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1173
+ * const variant = useVariant({ product, selectedOptions })
1174
+ * const { productList, sceneList, videoList } = useVariantMedia({ product, variant })
1188
1175
  *
1189
1176
  * return (
1190
1177
  * <div>
1191
- * {products?.map(product => (
1192
- * <div key={product.id}>
1193
- * <h2>{product.title}</h2>
1194
- * <p>${product.price.amount}</p>
1195
- * </div>
1178
+ * {/* Main product image *\/}
1179
+ * {productList.map(media => (
1180
+ * <img key={media.id} src={media.image?.url} alt={media.alt} />
1196
1181
  * ))}
1197
- * </div>
1198
- * )
1199
- * }
1200
- * ```
1201
- */
1202
- declare function useAllProducts(options?: UseAllProductsOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
1203
-
1204
- interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
1205
- handles?: string[];
1206
- metafieldIdentifiers?: {
1207
- product: HasMetafieldsIdentifier[];
1208
- variant: HasMetafieldsIdentifier[];
1209
- };
1210
- }
1211
- /**
1212
- * Hook to fetch multiple products by their handles
1213
- *
1214
- * @param options - Hook options including handles array and SWR configuration
1215
- * @returns SWR response with products array
1216
- *
1217
- * @example
1218
- * ```typescript
1219
- * function FeaturedProducts() {
1220
- * const { data: products, error, isLoading } = useProductsByHandles({
1221
- * handles: ['product-1', 'product-2', 'product-3']
1222
- * })
1223
1182
  *
1224
- * if (isLoading) return <div>Loading...</div>
1225
- * if (error) return <div>Error loading products</div>
1183
+ * {/* Scene/detail images *\/}
1184
+ * {sceneList.map(media => (
1185
+ * <img key={media.id} src={media.image?.url} alt={media.alt} />
1186
+ * ))}
1226
1187
  *
1227
- * return (
1228
- * <div>
1229
- * {products?.map(product => (
1230
- * <div key={product.id}>
1231
- * <h2>{product.title}</h2>
1232
- * <p>${product.price.amount}</p>
1233
- * </div>
1188
+ * {/* Videos *\/}
1189
+ * {videoList.map(media => (
1190
+ * <video key={media.id} src={media.sources?.[0]?.url} controls />
1234
1191
  * ))}
1235
1192
  * </div>
1236
1193
  * )
1237
1194
  * }
1238
1195
  * ```
1239
1196
  */
1240
- declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
1197
+ declare function useVariantMedia({ product, variant, }: {
1198
+ product?: NormalizedProduct;
1199
+ variant?: NormalizedProductVariant;
1200
+ }): VariantMedia;
1241
1201
 
1242
- /**
1243
- * useVariant Hook
1244
- *
1245
- * Client-side hook to get the selected variant based on selected options
1246
- */
1202
+ interface UseCollectionOptions extends SWRConfiguration<NormalizedCollection | undefined> {
1203
+ handle?: string;
1204
+ metafieldIdentifiers?: Array<{
1205
+ namespace: string;
1206
+ key: string;
1207
+ }>;
1208
+ }
1209
+ declare function useCollection(options?: UseCollectionOptions): swr.SWRResponse<NormalizedCollection | undefined, any, SWRConfiguration<NormalizedCollection | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>)> | undefined>;
1247
1210
 
1248
- type Options = Record<string, string>;
1249
- /**
1250
- * Hook to manage variant selection based on selected options
1251
- *
1252
- * @param product - The product object
1253
- * @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
1254
- * @returns The matching variant
1255
- *
1256
- * @example
1257
- * ```typescript
1258
- * function ProductDetail() {
1259
- * const { data: product } = useProduct({ handle: 'my-product' })
1260
- * const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
1261
- * const variant = useVariant({ product, selectedOptions })
1262
- *
1263
- * return (
1264
- * <div>
1265
- * <h1>{product.title}</h1>
1266
- * <p>Selected: {variant.title}</p>
1267
- * <p>Price: ${variant.price.amount}</p>
1268
- * <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
1269
- * </div>
1270
- * )
1271
- * }
1272
- * ```
1273
- */
1274
- declare function useVariant({ product, selectedOptions, }: {
1275
- product?: NormalizedProduct;
1276
- selectedOptions: Options;
1277
- }): NormalizedProductVariant | undefined;
1211
+ interface UseAllCollectionsOptions extends SWRConfiguration<NormalizedCollection[]> {
1212
+ first?: number;
1213
+ query?: string;
1214
+ sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1215
+ reverse?: boolean;
1216
+ metafieldIdentifiers?: Array<{
1217
+ namespace: string;
1218
+ key: string;
1219
+ }>;
1220
+ }
1221
+ declare function useAllCollections(options?: UseAllCollectionsOptions): swr.SWRResponse<NormalizedCollection[], any, SWRConfiguration<NormalizedCollection[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>)> | undefined>;
1278
1222
 
1279
- /**
1280
- * usePrice Hook
1281
- *
1282
- * Client-side hook to format price for display
1283
- */
1284
- interface UsePriceOptions {
1285
- amount: number;
1286
- baseAmount?: number;
1287
- currencyCode: string;
1288
- soldOutDescription?: string;
1289
- maximumFractionDigits?: number;
1290
- minimumFractionDigits?: number;
1291
- removeTrailingZeros?: boolean;
1223
+ interface UseCollectionsOptions extends SWRConfiguration<CollectionsConnection> {
1224
+ first?: number;
1225
+ after?: string;
1226
+ query?: string;
1227
+ sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1228
+ reverse?: boolean;
1229
+ metafieldIdentifiers?: Array<{
1230
+ namespace: string;
1231
+ key: string;
1232
+ }>;
1292
1233
  }
1293
- interface UsePriceResult {
1294
- price: string;
1295
- basePrice?: string;
1296
- free: boolean;
1234
+ declare function useCollections(options?: UseCollectionsOptions): swr.SWRResponse<CollectionsConnection, any, SWRConfiguration<CollectionsConnection, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>)> | undefined>;
1235
+
1236
+ interface UseBlogOptions extends SWRConfiguration<NormalizedBlog | undefined> {
1237
+ handle?: string;
1238
+ metafieldIdentifiers?: Array<{
1239
+ namespace: string;
1240
+ key: string;
1241
+ }>;
1297
1242
  }
1298
- /**
1299
- * Hook to format price for display
1300
- *
1301
- * @param options - Price formatting options
1302
- * @returns Formatted price object
1303
- *
1304
- * @example
1305
- * ```typescript
1306
- * function ProductPrice({ variant }) {
1307
- * const { price, basePrice, free } = usePrice({
1308
- * amount: variant.price.amount,
1309
- * baseAmount: variant.compareAtPrice?.amount,
1310
- * currencyCode: variant.price.currencyCode
1311
- * })
1312
- *
1313
- * return (
1314
- * <div>
1315
- * {free ? (
1316
- * <span>Free</span>
1317
- * ) : (
1318
- * <>
1319
- * <span className="price">{price}</span>
1320
- * {basePrice && <span className="original">{basePrice}</span>}
1321
- * </>
1322
- * )}
1323
- * </div>
1324
- * )
1325
- * }
1326
- * ```
1327
- */
1328
- declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
1243
+ declare function useBlog(options?: UseBlogOptions): swr.SWRResponse<NormalizedBlog | undefined, any, SWRConfiguration<NormalizedBlog | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>)> | undefined>;
1329
1244
 
1330
- /**
1331
- * useSelectedOptions Hook
1332
- *
1333
- * Client-side hook to manage selected product options
1334
- */
1245
+ interface UseAllBlogsOptions extends SWRConfiguration<NormalizedBlog[]> {
1246
+ first?: number;
1247
+ query?: string;
1248
+ metafieldIdentifiers?: Array<{
1249
+ namespace: string;
1250
+ key: string;
1251
+ }>;
1252
+ }
1253
+ declare function useAllBlogs(options?: UseAllBlogsOptions): swr.SWRResponse<NormalizedBlog[], any, SWRConfiguration<NormalizedBlog[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>)> | undefined>;
1335
1254
 
1336
- type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
1337
- /**
1338
- * Hook to manage selected product options based on URL query or SKU
1339
- *
1340
- * @param product - The product object
1341
- * @param sku - Optional SKU to match variant
1342
- * @returns Tuple of [options, setOptions]
1343
- *
1344
- * @example
1345
- * ```typescript
1346
- * function ProductDetail() {
1347
- * const { data: product } = useProduct({ handle: 'my-product' })
1348
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1349
- * const variant = useVariant({ product, selectedOptions })
1350
- *
1351
- * const handleOptionChange = (name: string, value: string) => {
1352
- * setSelectedOptions(prev => ({ ...prev, [name]: value }))
1353
- * }
1354
- *
1355
- * return (
1356
- * <div>
1357
- * {product?.options.map(option => (
1358
- * <select
1359
- * key={option.id}
1360
- * value={selectedOptions[option.name] || ''}
1361
- * onChange={(e) => handleOptionChange(option.name, e.target.value)}
1362
- * >
1363
- * {option.values.map(value => (
1364
- * <option key={value.label} value={value.label}>
1365
- * {value.label}
1366
- * </option>
1367
- * ))}
1368
- * </select>
1369
- * ))}
1370
- * <p>Selected: {variant?.title}</p>
1371
- * </div>
1372
- * )
1373
- * }
1374
- * ```
1375
- */
1376
- declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
1255
+ interface UseArticleOptions extends SWRConfiguration<NormalizedArticle | undefined> {
1256
+ blogHandle?: string;
1257
+ articleHandle?: string;
1258
+ metafieldIdentifiers?: Array<{
1259
+ namespace: string;
1260
+ key: string;
1261
+ }>;
1262
+ }
1263
+ declare function useArticle(options?: UseArticleOptions): swr.SWRResponse<NormalizedArticle | undefined, any, SWRConfiguration<NormalizedArticle | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>)> | undefined>;
1377
1264
 
1378
- /**
1379
- * useProductUrl Hook
1380
- *
1381
- * Hook to generate product URLs with variant query params
1382
- * Requires routerAdapter to be configured in ShopifyProvider
1383
- */
1384
-
1385
- /**
1386
- * Hook to generate product URLs
1387
- *
1388
- * @param otherQuery - Additional query parameters to include
1389
- * @returns Function to generate product URL
1390
- *
1391
- * @example
1392
- * ```typescript
1393
- * function ProductCard({ product, variant }) {
1394
- * const getProductUrl = useProductUrl()
1395
- *
1396
- * const url = getProductUrl({ product, variant })
1397
- *
1398
- * return (
1399
- * <a href={url}>
1400
- * <h2>{product.title}</h2>
1401
- * <p>{variant.title}</p>
1402
- * </a>
1403
- * )
1404
- * }
1405
- * ```
1406
- *
1407
- * @example With additional query params
1408
- * ```typescript
1409
- * function ProductCard({ product, variant }) {
1410
- * const getProductUrl = useProductUrl({ utm_source: 'email' })
1411
- *
1412
- * const url = getProductUrl({ product, variant })
1413
- * // URL will include: ?variant=123&utm_source=email
1414
- *
1415
- * return <a href={url}>{product.title}</a>
1416
- * }
1417
- * ```
1418
- */
1419
- declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
1420
- product?: NormalizedProduct;
1421
- variant?: NormalizedProductVariant;
1422
- }) => string;
1423
-
1424
- /**
1425
- * useUpdateVariantQuery Hook
1426
- *
1427
- * Hook to automatically update URL query string when variant changes
1428
- */
1429
-
1430
- /**
1431
- * Hook to update URL query string when variant changes
1432
- *
1433
- * This hook automatically updates the browser URL with the selected variant ID
1434
- * without causing a page reload. Useful for shareable URLs and browser history.
1435
- *
1436
- * @param variant - The selected variant
1437
- *
1438
- * @example
1439
- * ```typescript
1440
- * function ProductDetail() {
1441
- * const { data: product } = useProduct({ handle: 'my-product' })
1442
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1443
- * const variant = useVariant({ product, selectedOptions })
1444
- *
1445
- * // Automatically updates URL when variant changes
1446
- * useUpdateVariantQuery(variant)
1447
- *
1448
- * return (
1449
- * <div>
1450
- * <h1>{product?.title}</h1>
1451
- * <p>Current variant: {variant?.title}</p>
1452
- * {/* URL will be: /products/my-product?variant=123456 *\/}
1453
- * </div>
1454
- * )
1455
- * }
1456
- * ```
1457
- */
1458
- declare function useUpdateVariantQuery(variant?: NormalizedProductVariant): void;
1459
-
1460
- /**
1461
- * useVariantMedia Hook
1462
- *
1463
- * Hook to get media (images and videos) for the selected variant
1464
- */
1465
-
1466
- type ImageMedia = Media & {
1467
- mediaContentType: 'IMAGE';
1468
- };
1469
- type VideoMedia = Media & {
1470
- mediaContentType: 'VIDEO' | 'EXTERNAL_VIDEO';
1471
- };
1472
- interface VariantMedia {
1473
- productList: ImageMedia[];
1474
- sceneList: ImageMedia[];
1475
- videoList: VideoMedia[];
1476
- }
1477
- /**
1478
- * Hook to get media for the selected variant
1479
- *
1480
- * @param product - The product object
1481
- * @param variant - The selected variant
1482
- * @returns Object with productList (first image), sceneList (other images), videoList
1483
- *
1484
- * @example
1485
- * ```typescript
1486
- * function ProductGallery() {
1487
- * const { data: product } = useProduct({ handle: 'my-product' })
1488
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1489
- * const variant = useVariant({ product, selectedOptions })
1490
- * const { productList, sceneList, videoList } = useVariantMedia({ product, variant })
1491
- *
1492
- * return (
1493
- * <div>
1494
- * {/* Main product image *\/}
1495
- * {productList.map(media => (
1496
- * <img key={media.id} src={media.image?.url} alt={media.alt} />
1497
- * ))}
1498
- *
1499
- * {/* Scene/detail images *\/}
1500
- * {sceneList.map(media => (
1501
- * <img key={media.id} src={media.image?.url} alt={media.alt} />
1502
- * ))}
1503
- *
1504
- * {/* Videos *\/}
1505
- * {videoList.map(media => (
1506
- * <video key={media.id} src={media.sources?.[0]?.url} controls />
1507
- * ))}
1508
- * </div>
1509
- * )
1510
- * }
1511
- * ```
1512
- */
1513
- declare function useVariantMedia({ product, variant, }: {
1514
- product?: NormalizedProduct;
1515
- variant?: NormalizedProductVariant;
1516
- }): VariantMedia;
1517
-
1518
- interface UseCollectionOptions extends SWRConfiguration<NormalizedCollection | undefined> {
1519
- handle?: string;
1520
- metafieldIdentifiers?: Array<{
1521
- namespace: string;
1522
- key: string;
1523
- }>;
1524
- }
1525
- declare function useCollection(options?: UseCollectionOptions): swr.SWRResponse<NormalizedCollection | undefined, any, SWRConfiguration<NormalizedCollection | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>)> | undefined>;
1526
-
1527
- interface UseAllCollectionsOptions extends SWRConfiguration<NormalizedCollection[]> {
1528
- first?: number;
1529
- query?: string;
1530
- sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1531
- reverse?: boolean;
1532
- metafieldIdentifiers?: Array<{
1533
- namespace: string;
1534
- key: string;
1535
- }>;
1536
- }
1537
- declare function useAllCollections(options?: UseAllCollectionsOptions): swr.SWRResponse<NormalizedCollection[], any, SWRConfiguration<NormalizedCollection[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>)> | undefined>;
1538
-
1539
- interface UseCollectionsOptions extends SWRConfiguration<CollectionsConnection> {
1540
- first?: number;
1541
- after?: string;
1542
- query?: string;
1543
- sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1544
- reverse?: boolean;
1545
- metafieldIdentifiers?: Array<{
1546
- namespace: string;
1547
- key: string;
1548
- }>;
1549
- }
1550
- declare function useCollections(options?: UseCollectionsOptions): swr.SWRResponse<CollectionsConnection, any, SWRConfiguration<CollectionsConnection, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>)> | undefined>;
1551
-
1552
- interface UseBlogOptions extends SWRConfiguration<NormalizedBlog | undefined> {
1553
- handle?: string;
1554
- metafieldIdentifiers?: Array<{
1555
- namespace: string;
1556
- key: string;
1557
- }>;
1558
- }
1559
- declare function useBlog(options?: UseBlogOptions): swr.SWRResponse<NormalizedBlog | undefined, any, SWRConfiguration<NormalizedBlog | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>)> | undefined>;
1560
-
1561
- interface UseAllBlogsOptions extends SWRConfiguration<NormalizedBlog[]> {
1562
- first?: number;
1563
- query?: string;
1564
- metafieldIdentifiers?: Array<{
1565
- namespace: string;
1566
- key: string;
1567
- }>;
1568
- }
1569
- declare function useAllBlogs(options?: UseAllBlogsOptions): swr.SWRResponse<NormalizedBlog[], any, SWRConfiguration<NormalizedBlog[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>)> | undefined>;
1570
-
1571
- interface UseArticleOptions extends SWRConfiguration<NormalizedArticle | undefined> {
1572
- blogHandle?: string;
1573
- articleHandle?: string;
1574
- metafieldIdentifiers?: Array<{
1575
- namespace: string;
1576
- key: string;
1577
- }>;
1578
- }
1579
- declare function useArticle(options?: UseArticleOptions): swr.SWRResponse<NormalizedArticle | undefined, any, SWRConfiguration<NormalizedArticle | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>)> | undefined>;
1580
-
1581
- interface UseArticlesOptions extends SWRConfiguration<NormalizedArticle[]> {
1582
- first?: number;
1583
- query?: string;
1584
- sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1585
- reverse?: boolean;
1586
- metafieldIdentifiers?: Array<{
1587
- namespace: string;
1588
- key: string;
1589
- }>;
1590
- }
1591
- declare function useArticles(options?: UseArticlesOptions): swr.SWRResponse<NormalizedArticle[], any, SWRConfiguration<NormalizedArticle[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>)> | undefined>;
1265
+ interface UseArticlesOptions extends SWRConfiguration<NormalizedArticle[]> {
1266
+ first?: number;
1267
+ query?: string;
1268
+ sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1269
+ reverse?: boolean;
1270
+ metafieldIdentifiers?: Array<{
1271
+ namespace: string;
1272
+ key: string;
1273
+ }>;
1274
+ }
1275
+ declare function useArticles(options?: UseArticlesOptions): swr.SWRResponse<NormalizedArticle[], any, SWRConfiguration<NormalizedArticle[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>)> | undefined>;
1592
1276
 
1593
1277
  interface UseArticlesInBlogOptions extends SWRConfiguration<NormalizedArticle[]> {
1594
1278
  blogHandle?: string;
@@ -1659,6 +1343,412 @@ interface UseSiteOptions extends SWRConfiguration<SiteInfo | undefined> {
1659
1343
  }
1660
1344
  declare function useSite(options?: UseSiteOptions): swr.SWRResponse<SiteInfo | undefined, any, SWRConfiguration<SiteInfo | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SiteInfo | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SiteInfo | undefined>)> | undefined>;
1661
1345
 
1346
+ interface ShippingMethodsContext {
1347
+ freeShippingMethods: PlusMemberShippingMethodConfig[];
1348
+ paymentShippingMethods: PlusMemberShippingMethodConfig[];
1349
+ nddOverweight: boolean;
1350
+ tddOverweight: boolean;
1351
+ nddCoupon?: string;
1352
+ tddCoupon?: string;
1353
+ isLoadingCoupon: boolean;
1354
+ }
1355
+ interface PlusMemberContextValue<TProduct = any, TVariant = any, TProfile extends {
1356
+ isPlus?: boolean;
1357
+ } = any> {
1358
+ plusMemberMetafields: PlusMemberSettingsMetafields;
1359
+ selectedPlusMemberMode: DeliveryPlusType;
1360
+ setSelectedPlusMemberMode: (value: DeliveryPlusType) => void;
1361
+ selectedShippingMethod?: PlusMemberShippingMethodConfig;
1362
+ setSelectedShippingMethod: (value: PlusMemberShippingMethodConfig) => void;
1363
+ showMoreShippingMethod: boolean;
1364
+ setShowMoreShippingMethod: (value: boolean) => void;
1365
+ variant: TVariant;
1366
+ product: TProduct;
1367
+ shippingMethodsContext: ShippingMethodsContext;
1368
+ selectedPlusMemberVariant: SelectedPlusMemberVariant;
1369
+ showPlusMemberBenefit: boolean;
1370
+ setShowPlusMemberBenefit: (value: boolean) => void;
1371
+ profile?: TProfile;
1372
+ }
1373
+ declare const PlusMemberContext: React$1.Context<PlusMemberContextValue<any, any, any>>;
1374
+
1375
+ /**
1376
+ * Hook to access Plus Member Context
1377
+ */
1378
+ declare function usePlusMemberContext<TProfile extends {
1379
+ isPlus?: boolean;
1380
+ } = any>(): PlusMemberContextValue<any, any, any>;
1381
+
1382
+ /**
1383
+ * Hook to get Plus Member Product Variants (Monthly and Annual)
1384
+ */
1385
+
1386
+ interface UsePlusMemberVariantsOptions {
1387
+ /** Plus member metafields configuration */
1388
+ memberSetting: PlusMemberSettingsMetafields;
1389
+ }
1390
+ interface UsePlusMemberVariantsResult {
1391
+ monthlyVariant?: NormalizedProductVariant & {
1392
+ product: NormalizedProduct | undefined;
1393
+ };
1394
+ annualVariant?: NormalizedProductVariant & {
1395
+ product: NormalizedProduct | undefined;
1396
+ };
1397
+ }
1398
+ /**
1399
+ * Get Plus Member product variants (monthly and annual)
1400
+ *
1401
+ * @param options - Configuration options
1402
+ * @returns Monthly and annual variants
1403
+ *
1404
+ * @example
1405
+ * ```tsx
1406
+ * const { monthlyVariant, annualVariant } = usePlusMemberVariants({
1407
+ * plusMemberMetafields
1408
+ * })
1409
+ * ```
1410
+ */
1411
+ declare function usePlusMemberVariants({ memberSetting, }: UsePlusMemberVariantsOptions): UsePlusMemberVariantsResult;
1412
+
1413
+ /**
1414
+ * Hook to calculate available shipping methods based on product weight and member status
1415
+ */
1416
+
1417
+ interface UseShippingMethodsOptions<TVariant = any, TProfile extends {
1418
+ isPlus?: boolean;
1419
+ } = any> {
1420
+ /** Product variant with weight information */
1421
+ variant: TVariant;
1422
+ /** Plus member metafields configuration */
1423
+ plusMemberMetafields: PlusMemberSettingsMetafields;
1424
+ /** Selected plus member mode */
1425
+ selectedPlusMemberMode: DeliveryPlusType;
1426
+ profile?: TProfile;
1427
+ }
1428
+ interface UseShippingMethodsResult {
1429
+ freeShippingMethods: PlusMemberShippingMethodConfig[];
1430
+ paymentShippingMethods: PlusMemberShippingMethodConfig[];
1431
+ nddOverweight: boolean;
1432
+ tddOverweight: boolean;
1433
+ nddCoupon?: string;
1434
+ tddCoupon?: string;
1435
+ isLoadingCoupon: boolean;
1436
+ }
1437
+ /**
1438
+ * Calculate available shipping methods based on product weight, member status, and available coupons
1439
+ *
1440
+ * @param options - Configuration options
1441
+ * @returns Shipping methods categorized by free/payment and overweight status
1442
+ *
1443
+ * @example
1444
+ * ```tsx
1445
+ * const { freeShippingMethods, paymentShippingMethods, nddOverweight, tddOverweight } = useShippingMethods({
1446
+ * variant,
1447
+ * plusMemberMetafields,
1448
+ * selectedPlusMemberMode,
1449
+ * })
1450
+ * ```
1451
+ */
1452
+ declare function useShippingMethods<TVariant extends {
1453
+ weight?: number;
1454
+ } = any>(options: UseShippingMethodsOptions<TVariant>): UseShippingMethodsResult;
1455
+
1456
+ /**
1457
+ * Hook to replace cart plus member product
1458
+ *
1459
+ * When adding a monthly membership while an annual membership exists in cart,
1460
+ * the annual membership will be replaced and vice versa.
1461
+ *
1462
+ * @returns Handler function to replace conflicting membership products
1463
+ *
1464
+ * @example
1465
+ * ```tsx
1466
+ * const replaceCartPlusMember = useReplaceCartPlusMember()
1467
+ *
1468
+ * // Call before adding new membership product
1469
+ * await replaceCartPlusMember()
1470
+ * ```
1471
+ */
1472
+ declare const useReplaceCartPlusMember: () => () => Promise<void>;
1473
+
1474
+ declare const usePlusMemberCheckoutCustomAttributes: ({ disableShipping, isPresaleContains, }: {
1475
+ disableShipping?: boolean;
1476
+ isPresaleContains?: boolean;
1477
+ }) => NormalizedAttribute[];
1478
+
1479
+ /**
1480
+ * useAutoRemovePlusMemberInCart Hook
1481
+ * 付费会员身份自动移除购物车中的会员产品
1482
+ * 年费会员删除月费会员产品,月费会员删除年费会员产品
1483
+ */
1484
+
1485
+ interface UseAutoRemovePlusMemberInCartProps {
1486
+ profile: any;
1487
+ cart?: NormalizedCart;
1488
+ memberSetting: PlusMemberSettingsMetafields;
1489
+ }
1490
+ /**
1491
+ * 自动移除购物车中的会员产品
1492
+ *
1493
+ * @param props - Hook 参数
1494
+ * @param props.memberSetting - Plus Member 配置
1495
+ * @param props.isMonthlyPlus - 用户是否是月费会员
1496
+ * @param props.isAnnualPlus - 用户是否是年费会员
1497
+ *
1498
+ * @example
1499
+ * ```tsx
1500
+ * const { profile } = useProfile()
1501
+ *
1502
+ * useAutoRemovePlusMemberInCart({
1503
+ * cart,
1504
+ * profile,
1505
+ * })
1506
+ * ```
1507
+ */
1508
+ declare function useAutoRemovePlusMemberInCart({ cart, profile, memberSetting, }: UseAutoRemovePlusMemberInCartProps): void;
1509
+
1510
+ /**
1511
+ * Has Plus Member In Cart
1512
+ * 判断购物车中是否包含年费会员或月费会员产品
1513
+ */
1514
+
1515
+ interface HasPlusMemberInCartProps {
1516
+ /** Plus Member 配置 */
1517
+ memberSetting?: PlusMemberSettingsMetafields;
1518
+ /** 购物车数据 */
1519
+ cart?: NormalizedCart;
1520
+ }
1521
+ interface HasPlusMemberInCartResult {
1522
+ /** 购物车中是否有任何会员产品 */
1523
+ hasPlusMember: boolean;
1524
+ /** 购物车中是否有月费会员产品 */
1525
+ hasMonthlyPlus: boolean;
1526
+ /** 购物车中是否有年费会员产品 */
1527
+ hasAnnualPlus: boolean;
1528
+ /** 月费会员产品的 line item */
1529
+ monthlyPlusItem?: {
1530
+ id: string;
1531
+ quantity: number;
1532
+ handle?: string;
1533
+ sku?: string;
1534
+ };
1535
+ /** 年费会员产品的 line item */
1536
+ annualPlusItem?: {
1537
+ id: string;
1538
+ quantity: number;
1539
+ handle?: string;
1540
+ sku?: string;
1541
+ };
1542
+ }
1543
+ /**
1544
+ * 判断购物车中是否包含年费会员或月费会员产品(纯函数版本)
1545
+ *
1546
+ * @param props - 函数参数
1547
+ * @param props.memberSetting - Plus Member 配置
1548
+ * @param props.cart - 购物车数据
1549
+ * @returns 会员产品信息
1550
+ *
1551
+ * @example
1552
+ * ```tsx
1553
+ * const {
1554
+ * hasPlusMember,
1555
+ * hasMonthlyPlus,
1556
+ * hasAnnualPlus,
1557
+ * monthlyPlusItem,
1558
+ * annualPlusItem,
1559
+ * } = hasPlusMemberInCart({
1560
+ * memberSetting: plusMemberSettings,
1561
+ * cart: currentCart,
1562
+ * })
1563
+ *
1564
+ * if (hasPlusMember) {
1565
+ * console.log('购物车中有会员产品')
1566
+ * }
1567
+ * ```
1568
+ */
1569
+ declare function hasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1570
+ /**
1571
+ * 判断购物车中是否包含年费会员或月费会员产品(Hook 版本)
1572
+ *
1573
+ * 内部使用 hasPlusMemberInCart 纯函数,并通过 useMemo 优化性能
1574
+ *
1575
+ * @param props - Hook 参数
1576
+ * @param props.memberSetting - Plus Member 配置
1577
+ * @param props.cart - 购物车数据
1578
+ * @returns 会员产品信息
1579
+ *
1580
+ * @example
1581
+ * ```tsx
1582
+ * const {
1583
+ * hasPlusMember,
1584
+ * hasMonthlyPlus,
1585
+ * hasAnnualPlus,
1586
+ * monthlyPlusItem,
1587
+ * annualPlusItem,
1588
+ * } = useHasPlusMemberInCart({
1589
+ * memberSetting: plusMemberSettings,
1590
+ * cart: currentCart,
1591
+ * })
1592
+ *
1593
+ * if (hasPlusMember) {
1594
+ * console.log('购物车中有会员产品')
1595
+ * }
1596
+ * ```
1597
+ */
1598
+ declare function useHasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1599
+
1600
+ /**
1601
+ * Hook to check if plus member products are in line items
1602
+ * 判断加购的 line 中是否包含付费会员产品
1603
+ */
1604
+
1605
+ interface UseHasPlusMemberInLinesProps {
1606
+ /** Plus Member 配置 */
1607
+ memberSetting?: PlusMemberSettingsMetafields;
1608
+ /** 加购的 line items */
1609
+ lines: AddToCartLineItem[];
1610
+ }
1611
+ interface HasPlusMemberInLinesResult {
1612
+ /** 加购的 lines 中是否有任何会员产品 */
1613
+ hasPlusMember: boolean;
1614
+ /** 加购的 lines 中是否有月费会员产品 */
1615
+ hasMonthlyPlus: boolean;
1616
+ /** 加购的 lines 中是否有年费会员产品 */
1617
+ hasAnnualPlus: boolean;
1618
+ /** 月费会员产品的 line item */
1619
+ monthlyPlusLine?: AddToCartLineItem;
1620
+ /** 年费会员产品的 line item */
1621
+ annualPlusLine?: AddToCartLineItem;
1622
+ }
1623
+ /**
1624
+ * 判断加购的 line items 中是否包含付费会员产品(纯函数版本)
1625
+ *
1626
+ * @param props - 函数参数
1627
+ * @param props.memberSetting - Plus Member 配置
1628
+ * @param props.lines - 加购的 line items
1629
+ * @returns 会员产品信息
1630
+ *
1631
+ * @example
1632
+ * ```tsx
1633
+ * const {
1634
+ * hasPlusMember,
1635
+ * hasMonthlyPlus,
1636
+ * hasAnnualPlus,
1637
+ * } = hasPlusMemberInLines({
1638
+ * memberSetting: plusMemberSettings,
1639
+ * lines: lineItems,
1640
+ * })
1641
+ *
1642
+ * if (hasPlusMember) {
1643
+ * console.log('加购的商品中包含会员产品')
1644
+ * }
1645
+ * ```
1646
+ */
1647
+ declare function hasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
1648
+ /**
1649
+ * 判断加购的 line items 中是否包含付费会员产品(Hook 版本)
1650
+ *
1651
+ * 内部使用 hasPlusMemberInLines 纯函数,并通过 useMemo 优化性能
1652
+ *
1653
+ * @param props - Hook 参数
1654
+ * @param props.memberSetting - Plus Member 配置
1655
+ * @param props.lines - 加购的 line items
1656
+ * @returns 会员产品信息
1657
+ *
1658
+ * @example
1659
+ * ```tsx
1660
+ * const {
1661
+ * hasPlusMember,
1662
+ * hasMonthlyPlus,
1663
+ * hasAnnualPlus,
1664
+ * monthlyPlusLine,
1665
+ * annualPlusLine,
1666
+ * } = useHasPlusMemberInLines({
1667
+ * memberSetting: plusMemberSettings,
1668
+ * lines: lineItems,
1669
+ * })
1670
+ *
1671
+ * if (hasPlusMember) {
1672
+ * console.log('加购的商品中包含会员产品')
1673
+ * }
1674
+ * ```
1675
+ */
1676
+ declare function useHasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
1677
+
1678
+ /**
1679
+ * 返回需要添加到购物车的 Plus Member 产品
1680
+ *
1681
+ * 该 hook 会根据用户选择的会员模式和购物车现有状态,
1682
+ * 返回需要添加的会员产品。如果不需要添加会员产品,则返回 undefined。
1683
+ *
1684
+ * @param props - Hook 参数
1685
+ * @param props.cart - 购物车数据
1686
+ * @returns Plus Member 产品对象或 undefined
1687
+ *
1688
+ * @example
1689
+ * ```tsx
1690
+ * const plusMemberVariant = usePlusMemberNeedAddToCart({
1691
+ * cart,
1692
+ * })
1693
+ *
1694
+ * ```
1695
+ */
1696
+ declare function usePlusMemberNeedAddToCart({ cart, profile, }: {
1697
+ cart: NormalizedCart;
1698
+ profile?: any;
1699
+ }): (_anker_in_shopify_sdk.NormalizedProductVariant & {
1700
+ product: _anker_in_shopify_sdk.NormalizedProduct | undefined;
1701
+ }) | undefined;
1702
+
1703
+ interface UseAvailableDeliveryCouponResult {
1704
+ nddCoupon?: string;
1705
+ tddCoupon?: string;
1706
+ isLoading: boolean;
1707
+ }
1708
+ declare const useAvailableDeliveryCoupon: ({ profile, }: {
1709
+ profile?: any;
1710
+ }) => UseAvailableDeliveryCouponResult;
1711
+
1712
+ interface PlusMemberProviderProps<TProduct = any, TVariant = any, TProfile extends {
1713
+ isPlus?: boolean;
1714
+ } = any> {
1715
+ variant: TVariant;
1716
+ product: TProduct;
1717
+ memberSetting: PlusMemberSettingsMetafields;
1718
+ initialSelectedPlusMemberMode?: DeliveryPlusType;
1719
+ profile?: TProfile;
1720
+ }
1721
+ /**
1722
+ * Plus Member Provider Component
1723
+ *
1724
+ * Provides Plus Member context and state management to child components.
1725
+ *
1726
+ * @param variant - Product variant
1727
+ * @param product - Product
1728
+ * @param metafields - Plus member settings from metafields
1729
+ * @param initialSelectedPlusMemberMode - Initial selected mode (default: 'free')
1730
+ * @param profile - User profile
1731
+ * @param locale - Locale code
1732
+ * @param children - Child components
1733
+ *
1734
+ * @example
1735
+ * ```tsx
1736
+ * <PlusMemberProvider
1737
+ * variant={variant}
1738
+ * product={product}
1739
+ * memberSetting={memberSetting}
1740
+ * profile={profile}
1741
+ * >
1742
+ * <YourComponent />
1743
+ * </PlusMemberProvider>
1744
+ * ```
1745
+ */
1746
+ declare const PlusMemberProvider: <TProduct = any, TVariant extends {
1747
+ weight?: number;
1748
+ } = any, TProfile extends {
1749
+ isPlus?: boolean;
1750
+ } = any>({ variant, product, memberSetting, initialSelectedPlusMemberMode, profile, children, }: PropsWithChildren<PlusMemberProviderProps<TProduct, TVariant, TProfile>>) => react_jsx_runtime.JSX.Element;
1751
+
1662
1752
  /**
1663
1753
  * useIntersection Hook
1664
1754
  *
@@ -1894,4 +1984,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
1894
1984
  */
1895
1985
  declare function clearGeoLocationCache(cacheKey?: string): void;
1896
1986
 
1897
- export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, type UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdateCartAttributesOptions, type VariantItem, type VariantMedia, type VideoMedia, 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 };
1987
+ export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GetCartAttributesProps, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type HasPlusMemberInLinesResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInLinesProps, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, type UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdateCartAttributesOptions, type VariantItem, type VariantMedia, type VideoMedia, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, 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, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };