@anker-in/shopify-react 0.1.1-beta.42 → 0.1.1-beta.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.mts +711 -714
- package/dist/hooks/index.d.ts +711 -714
- package/dist/hooks/index.js +1550 -1682
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1547 -1680
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1574 -1689
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1571 -1687
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +7 -1
- package/dist/provider/index.d.ts +7 -1
- package/dist/provider/index.js +205 -225
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +205 -225
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-DntkHhf8.d.mts → types-CMMWxyUF.d.mts} +2 -6
- package/dist/{types-DntkHhf8.d.ts → types-CMMWxyUF.d.ts} +2 -6
- package/package.json +5 -5
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import * as swr_mutation from 'swr/mutation';
|
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
4
|
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, NormalizedAttribute, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle } from '@anker-in/shopify-sdk';
|
|
5
|
-
import { U as UseAddToCartOptions, a as AddToCartInput, A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig,
|
|
6
|
-
export { g as DeliveryCustomData, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, c as PlusMemberShippingMethodMetafields, S as ShippingMethodMode } from '../types-
|
|
5
|
+
import { U as UseAddToCartOptions, a as AddToCartInput, A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, e as PlusMemberSettingsMetafields, d as PlusMemberShippingMethodConfig, D as DeliveryPlusType, f as SelectedPlusMemberVariant } from '../types-CMMWxyUF.js';
|
|
6
|
+
export { g as DeliveryCustomData, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, c as PlusMemberShippingMethodMetafields, S as ShippingMethodMode } from '../types-CMMWxyUF.js';
|
|
7
7
|
import Decimal from 'decimal.js';
|
|
8
8
|
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 {
|
|
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(
|
|
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,839 +690,503 @@ interface OrderDiscountResult {
|
|
|
685
690
|
*/
|
|
686
691
|
declare const useCalcOrderDiscount: (cart: any, orderDiscountConfig?: OrderDiscountConfig[], customer?: any) => OrderDiscountResult;
|
|
687
692
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
allowNextDayDelivery: boolean;
|
|
703
|
-
setAllowNextDayDelivery: (value: boolean) => void;
|
|
704
|
-
allowThirdDayDelivery: boolean;
|
|
705
|
-
setAllowThirdDayDelivery: (value: boolean) => void;
|
|
706
|
-
selectedPlusMemberMode: DeliveryPlusType;
|
|
707
|
-
setSelectedPlusMemberMode: (value: DeliveryPlusType) => void;
|
|
708
|
-
showAreaCheckModal: boolean;
|
|
709
|
-
setShowAreaCheckModal: (value: boolean) => void;
|
|
710
|
-
selectedShippingMethod?: PlusMemberShippingMethodConfig;
|
|
711
|
-
setSelectedShippingMethod: (value: PlusMemberShippingMethodConfig) => void;
|
|
712
|
-
showTip: boolean;
|
|
713
|
-
setShowTip: (value: boolean) => void;
|
|
714
|
-
showMoreShippingMethod: boolean;
|
|
715
|
-
setShowMoreShippingMethod: (value: boolean) => void;
|
|
716
|
-
variant: TVariant;
|
|
717
|
-
product: TProduct;
|
|
718
|
-
shippingMethodsContext: ShippingMethodsContext;
|
|
719
|
-
selectedPlusMemberVariant: SelectedPlusMemberVariant;
|
|
720
|
-
monthlyVariant?: NormalizedProductVariant & {
|
|
721
|
-
product: NormalizedProduct | undefined;
|
|
722
|
-
};
|
|
723
|
-
annualVariant?: NormalizedProductVariant & {
|
|
724
|
-
product: NormalizedProduct | undefined;
|
|
725
|
-
};
|
|
726
|
-
showPlusMemberBenefit: boolean;
|
|
727
|
-
setShowPlusMemberBenefit: (value: boolean) => void;
|
|
728
|
-
deleteMarginBottom: boolean;
|
|
729
|
-
setDeleteMarginBottom: (value: boolean) => void;
|
|
730
|
-
profile?: TProfile;
|
|
731
|
-
locale?: string;
|
|
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;
|
|
732
707
|
}
|
|
733
|
-
declare const PlusMemberContext: React$1.Context<PlusMemberContextValue<any, any, any>>;
|
|
734
|
-
|
|
735
708
|
/**
|
|
736
|
-
*
|
|
709
|
+
* Get cart attributes (pure function version)
|
|
737
710
|
*/
|
|
738
|
-
declare function
|
|
739
|
-
|
|
711
|
+
declare function getCartAttributes({ profile, customer, cart, memberType, currentUrl, }: GetCartAttributesProps): Array<{
|
|
712
|
+
key: string;
|
|
713
|
+
value: any;
|
|
714
|
+
}>;
|
|
740
715
|
/**
|
|
741
|
-
* Hook to get
|
|
716
|
+
* Hook to get cart attributes
|
|
742
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
|
+
};
|
|
743
729
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
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
|
+
}>;
|
|
754
742
|
};
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
* @param options - Configuration options
|
|
760
|
-
* @returns Monthly and annual variants
|
|
761
|
-
*
|
|
762
|
-
* @example
|
|
763
|
-
* ```tsx
|
|
764
|
-
* const { monthlyVariant, annualVariant } = usePlusMemberVariants({
|
|
765
|
-
* plusMemberMetafields
|
|
766
|
-
* })
|
|
767
|
-
* ```
|
|
768
|
-
*/
|
|
769
|
-
declare function usePlusMemberVariants({ memberSetting, }: UsePlusMemberVariantsOptions): UsePlusMemberVariantsResult;
|
|
743
|
+
}) => {
|
|
744
|
+
min: number;
|
|
745
|
+
max: number;
|
|
746
|
+
};
|
|
770
747
|
|
|
771
748
|
/**
|
|
772
|
-
* Hook to
|
|
749
|
+
* Hook to check if plus member products are in line items
|
|
750
|
+
* 判断加购的 line 中是否包含付费会员产品
|
|
773
751
|
*/
|
|
774
752
|
|
|
775
|
-
interface
|
|
776
|
-
/**
|
|
777
|
-
|
|
778
|
-
/**
|
|
779
|
-
|
|
780
|
-
/** Whether third day delivery is allowed */
|
|
781
|
-
allowThirdDayDelivery: boolean;
|
|
782
|
-
/** Plus member metafields configuration */
|
|
783
|
-
plusMemberMetafields: PlusMemberSettingsMetafields;
|
|
784
|
-
/** Selected plus member mode */
|
|
785
|
-
selectedPlusMemberMode: DeliveryPlusType;
|
|
786
|
-
/** Whether user is a plus member */
|
|
787
|
-
isPlus?: boolean;
|
|
788
|
-
profile?: any;
|
|
753
|
+
interface UseHasPlusMemberInLinesProps {
|
|
754
|
+
/** Plus Member 配置 */
|
|
755
|
+
memberSetting?: PlusMemberSettingsMetafields;
|
|
756
|
+
/** 加购的 line items */
|
|
757
|
+
lines: AddToCartLineItem[];
|
|
789
758
|
}
|
|
790
|
-
interface
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
759
|
+
interface HasPlusMemberInLinesResult {
|
|
760
|
+
/** 加购的 lines 中是否有任何会员产品 */
|
|
761
|
+
hasPlusMember: boolean;
|
|
762
|
+
/** 加购的 lines 中是否有月费会员产品 */
|
|
763
|
+
hasMonthlyPlus: boolean;
|
|
764
|
+
/** 加购的 lines 中是否有年费会员产品 */
|
|
765
|
+
hasAnnualPlus: boolean;
|
|
766
|
+
/** 月费会员产品的 line item */
|
|
767
|
+
monthlyPlusLine?: AddToCartLineItem;
|
|
768
|
+
/** 年费会员产品的 line item */
|
|
769
|
+
annualPlusLine?: AddToCartLineItem;
|
|
798
770
|
}
|
|
799
771
|
/**
|
|
800
|
-
*
|
|
772
|
+
* 判断加购的 line items 中是否包含付费会员产品(纯函数版本)
|
|
801
773
|
*
|
|
802
|
-
* @param
|
|
803
|
-
* @
|
|
774
|
+
* @param props - 函数参数
|
|
775
|
+
* @param props.memberSetting - Plus Member 配置
|
|
776
|
+
* @param props.lines - 加购的 line items
|
|
777
|
+
* @returns 会员产品信息
|
|
804
778
|
*
|
|
805
779
|
* @example
|
|
806
780
|
* ```tsx
|
|
807
|
-
* const {
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
781
|
+
* const {
|
|
782
|
+
* hasPlusMember,
|
|
783
|
+
* hasMonthlyPlus,
|
|
784
|
+
* hasAnnualPlus,
|
|
785
|
+
* } = hasPlusMemberInLines({
|
|
786
|
+
* memberSetting: plusMemberSettings,
|
|
787
|
+
* lines: lineItems,
|
|
814
788
|
* })
|
|
789
|
+
*
|
|
790
|
+
* if (hasPlusMember) {
|
|
791
|
+
* console.log('加购的商品中包含会员产品')
|
|
792
|
+
* }
|
|
815
793
|
* ```
|
|
816
794
|
*/
|
|
817
|
-
declare function
|
|
818
|
-
weight?: number;
|
|
819
|
-
} = any>(options: UseShippingMethodsOptions<TVariant>): UseShippingMethodsResult;
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Hook to check shipping method availability and automatically adjust selection
|
|
823
|
-
*/
|
|
824
|
-
declare function useShippingMethodAvailableCheck(): void;
|
|
825
|
-
|
|
795
|
+
declare function hasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
|
|
826
796
|
/**
|
|
827
|
-
*
|
|
797
|
+
* 判断加购的 line items 中是否包含付费会员产品(Hook 版本)
|
|
828
798
|
*
|
|
829
|
-
*
|
|
830
|
-
* the annual membership will be replaced and vice versa.
|
|
799
|
+
* 内部使用 hasPlusMemberInLines 纯函数,并通过 useMemo 优化性能
|
|
831
800
|
*
|
|
832
|
-
* @
|
|
801
|
+
* @param props - Hook 参数
|
|
802
|
+
* @param props.memberSetting - Plus Member 配置
|
|
803
|
+
* @param props.lines - 加购的 line items
|
|
804
|
+
* @returns 会员产品信息
|
|
833
805
|
*
|
|
834
806
|
* @example
|
|
835
807
|
* ```tsx
|
|
836
|
-
* const
|
|
808
|
+
* const {
|
|
809
|
+
* hasPlusMember,
|
|
810
|
+
* hasMonthlyPlus,
|
|
811
|
+
* hasAnnualPlus,
|
|
812
|
+
* monthlyPlusLine,
|
|
813
|
+
* annualPlusLine,
|
|
814
|
+
* } = useHasPlusMemberInLines({
|
|
815
|
+
* memberSetting: plusMemberSettings,
|
|
816
|
+
* lines: lineItems,
|
|
817
|
+
* })
|
|
837
818
|
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
819
|
+
* if (hasPlusMember) {
|
|
820
|
+
* console.log('加购的商品中包含会员产品')
|
|
821
|
+
* }
|
|
840
822
|
* ```
|
|
841
823
|
*/
|
|
842
|
-
declare
|
|
824
|
+
declare function useHasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
|
|
843
825
|
|
|
844
826
|
/**
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
* Extracts and returns the discount codes from the delivery custom data.
|
|
848
|
-
*
|
|
849
|
-
* @param deliveryData - Delivery data containing custom attributes
|
|
850
|
-
* @returns Array of discount codes or undefined
|
|
851
|
-
*
|
|
852
|
-
* @example
|
|
853
|
-
* ```tsx
|
|
854
|
-
* const deliveryCodes = usePlusMemberDeliveryCodes({ deliveryData })
|
|
855
|
-
* ```
|
|
827
|
+
* 更新购物车中各个 item 的折后价相关的属性
|
|
856
828
|
*/
|
|
857
|
-
declare const
|
|
858
|
-
|
|
859
|
-
|
|
829
|
+
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
830
|
+
cart?: NormalizedCart;
|
|
831
|
+
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
832
|
+
isCartLoading: boolean;
|
|
833
|
+
setLoadingState: React.Dispatch<React.SetStateAction<any>>;
|
|
834
|
+
metafieldIdentifiers?: {
|
|
835
|
+
variant: HasMetafieldsIdentifier[];
|
|
836
|
+
product: HasMetafieldsIdentifier[];
|
|
837
|
+
};
|
|
838
|
+
}) => void;
|
|
839
|
+
|
|
840
|
+
declare const currencyCodeMapping: Record<string, string>;
|
|
841
|
+
declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
|
|
842
|
+
throwOnError?: boolean;
|
|
843
|
+
};
|
|
844
|
+
declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
|
|
845
|
+
declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
|
|
846
|
+
declare const CODE_AMOUNT_KEY = "_sku_code_money";
|
|
847
|
+
declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
848
|
+
declare const MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
|
|
849
|
+
declare const MAIN_PRODUCT_CODE: string[];
|
|
860
850
|
|
|
861
|
-
interface UseUpdatePlusMemberDeliveryOptionsProps {
|
|
862
|
-
/** SWR mutation configuration */
|
|
863
|
-
options?: SWRMutationConfiguration<any, Error, 'update-cart-delivery-options', {
|
|
864
|
-
deliveryData: DeliveryData;
|
|
865
|
-
}>;
|
|
866
|
-
}
|
|
867
851
|
/**
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* This hook extracts the selected delivery option from delivery custom data and
|
|
871
|
-
* maps it to the appropriate delivery option handle from the cart's deliveryGroups.
|
|
872
|
-
* It then triggers the update-cart-delivery-options mutation to apply the selection.
|
|
873
|
-
*
|
|
874
|
-
* The hook handles:
|
|
875
|
-
* - Extracting delivery option code from deliveryCustomData.selected_delivery_option
|
|
876
|
-
* - Finding the matching delivery option in cart.deliveryGroups
|
|
877
|
-
* - Triggering the cart update with the correct delivery option handle
|
|
878
|
-
*
|
|
879
|
-
* @param props - Hook properties
|
|
880
|
-
* @returns useSWRMutation result with trigger and loading state
|
|
881
|
-
*
|
|
882
|
-
* @example
|
|
883
|
-
* ```tsx
|
|
884
|
-
* const { trigger, isMutating } = useUpdatePlusMemberDeliveryOptions()
|
|
885
|
-
*
|
|
886
|
-
* // Trigger update with delivery data
|
|
887
|
-
* await trigger({ deliveryData })
|
|
888
|
-
* ```
|
|
852
|
+
* Normalize AddToCartLineItem[] to NormalizedLineItem[] format
|
|
853
|
+
* This is used to calculate gifts from lines before they are added to cart
|
|
889
854
|
*/
|
|
890
|
-
declare
|
|
891
|
-
deliveryData: DeliveryData;
|
|
892
|
-
}>;
|
|
893
|
-
|
|
855
|
+
declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
|
|
894
856
|
/**
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
* Creates custom attributes based on delivery data to be attached to line items.
|
|
898
|
-
*
|
|
899
|
-
* @param deliveryData - Delivery data containing custom attributes
|
|
900
|
-
* @returns Array of custom attributes for line items
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* ```tsx
|
|
904
|
-
* const itemAttributes = usePlusMemberItemCustomAttributes({ deliveryData })
|
|
905
|
-
*
|
|
906
|
-
* // Use in addToCart
|
|
907
|
-
* await addToCart({
|
|
908
|
-
* lineItems: lineItems.map(item => ({
|
|
909
|
-
* ...item,
|
|
910
|
-
* customAttributes: [...(item.customAttributes || []), ...itemAttributes]
|
|
911
|
-
* }))
|
|
912
|
-
* })
|
|
913
|
-
* ```
|
|
857
|
+
* Create a mock cart structure from AddToCartLineItem[]
|
|
858
|
+
* This is useful for calculating gifts before actual cart operations
|
|
914
859
|
*/
|
|
915
|
-
declare
|
|
916
|
-
|
|
917
|
-
|
|
860
|
+
declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
|
|
861
|
+
|
|
862
|
+
declare const getQuery: () => Record<string, string>;
|
|
863
|
+
|
|
864
|
+
declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
|
|
865
|
+
declare const safeParse: (str: string) => any;
|
|
866
|
+
declare const getDiscountEnvAttributeValue: (attributes?: {
|
|
867
|
+
key: string;
|
|
868
|
+
value: string;
|
|
869
|
+
}[]) => any;
|
|
870
|
+
declare const checkAttributesUpdateNeeded: (oldAttributes: NormalizedAttribute[], newAttributes: NormalizedAttribute[], customAttributesNeedRemove: {
|
|
871
|
+
key: string;
|
|
872
|
+
}[]) => boolean;
|
|
873
|
+
declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
|
|
874
|
+
declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
|
|
875
|
+
scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
|
|
876
|
+
gradient_gifts: any;
|
|
877
|
+
locale: string;
|
|
878
|
+
}) => any[];
|
|
879
|
+
declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
|
|
880
|
+
locale: string;
|
|
881
|
+
qualifyingGift?: FormattedGift | null;
|
|
882
|
+
giftProductsResult?: NormalizedProduct[] | [];
|
|
883
|
+
}) => any[];
|
|
918
884
|
|
|
885
|
+
interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
|
|
886
|
+
handle?: string;
|
|
887
|
+
metafieldIdentifiers?: Array<{
|
|
888
|
+
namespace: string;
|
|
889
|
+
key: string;
|
|
890
|
+
}>;
|
|
891
|
+
}
|
|
919
892
|
/**
|
|
920
|
-
* Hook to
|
|
893
|
+
* Hook to fetch a single product by handle
|
|
921
894
|
*
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
*
|
|
925
|
-
* Requires profile to be provided via PlusMemberContext.
|
|
926
|
-
*
|
|
927
|
-
* @param deliveryData - Delivery data containing custom attributes
|
|
928
|
-
* @param product - Product information (optional, for hiding shipping benefits check)
|
|
929
|
-
* @param variant - Variant information (optional, for presale and hiding shipping benefits check)
|
|
930
|
-
* @param isShowShippingBenefits - Function to check if shipping benefits should be shown (optional)
|
|
931
|
-
* @returns Array of custom attributes for checkout
|
|
895
|
+
* @param options - Hook options including handle and SWR configuration
|
|
896
|
+
* @returns SWR response with product data
|
|
932
897
|
*
|
|
933
898
|
* @example
|
|
934
|
-
* ```
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
* customer,
|
|
940
|
-
* isShowShippingBenefits
|
|
941
|
-
* })
|
|
899
|
+
* ```typescript
|
|
900
|
+
* function ProductPage() {
|
|
901
|
+
* const { data: product, error, isLoading } = useProduct({
|
|
902
|
+
* handle: 'my-product'
|
|
903
|
+
* })
|
|
942
904
|
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
905
|
+
* if (isLoading) return <div>Loading...</div>
|
|
906
|
+
* if (error) return <div>Error loading product</div>
|
|
907
|
+
* if (!product) return <div>Product not found</div>
|
|
908
|
+
*
|
|
909
|
+
* return (
|
|
910
|
+
* <div>
|
|
911
|
+
* <h1>{product.title}</h1>
|
|
912
|
+
* <p>{product.description}</p>
|
|
913
|
+
* <p>${product.price.amount}</p>
|
|
914
|
+
* </div>
|
|
915
|
+
* )
|
|
916
|
+
* }
|
|
948
917
|
* ```
|
|
949
918
|
*/
|
|
950
|
-
declare
|
|
951
|
-
deliveryData?: DeliveryData;
|
|
952
|
-
product?: TProduct;
|
|
953
|
-
variant?: TVariant;
|
|
954
|
-
isShowShippingBenefits?: (args: {
|
|
955
|
-
variant?: TVariant;
|
|
956
|
-
product?: TProduct;
|
|
957
|
-
setting: any;
|
|
958
|
-
}) => boolean;
|
|
959
|
-
}) => NormalizedAttribute[];
|
|
960
|
-
|
|
961
|
-
/**
|
|
962
|
-
* useAutoRemovePlusMemberInCart Hook
|
|
963
|
-
* 付费会员身份自动移除购物车中的会员产品
|
|
964
|
-
* 年费会员删除月费会员产品,月费会员删除年费会员产品
|
|
965
|
-
*/
|
|
919
|
+
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>;
|
|
966
920
|
|
|
967
|
-
interface
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
921
|
+
interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
922
|
+
first?: number;
|
|
923
|
+
query?: string;
|
|
924
|
+
sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
|
|
925
|
+
reverse?: boolean;
|
|
926
|
+
metafieldIdentifiers?: Array<{
|
|
927
|
+
namespace: string;
|
|
928
|
+
key: string;
|
|
929
|
+
}>;
|
|
971
930
|
}
|
|
972
931
|
/**
|
|
973
|
-
*
|
|
932
|
+
* Hook to fetch all products
|
|
974
933
|
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
* @param
|
|
934
|
+
* This hook automatically handles pagination and fetches all products.
|
|
935
|
+
* Use with caution on stores with many products.
|
|
936
|
+
*
|
|
937
|
+
* @param options - Hook options including query parameters and SWR configuration
|
|
938
|
+
* @returns SWR response with products array
|
|
979
939
|
*
|
|
980
940
|
* @example
|
|
981
|
-
* ```
|
|
982
|
-
*
|
|
941
|
+
* ```typescript
|
|
942
|
+
* function ProductList() {
|
|
943
|
+
* const { data: products, error, isLoading } = useAllProducts({
|
|
944
|
+
* sortKey: 'TITLE',
|
|
945
|
+
* reverse: false
|
|
946
|
+
* })
|
|
983
947
|
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
*
|
|
948
|
+
* if (isLoading) return <div>Loading...</div>
|
|
949
|
+
* if (error) return <div>Error loading products</div>
|
|
950
|
+
*
|
|
951
|
+
* return (
|
|
952
|
+
* <div>
|
|
953
|
+
* {products?.map(product => (
|
|
954
|
+
* <div key={product.id}>
|
|
955
|
+
* <h2>{product.title}</h2>
|
|
956
|
+
* <p>${product.price.amount}</p>
|
|
957
|
+
* </div>
|
|
958
|
+
* ))}
|
|
959
|
+
* </div>
|
|
960
|
+
* )
|
|
961
|
+
* }
|
|
988
962
|
* ```
|
|
989
963
|
*/
|
|
990
|
-
declare function
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* useHasPlusMemberInCart Hook
|
|
994
|
-
* 判断购物车中是否包含年费会员或月费会员产品
|
|
995
|
-
*/
|
|
964
|
+
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>;
|
|
996
965
|
|
|
997
|
-
interface
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
interface HasPlusMemberInCartResult {
|
|
1004
|
-
/** 购物车中是否有任何会员产品 */
|
|
1005
|
-
hasPlusMember: boolean;
|
|
1006
|
-
/** 购物车中是否有月费会员产品 */
|
|
1007
|
-
hasMonthlyPlus: boolean;
|
|
1008
|
-
/** 购物车中是否有年费会员产品 */
|
|
1009
|
-
hasAnnualPlus: boolean;
|
|
1010
|
-
/** 月费会员产品的 line item */
|
|
1011
|
-
monthlyPlusItem?: {
|
|
1012
|
-
id: string;
|
|
1013
|
-
quantity: number;
|
|
1014
|
-
handle?: string;
|
|
1015
|
-
sku?: string;
|
|
1016
|
-
};
|
|
1017
|
-
/** 年费会员产品的 line item */
|
|
1018
|
-
annualPlusItem?: {
|
|
1019
|
-
id: string;
|
|
1020
|
-
quantity: number;
|
|
1021
|
-
handle?: string;
|
|
1022
|
-
sku?: string;
|
|
966
|
+
interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
967
|
+
handles?: string[];
|
|
968
|
+
metafieldIdentifiers?: {
|
|
969
|
+
product: HasMetafieldsIdentifier[];
|
|
970
|
+
variant: HasMetafieldsIdentifier[];
|
|
1023
971
|
};
|
|
1024
972
|
}
|
|
1025
973
|
/**
|
|
1026
|
-
*
|
|
974
|
+
* Hook to fetch multiple products by their handles
|
|
1027
975
|
*
|
|
1028
|
-
* @param
|
|
1029
|
-
* @
|
|
1030
|
-
* @returns 会员产品信息
|
|
976
|
+
* @param options - Hook options including handles array and SWR configuration
|
|
977
|
+
* @returns SWR response with products array
|
|
1031
978
|
*
|
|
1032
979
|
* @example
|
|
1033
|
-
* ```
|
|
1034
|
-
*
|
|
1035
|
-
*
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
* monthlyPlusItem,
|
|
1039
|
-
* annualPlusItem,
|
|
1040
|
-
* } = useHasPlusMemberInCart({
|
|
1041
|
-
* memberSetting: plusMemberSettings,
|
|
1042
|
-
* })
|
|
980
|
+
* ```typescript
|
|
981
|
+
* function FeaturedProducts() {
|
|
982
|
+
* const { data: products, error, isLoading } = useProductsByHandles({
|
|
983
|
+
* handles: ['product-1', 'product-2', 'product-3']
|
|
984
|
+
* })
|
|
1043
985
|
*
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
986
|
+
* if (isLoading) return <div>Loading...</div>
|
|
987
|
+
* if (error) return <div>Error loading products</div>
|
|
988
|
+
*
|
|
989
|
+
* return (
|
|
990
|
+
* <div>
|
|
991
|
+
* {products?.map(product => (
|
|
992
|
+
* <div key={product.id}>
|
|
993
|
+
* <h2>{product.title}</h2>
|
|
994
|
+
* <p>${product.price.amount}</p>
|
|
995
|
+
* </div>
|
|
996
|
+
* ))}
|
|
997
|
+
* </div>
|
|
998
|
+
* )
|
|
1046
999
|
* }
|
|
1047
1000
|
* ```
|
|
1048
1001
|
*/
|
|
1049
|
-
declare function
|
|
1002
|
+
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>;
|
|
1050
1003
|
|
|
1051
1004
|
/**
|
|
1052
|
-
*
|
|
1005
|
+
* useVariant Hook
|
|
1053
1006
|
*
|
|
1054
|
-
*
|
|
1055
|
-
|
|
1007
|
+
* Client-side hook to get the selected variant based on selected options
|
|
1008
|
+
*/
|
|
1009
|
+
|
|
1010
|
+
type Options = Record<string, string>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Hook to manage variant selection based on selected options
|
|
1056
1013
|
*
|
|
1057
|
-
* @param
|
|
1058
|
-
* @param
|
|
1059
|
-
* @returns
|
|
1014
|
+
* @param product - The product object
|
|
1015
|
+
* @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
|
|
1016
|
+
* @returns The matching variant
|
|
1060
1017
|
*
|
|
1061
1018
|
* @example
|
|
1062
|
-
* ```
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
* })
|
|
1019
|
+
* ```typescript
|
|
1020
|
+
* function ProductDetail() {
|
|
1021
|
+
* const { data: product } = useProduct({ handle: 'my-product' })
|
|
1022
|
+
* const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
|
|
1023
|
+
* const variant = useVariant({ product, selectedOptions })
|
|
1066
1024
|
*
|
|
1025
|
+
* return (
|
|
1026
|
+
* <div>
|
|
1027
|
+
* <h1>{product.title}</h1>
|
|
1028
|
+
* <p>Selected: {variant.title}</p>
|
|
1029
|
+
* <p>Price: ${variant.price.amount}</p>
|
|
1030
|
+
* <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
|
|
1031
|
+
* </div>
|
|
1032
|
+
* )
|
|
1033
|
+
* }
|
|
1067
1034
|
* ```
|
|
1068
1035
|
*/
|
|
1069
|
-
declare function
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}):
|
|
1073
|
-
product: _anker_in_shopify_sdk.NormalizedProduct | undefined;
|
|
1074
|
-
}) | undefined;
|
|
1036
|
+
declare function useVariant({ product, selectedOptions, }: {
|
|
1037
|
+
product?: NormalizedProduct;
|
|
1038
|
+
selectedOptions: Options;
|
|
1039
|
+
}): NormalizedProductVariant | undefined;
|
|
1075
1040
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1041
|
+
/**
|
|
1042
|
+
* usePrice Hook
|
|
1043
|
+
*
|
|
1044
|
+
* Client-side hook to format price for display
|
|
1045
|
+
*/
|
|
1046
|
+
interface UsePriceOptions {
|
|
1047
|
+
amount: number;
|
|
1048
|
+
baseAmount?: number;
|
|
1049
|
+
currencyCode: string;
|
|
1050
|
+
soldOutDescription?: string;
|
|
1051
|
+
maximumFractionDigits?: number;
|
|
1052
|
+
minimumFractionDigits?: number;
|
|
1053
|
+
removeTrailingZeros?: boolean;
|
|
1080
1054
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
interface PlusMemberProviderProps<TProduct = any, TVariant = any, TProfile = any> {
|
|
1086
|
-
variant: TVariant;
|
|
1087
|
-
product: TProduct;
|
|
1088
|
-
memberSetting: PlusMemberSettingsMetafields;
|
|
1089
|
-
initialSelectedPlusMemberMode?: DeliveryPlusType;
|
|
1090
|
-
profile?: TProfile;
|
|
1055
|
+
interface UsePriceResult {
|
|
1056
|
+
price: string;
|
|
1057
|
+
basePrice?: string;
|
|
1058
|
+
free: boolean;
|
|
1091
1059
|
}
|
|
1092
1060
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
* Provides Plus Member context and state management to child components.
|
|
1061
|
+
* Hook to format price for display
|
|
1096
1062
|
*
|
|
1097
|
-
* @param
|
|
1098
|
-
* @
|
|
1099
|
-
* @param metafields - Plus member settings from metafields
|
|
1100
|
-
* @param initialSelectedPlusMemberMode - Initial selected mode (default: 'free')
|
|
1101
|
-
* @param profile - User profile
|
|
1102
|
-
* @param locale - Locale code
|
|
1103
|
-
* @param children - Child components
|
|
1104
|
-
*
|
|
1105
|
-
* @example
|
|
1106
|
-
* ```tsx
|
|
1107
|
-
* <PlusMemberProvider
|
|
1108
|
-
* variant={variant}
|
|
1109
|
-
* product={product}
|
|
1110
|
-
* memberSetting={memberSetting}
|
|
1111
|
-
* profile={profile}
|
|
1112
|
-
* >
|
|
1113
|
-
* <YourComponent />
|
|
1114
|
-
* </PlusMemberProvider>
|
|
1115
|
-
* ```
|
|
1116
|
-
*/
|
|
1117
|
-
declare const PlusMemberProvider: <TProduct = any, TVariant extends {
|
|
1118
|
-
weight?: number;
|
|
1119
|
-
} = any, TProfile extends {
|
|
1120
|
-
isPlus?: boolean;
|
|
1121
|
-
} = any>({ variant, product, memberSetting, initialSelectedPlusMemberMode, profile, children, }: PropsWithChildren<PlusMemberProviderProps<TProduct, TVariant, TProfile>>) => react_jsx_runtime.JSX.Element;
|
|
1122
|
-
|
|
1123
|
-
declare const getReferralAttributes: () => {
|
|
1124
|
-
key: string;
|
|
1125
|
-
value: any;
|
|
1126
|
-
}[];
|
|
1127
|
-
declare const useCartAttributes: ({ profile, customer, cart, memberSetting, }: {
|
|
1128
|
-
profile: any;
|
|
1129
|
-
customer: any;
|
|
1130
|
-
cart?: NormalizedCart;
|
|
1131
|
-
memberSetting?: PlusMemberSettingsMetafields;
|
|
1132
|
-
}) => {
|
|
1133
|
-
attributes: Array<{
|
|
1134
|
-
key: string;
|
|
1135
|
-
value: any;
|
|
1136
|
-
}>;
|
|
1137
|
-
};
|
|
1138
|
-
|
|
1139
|
-
declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
1140
|
-
cart?: NormalizedCart;
|
|
1141
|
-
cartItem: NormalizedLineItem;
|
|
1142
|
-
config: {
|
|
1143
|
-
handle: Record<string, {
|
|
1144
|
-
min: number;
|
|
1145
|
-
max: number;
|
|
1146
|
-
}>;
|
|
1147
|
-
sku: Record<string, {
|
|
1148
|
-
min: number;
|
|
1149
|
-
max: number;
|
|
1150
|
-
}>;
|
|
1151
|
-
};
|
|
1152
|
-
}) => {
|
|
1153
|
-
min: number;
|
|
1154
|
-
max: number;
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
/**
|
|
1158
|
-
* 更新购物车中各个 item 的折后价相关的属性
|
|
1159
|
-
*/
|
|
1160
|
-
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
1161
|
-
cart?: NormalizedCart;
|
|
1162
|
-
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
1163
|
-
isCartLoading: boolean;
|
|
1164
|
-
setLoadingState: React.Dispatch<React.SetStateAction<any>>;
|
|
1165
|
-
metafieldIdentifiers?: {
|
|
1166
|
-
variant: HasMetafieldsIdentifier[];
|
|
1167
|
-
product: HasMetafieldsIdentifier[];
|
|
1168
|
-
};
|
|
1169
|
-
}) => void;
|
|
1170
|
-
|
|
1171
|
-
declare const currencyCodeMapping: Record<string, string>;
|
|
1172
|
-
declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
|
|
1173
|
-
throwOnError?: boolean;
|
|
1174
|
-
};
|
|
1175
|
-
declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
|
|
1176
|
-
declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
|
|
1177
|
-
declare const CODE_AMOUNT_KEY = "_sku_code_money";
|
|
1178
|
-
declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
1179
|
-
declare const MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
|
|
1180
|
-
declare const MAIN_PRODUCT_CODE: string[];
|
|
1181
|
-
|
|
1182
|
-
/**
|
|
1183
|
-
* Normalize AddToCartLineItem[] to NormalizedLineItem[] format
|
|
1184
|
-
* This is used to calculate gifts from lines before they are added to cart
|
|
1185
|
-
*/
|
|
1186
|
-
declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
|
|
1187
|
-
/**
|
|
1188
|
-
* Create a mock cart structure from AddToCartLineItem[]
|
|
1189
|
-
* This is useful for calculating gifts before actual cart operations
|
|
1190
|
-
*/
|
|
1191
|
-
declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
|
|
1192
|
-
|
|
1193
|
-
declare const getQuery: () => Record<string, string>;
|
|
1194
|
-
|
|
1195
|
-
declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
|
|
1196
|
-
declare const safeParse: (str: string) => any;
|
|
1197
|
-
declare const getDiscountEnvAttributeValue: (attributes?: {
|
|
1198
|
-
key: string;
|
|
1199
|
-
value: string;
|
|
1200
|
-
}[]) => any;
|
|
1201
|
-
declare const checkAttributesUpdateNeeded: (oldAttributes: NormalizedAttribute[], newAttributes: NormalizedAttribute[], customAttributesNeedRemove: {
|
|
1202
|
-
key: string;
|
|
1203
|
-
}[]) => boolean;
|
|
1204
|
-
declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
|
|
1205
|
-
declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
|
|
1206
|
-
scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
|
|
1207
|
-
gradient_gifts: any;
|
|
1208
|
-
locale: string;
|
|
1209
|
-
}) => any[];
|
|
1210
|
-
declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
|
|
1211
|
-
locale: string;
|
|
1212
|
-
qualifyingGift?: FormattedGift | null;
|
|
1213
|
-
giftProductsResult?: NormalizedProduct[] | [];
|
|
1214
|
-
}) => any[];
|
|
1215
|
-
|
|
1216
|
-
interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
|
|
1217
|
-
handle?: string;
|
|
1218
|
-
metafieldIdentifiers?: Array<{
|
|
1219
|
-
namespace: string;
|
|
1220
|
-
key: string;
|
|
1221
|
-
}>;
|
|
1222
|
-
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Hook to fetch a single product by handle
|
|
1225
|
-
*
|
|
1226
|
-
* @param options - Hook options including handle and SWR configuration
|
|
1227
|
-
* @returns SWR response with product data
|
|
1063
|
+
* @param options - Price formatting options
|
|
1064
|
+
* @returns Formatted price object
|
|
1228
1065
|
*
|
|
1229
1066
|
* @example
|
|
1230
1067
|
* ```typescript
|
|
1231
|
-
* function
|
|
1232
|
-
* const {
|
|
1233
|
-
*
|
|
1068
|
+
* function ProductPrice({ variant }) {
|
|
1069
|
+
* const { price, basePrice, free } = usePrice({
|
|
1070
|
+
* amount: variant.price.amount,
|
|
1071
|
+
* baseAmount: variant.compareAtPrice?.amount,
|
|
1072
|
+
* currencyCode: variant.price.currencyCode
|
|
1234
1073
|
* })
|
|
1235
1074
|
*
|
|
1236
|
-
* if (isLoading) return <div>Loading...</div>
|
|
1237
|
-
* if (error) return <div>Error loading product</div>
|
|
1238
|
-
* if (!product) return <div>Product not found</div>
|
|
1239
|
-
*
|
|
1240
1075
|
* return (
|
|
1241
1076
|
* <div>
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1077
|
+
* {free ? (
|
|
1078
|
+
* <span>Free</span>
|
|
1079
|
+
* ) : (
|
|
1080
|
+
* <>
|
|
1081
|
+
* <span className="price">{price}</span>
|
|
1082
|
+
* {basePrice && <span className="original">{basePrice}</span>}
|
|
1083
|
+
* </>
|
|
1084
|
+
* )}
|
|
1245
1085
|
* </div>
|
|
1246
1086
|
* )
|
|
1247
1087
|
* }
|
|
1248
1088
|
* ```
|
|
1249
1089
|
*/
|
|
1250
|
-
declare function
|
|
1090
|
+
declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
|
|
1251
1091
|
|
|
1252
|
-
interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
1253
|
-
first?: number;
|
|
1254
|
-
query?: string;
|
|
1255
|
-
sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
|
|
1256
|
-
reverse?: boolean;
|
|
1257
|
-
metafieldIdentifiers?: Array<{
|
|
1258
|
-
namespace: string;
|
|
1259
|
-
key: string;
|
|
1260
|
-
}>;
|
|
1261
|
-
}
|
|
1262
1092
|
/**
|
|
1263
|
-
* Hook
|
|
1093
|
+
* useSelectedOptions Hook
|
|
1264
1094
|
*
|
|
1265
|
-
*
|
|
1266
|
-
|
|
1095
|
+
* Client-side hook to manage selected product options
|
|
1096
|
+
*/
|
|
1097
|
+
|
|
1098
|
+
type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
|
|
1099
|
+
/**
|
|
1100
|
+
* Hook to manage selected product options based on URL query or SKU
|
|
1267
1101
|
*
|
|
1268
|
-
* @param
|
|
1269
|
-
* @
|
|
1102
|
+
* @param product - The product object
|
|
1103
|
+
* @param sku - Optional SKU to match variant
|
|
1104
|
+
* @returns Tuple of [options, setOptions]
|
|
1270
1105
|
*
|
|
1271
1106
|
* @example
|
|
1272
1107
|
* ```typescript
|
|
1273
|
-
* function
|
|
1274
|
-
* const { data:
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
* })
|
|
1108
|
+
* function ProductDetail() {
|
|
1109
|
+
* const { data: product } = useProduct({ handle: 'my-product' })
|
|
1110
|
+
* const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
|
|
1111
|
+
* const variant = useVariant({ product, selectedOptions })
|
|
1278
1112
|
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1113
|
+
* const handleOptionChange = (name: string, value: string) => {
|
|
1114
|
+
* setSelectedOptions(prev => ({ ...prev, [name]: value }))
|
|
1115
|
+
* }
|
|
1281
1116
|
*
|
|
1282
1117
|
* return (
|
|
1283
1118
|
* <div>
|
|
1284
|
-
* {
|
|
1285
|
-
* <
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1119
|
+
* {product?.options.map(option => (
|
|
1120
|
+
* <select
|
|
1121
|
+
* key={option.id}
|
|
1122
|
+
* value={selectedOptions[option.name] || ''}
|
|
1123
|
+
* onChange={(e) => handleOptionChange(option.name, e.target.value)}
|
|
1124
|
+
* >
|
|
1125
|
+
* {option.values.map(value => (
|
|
1126
|
+
* <option key={value.label} value={value.label}>
|
|
1127
|
+
* {value.label}
|
|
1128
|
+
* </option>
|
|
1129
|
+
* ))}
|
|
1130
|
+
* </select>
|
|
1289
1131
|
* ))}
|
|
1132
|
+
* <p>Selected: {variant?.title}</p>
|
|
1290
1133
|
* </div>
|
|
1291
1134
|
* )
|
|
1292
1135
|
* }
|
|
1293
1136
|
* ```
|
|
1294
1137
|
*/
|
|
1295
|
-
declare function
|
|
1138
|
+
declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
|
|
1296
1139
|
|
|
1297
|
-
interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
|
|
1298
|
-
handles?: string[];
|
|
1299
|
-
metafieldIdentifiers?: {
|
|
1300
|
-
product: HasMetafieldsIdentifier[];
|
|
1301
|
-
variant: HasMetafieldsIdentifier[];
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
1140
|
/**
|
|
1305
|
-
* Hook
|
|
1141
|
+
* useProductUrl Hook
|
|
1306
1142
|
*
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1143
|
+
* Hook to generate product URLs with variant query params
|
|
1144
|
+
* Requires routerAdapter to be configured in ShopifyProvider
|
|
1145
|
+
*/
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Hook to generate product URLs
|
|
1149
|
+
*
|
|
1150
|
+
* @param otherQuery - Additional query parameters to include
|
|
1151
|
+
* @returns Function to generate product URL
|
|
1309
1152
|
*
|
|
1310
1153
|
* @example
|
|
1311
1154
|
* ```typescript
|
|
1312
|
-
* function
|
|
1313
|
-
* const
|
|
1314
|
-
* handles: ['product-1', 'product-2', 'product-3']
|
|
1315
|
-
* })
|
|
1155
|
+
* function ProductCard({ product, variant }) {
|
|
1156
|
+
* const getProductUrl = useProductUrl()
|
|
1316
1157
|
*
|
|
1317
|
-
*
|
|
1318
|
-
* if (error) return <div>Error loading products</div>
|
|
1158
|
+
* const url = getProductUrl({ product, variant })
|
|
1319
1159
|
*
|
|
1320
1160
|
* return (
|
|
1321
|
-
* <
|
|
1322
|
-
* {
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1325
|
-
* <p>${product.price.amount}</p>
|
|
1326
|
-
* </div>
|
|
1327
|
-
* ))}
|
|
1328
|
-
* </div>
|
|
1161
|
+
* <a href={url}>
|
|
1162
|
+
* <h2>{product.title}</h2>
|
|
1163
|
+
* <p>{variant.title}</p>
|
|
1164
|
+
* </a>
|
|
1329
1165
|
* )
|
|
1330
1166
|
* }
|
|
1331
1167
|
* ```
|
|
1168
|
+
*
|
|
1169
|
+
* @example With additional query params
|
|
1170
|
+
* ```typescript
|
|
1171
|
+
* function ProductCard({ product, variant }) {
|
|
1172
|
+
* const getProductUrl = useProductUrl({ utm_source: 'email' })
|
|
1173
|
+
*
|
|
1174
|
+
* const url = getProductUrl({ product, variant })
|
|
1175
|
+
* // URL will include: ?variant=123&utm_source=email
|
|
1176
|
+
*
|
|
1177
|
+
* return <a href={url}>{product.title}</a>
|
|
1178
|
+
* }
|
|
1179
|
+
* ```
|
|
1332
1180
|
*/
|
|
1333
|
-
declare function
|
|
1181
|
+
declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
|
|
1182
|
+
product?: NormalizedProduct;
|
|
1183
|
+
variant?: NormalizedProductVariant;
|
|
1184
|
+
}) => string;
|
|
1334
1185
|
|
|
1335
1186
|
/**
|
|
1336
|
-
*
|
|
1187
|
+
* useUpdateVariantQuery Hook
|
|
1337
1188
|
*
|
|
1338
|
-
*
|
|
1339
|
-
*/
|
|
1340
|
-
|
|
1341
|
-
type Options = Record<string, string>;
|
|
1342
|
-
/**
|
|
1343
|
-
* Hook to manage variant selection based on selected options
|
|
1344
|
-
*
|
|
1345
|
-
* @param product - The product object
|
|
1346
|
-
* @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
|
|
1347
|
-
* @returns The matching variant
|
|
1348
|
-
*
|
|
1349
|
-
* @example
|
|
1350
|
-
* ```typescript
|
|
1351
|
-
* function ProductDetail() {
|
|
1352
|
-
* const { data: product } = useProduct({ handle: 'my-product' })
|
|
1353
|
-
* const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
|
|
1354
|
-
* const variant = useVariant({ product, selectedOptions })
|
|
1355
|
-
*
|
|
1356
|
-
* return (
|
|
1357
|
-
* <div>
|
|
1358
|
-
* <h1>{product.title}</h1>
|
|
1359
|
-
* <p>Selected: {variant.title}</p>
|
|
1360
|
-
* <p>Price: ${variant.price.amount}</p>
|
|
1361
|
-
* <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
|
|
1362
|
-
* </div>
|
|
1363
|
-
* )
|
|
1364
|
-
* }
|
|
1365
|
-
* ```
|
|
1366
|
-
*/
|
|
1367
|
-
declare function useVariant({ product, selectedOptions, }: {
|
|
1368
|
-
product?: NormalizedProduct;
|
|
1369
|
-
selectedOptions: Options;
|
|
1370
|
-
}): NormalizedProductVariant | undefined;
|
|
1371
|
-
|
|
1372
|
-
/**
|
|
1373
|
-
* usePrice Hook
|
|
1374
|
-
*
|
|
1375
|
-
* Client-side hook to format price for display
|
|
1376
|
-
*/
|
|
1377
|
-
interface UsePriceOptions {
|
|
1378
|
-
amount: number;
|
|
1379
|
-
baseAmount?: number;
|
|
1380
|
-
currencyCode: string;
|
|
1381
|
-
soldOutDescription?: string;
|
|
1382
|
-
maximumFractionDigits?: number;
|
|
1383
|
-
minimumFractionDigits?: number;
|
|
1384
|
-
removeTrailingZeros?: boolean;
|
|
1385
|
-
}
|
|
1386
|
-
interface UsePriceResult {
|
|
1387
|
-
price: string;
|
|
1388
|
-
basePrice?: string;
|
|
1389
|
-
free: boolean;
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Hook to format price for display
|
|
1393
|
-
*
|
|
1394
|
-
* @param options - Price formatting options
|
|
1395
|
-
* @returns Formatted price object
|
|
1396
|
-
*
|
|
1397
|
-
* @example
|
|
1398
|
-
* ```typescript
|
|
1399
|
-
* function ProductPrice({ variant }) {
|
|
1400
|
-
* const { price, basePrice, free } = usePrice({
|
|
1401
|
-
* amount: variant.price.amount,
|
|
1402
|
-
* baseAmount: variant.compareAtPrice?.amount,
|
|
1403
|
-
* currencyCode: variant.price.currencyCode
|
|
1404
|
-
* })
|
|
1405
|
-
*
|
|
1406
|
-
* return (
|
|
1407
|
-
* <div>
|
|
1408
|
-
* {free ? (
|
|
1409
|
-
* <span>Free</span>
|
|
1410
|
-
* ) : (
|
|
1411
|
-
* <>
|
|
1412
|
-
* <span className="price">{price}</span>
|
|
1413
|
-
* {basePrice && <span className="original">{basePrice}</span>}
|
|
1414
|
-
* </>
|
|
1415
|
-
* )}
|
|
1416
|
-
* </div>
|
|
1417
|
-
* )
|
|
1418
|
-
* }
|
|
1419
|
-
* ```
|
|
1420
|
-
*/
|
|
1421
|
-
declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
|
|
1422
|
-
|
|
1423
|
-
/**
|
|
1424
|
-
* useSelectedOptions Hook
|
|
1425
|
-
*
|
|
1426
|
-
* Client-side hook to manage selected product options
|
|
1427
|
-
*/
|
|
1428
|
-
|
|
1429
|
-
type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
|
|
1430
|
-
/**
|
|
1431
|
-
* Hook to manage selected product options based on URL query or SKU
|
|
1432
|
-
*
|
|
1433
|
-
* @param product - The product object
|
|
1434
|
-
* @param sku - Optional SKU to match variant
|
|
1435
|
-
* @returns Tuple of [options, setOptions]
|
|
1436
|
-
*
|
|
1437
|
-
* @example
|
|
1438
|
-
* ```typescript
|
|
1439
|
-
* function ProductDetail() {
|
|
1440
|
-
* const { data: product } = useProduct({ handle: 'my-product' })
|
|
1441
|
-
* const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
|
|
1442
|
-
* const variant = useVariant({ product, selectedOptions })
|
|
1443
|
-
*
|
|
1444
|
-
* const handleOptionChange = (name: string, value: string) => {
|
|
1445
|
-
* setSelectedOptions(prev => ({ ...prev, [name]: value }))
|
|
1446
|
-
* }
|
|
1447
|
-
*
|
|
1448
|
-
* return (
|
|
1449
|
-
* <div>
|
|
1450
|
-
* {product?.options.map(option => (
|
|
1451
|
-
* <select
|
|
1452
|
-
* key={option.id}
|
|
1453
|
-
* value={selectedOptions[option.name] || ''}
|
|
1454
|
-
* onChange={(e) => handleOptionChange(option.name, e.target.value)}
|
|
1455
|
-
* >
|
|
1456
|
-
* {option.values.map(value => (
|
|
1457
|
-
* <option key={value.label} value={value.label}>
|
|
1458
|
-
* {value.label}
|
|
1459
|
-
* </option>
|
|
1460
|
-
* ))}
|
|
1461
|
-
* </select>
|
|
1462
|
-
* ))}
|
|
1463
|
-
* <p>Selected: {variant?.title}</p>
|
|
1464
|
-
* </div>
|
|
1465
|
-
* )
|
|
1466
|
-
* }
|
|
1467
|
-
* ```
|
|
1468
|
-
*/
|
|
1469
|
-
declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
|
|
1470
|
-
|
|
1471
|
-
/**
|
|
1472
|
-
* useProductUrl Hook
|
|
1473
|
-
*
|
|
1474
|
-
* Hook to generate product URLs with variant query params
|
|
1475
|
-
* Requires routerAdapter to be configured in ShopifyProvider
|
|
1476
|
-
*/
|
|
1477
|
-
|
|
1478
|
-
/**
|
|
1479
|
-
* Hook to generate product URLs
|
|
1480
|
-
*
|
|
1481
|
-
* @param otherQuery - Additional query parameters to include
|
|
1482
|
-
* @returns Function to generate product URL
|
|
1483
|
-
*
|
|
1484
|
-
* @example
|
|
1485
|
-
* ```typescript
|
|
1486
|
-
* function ProductCard({ product, variant }) {
|
|
1487
|
-
* const getProductUrl = useProductUrl()
|
|
1488
|
-
*
|
|
1489
|
-
* const url = getProductUrl({ product, variant })
|
|
1490
|
-
*
|
|
1491
|
-
* return (
|
|
1492
|
-
* <a href={url}>
|
|
1493
|
-
* <h2>{product.title}</h2>
|
|
1494
|
-
* <p>{variant.title}</p>
|
|
1495
|
-
* </a>
|
|
1496
|
-
* )
|
|
1497
|
-
* }
|
|
1498
|
-
* ```
|
|
1499
|
-
*
|
|
1500
|
-
* @example With additional query params
|
|
1501
|
-
* ```typescript
|
|
1502
|
-
* function ProductCard({ product, variant }) {
|
|
1503
|
-
* const getProductUrl = useProductUrl({ utm_source: 'email' })
|
|
1504
|
-
*
|
|
1505
|
-
* const url = getProductUrl({ product, variant })
|
|
1506
|
-
* // URL will include: ?variant=123&utm_source=email
|
|
1507
|
-
*
|
|
1508
|
-
* return <a href={url}>{product.title}</a>
|
|
1509
|
-
* }
|
|
1510
|
-
* ```
|
|
1511
|
-
*/
|
|
1512
|
-
declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
|
|
1513
|
-
product?: NormalizedProduct;
|
|
1514
|
-
variant?: NormalizedProductVariant;
|
|
1515
|
-
}) => string;
|
|
1516
|
-
|
|
1517
|
-
/**
|
|
1518
|
-
* useUpdateVariantQuery Hook
|
|
1519
|
-
*
|
|
1520
|
-
* Hook to automatically update URL query string when variant changes
|
|
1189
|
+
* Hook to automatically update URL query string when variant changes
|
|
1521
1190
|
*/
|
|
1522
1191
|
|
|
1523
1192
|
/**
|
|
@@ -1752,6 +1421,334 @@ interface UseSiteOptions extends SWRConfiguration<SiteInfo | undefined> {
|
|
|
1752
1421
|
}
|
|
1753
1422
|
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>;
|
|
1754
1423
|
|
|
1424
|
+
interface ShippingMethodsContext {
|
|
1425
|
+
freeShippingMethods: PlusMemberShippingMethodConfig[];
|
|
1426
|
+
paymentShippingMethods: PlusMemberShippingMethodConfig[];
|
|
1427
|
+
nddOverweight: boolean;
|
|
1428
|
+
tddOverweight: boolean;
|
|
1429
|
+
nddCoupon?: string;
|
|
1430
|
+
tddCoupon?: string;
|
|
1431
|
+
isLoadingCoupon: boolean;
|
|
1432
|
+
}
|
|
1433
|
+
interface PlusMemberContextValue<TProduct = any, TVariant = any, TProfile extends {
|
|
1434
|
+
isPlus?: boolean;
|
|
1435
|
+
} = any> {
|
|
1436
|
+
plusMemberMetafields: PlusMemberSettingsMetafields;
|
|
1437
|
+
selectedPlusMemberMode: DeliveryPlusType;
|
|
1438
|
+
setSelectedPlusMemberMode: (value: DeliveryPlusType) => void;
|
|
1439
|
+
selectedShippingMethod?: PlusMemberShippingMethodConfig;
|
|
1440
|
+
setSelectedShippingMethod: (value: PlusMemberShippingMethodConfig) => void;
|
|
1441
|
+
showMoreShippingMethod: boolean;
|
|
1442
|
+
setShowMoreShippingMethod: (value: boolean) => void;
|
|
1443
|
+
variant: TVariant;
|
|
1444
|
+
product: TProduct;
|
|
1445
|
+
shippingMethodsContext: ShippingMethodsContext;
|
|
1446
|
+
selectedPlusMemberVariant: SelectedPlusMemberVariant;
|
|
1447
|
+
showPlusMemberBenefit: boolean;
|
|
1448
|
+
setShowPlusMemberBenefit: (value: boolean) => void;
|
|
1449
|
+
profile?: TProfile;
|
|
1450
|
+
}
|
|
1451
|
+
declare const PlusMemberContext: React$1.Context<PlusMemberContextValue<any, any, any>>;
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* Hook to access Plus Member Context
|
|
1455
|
+
*/
|
|
1456
|
+
declare function usePlusMemberContext<TProfile extends {
|
|
1457
|
+
isPlus?: boolean;
|
|
1458
|
+
} = any>(): PlusMemberContextValue<any, any, any>;
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Hook to get Plus Member Product Variants (Monthly and Annual)
|
|
1462
|
+
*/
|
|
1463
|
+
|
|
1464
|
+
interface UsePlusMemberVariantsOptions {
|
|
1465
|
+
/** Plus member metafields configuration */
|
|
1466
|
+
memberSetting: PlusMemberSettingsMetafields;
|
|
1467
|
+
}
|
|
1468
|
+
interface UsePlusMemberVariantsResult {
|
|
1469
|
+
monthlyVariant?: NormalizedProductVariant & {
|
|
1470
|
+
product: NormalizedProduct | undefined;
|
|
1471
|
+
};
|
|
1472
|
+
annualVariant?: NormalizedProductVariant & {
|
|
1473
|
+
product: NormalizedProduct | undefined;
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Get Plus Member product variants (monthly and annual)
|
|
1478
|
+
*
|
|
1479
|
+
* @param options - Configuration options
|
|
1480
|
+
* @returns Monthly and annual variants
|
|
1481
|
+
*
|
|
1482
|
+
* @example
|
|
1483
|
+
* ```tsx
|
|
1484
|
+
* const { monthlyVariant, annualVariant } = usePlusMemberVariants({
|
|
1485
|
+
* plusMemberMetafields
|
|
1486
|
+
* })
|
|
1487
|
+
* ```
|
|
1488
|
+
*/
|
|
1489
|
+
declare function usePlusMemberVariants({ memberSetting, }: UsePlusMemberVariantsOptions): UsePlusMemberVariantsResult;
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Hook to calculate available shipping methods based on product weight and member status
|
|
1493
|
+
*/
|
|
1494
|
+
|
|
1495
|
+
interface UseShippingMethodsOptions<TVariant = any, TProfile extends {
|
|
1496
|
+
isPlus?: boolean;
|
|
1497
|
+
} = any> {
|
|
1498
|
+
/** Product variant with weight information */
|
|
1499
|
+
variant: TVariant;
|
|
1500
|
+
/** Plus member metafields configuration */
|
|
1501
|
+
plusMemberMetafields: PlusMemberSettingsMetafields;
|
|
1502
|
+
/** Selected plus member mode */
|
|
1503
|
+
selectedPlusMemberMode: DeliveryPlusType;
|
|
1504
|
+
profile?: TProfile;
|
|
1505
|
+
}
|
|
1506
|
+
interface UseShippingMethodsResult {
|
|
1507
|
+
freeShippingMethods: PlusMemberShippingMethodConfig[];
|
|
1508
|
+
paymentShippingMethods: PlusMemberShippingMethodConfig[];
|
|
1509
|
+
nddOverweight: boolean;
|
|
1510
|
+
tddOverweight: boolean;
|
|
1511
|
+
nddCoupon?: string;
|
|
1512
|
+
tddCoupon?: string;
|
|
1513
|
+
isLoadingCoupon: boolean;
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Calculate available shipping methods based on product weight, member status, and available coupons
|
|
1517
|
+
*
|
|
1518
|
+
* @param options - Configuration options
|
|
1519
|
+
* @returns Shipping methods categorized by free/payment and overweight status
|
|
1520
|
+
*
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```tsx
|
|
1523
|
+
* const { freeShippingMethods, paymentShippingMethods, nddOverweight, tddOverweight } = useShippingMethods({
|
|
1524
|
+
* variant,
|
|
1525
|
+
* plusMemberMetafields,
|
|
1526
|
+
* selectedPlusMemberMode,
|
|
1527
|
+
* })
|
|
1528
|
+
* ```
|
|
1529
|
+
*/
|
|
1530
|
+
declare function useShippingMethods<TVariant extends {
|
|
1531
|
+
weight?: number;
|
|
1532
|
+
} = any>(options: UseShippingMethodsOptions<TVariant>): UseShippingMethodsResult;
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Hook to replace cart plus member product
|
|
1536
|
+
*
|
|
1537
|
+
* When adding a monthly membership while an annual membership exists in cart,
|
|
1538
|
+
* the annual membership will be replaced and vice versa.
|
|
1539
|
+
*
|
|
1540
|
+
* @returns Handler function to replace conflicting membership products
|
|
1541
|
+
*
|
|
1542
|
+
* @example
|
|
1543
|
+
* ```tsx
|
|
1544
|
+
* const replaceCartPlusMember = useReplaceCartPlusMember()
|
|
1545
|
+
*
|
|
1546
|
+
* // Call before adding new membership product
|
|
1547
|
+
* await replaceCartPlusMember()
|
|
1548
|
+
* ```
|
|
1549
|
+
*/
|
|
1550
|
+
declare const useReplaceCartPlusMember: () => () => Promise<void>;
|
|
1551
|
+
|
|
1552
|
+
declare const usePlusMemberCheckoutCustomAttributes: ({ disableShipping, isPresaleContains, }: {
|
|
1553
|
+
disableShipping?: boolean;
|
|
1554
|
+
isPresaleContains?: boolean;
|
|
1555
|
+
}) => NormalizedAttribute[];
|
|
1556
|
+
|
|
1557
|
+
/**
|
|
1558
|
+
* useAutoRemovePlusMemberInCart Hook
|
|
1559
|
+
* 付费会员身份自动移除购物车中的会员产品
|
|
1560
|
+
* 年费会员删除月费会员产品,月费会员删除年费会员产品
|
|
1561
|
+
*/
|
|
1562
|
+
|
|
1563
|
+
interface UseAutoRemovePlusMemberInCartProps {
|
|
1564
|
+
profile: any;
|
|
1565
|
+
cart?: NormalizedCart;
|
|
1566
|
+
memberSetting: PlusMemberSettingsMetafields;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* 自动移除购物车中的会员产品
|
|
1570
|
+
*
|
|
1571
|
+
* @param props - Hook 参数
|
|
1572
|
+
* @param props.memberSetting - Plus Member 配置
|
|
1573
|
+
* @param props.isMonthlyPlus - 用户是否是月费会员
|
|
1574
|
+
* @param props.isAnnualPlus - 用户是否是年费会员
|
|
1575
|
+
*
|
|
1576
|
+
* @example
|
|
1577
|
+
* ```tsx
|
|
1578
|
+
* const { profile } = useProfile()
|
|
1579
|
+
*
|
|
1580
|
+
* useAutoRemovePlusMemberInCart({
|
|
1581
|
+
* cart,
|
|
1582
|
+
* profile,
|
|
1583
|
+
* })
|
|
1584
|
+
* ```
|
|
1585
|
+
*/
|
|
1586
|
+
declare function useAutoRemovePlusMemberInCart({ cart, profile, memberSetting, }: UseAutoRemovePlusMemberInCartProps): void;
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Has Plus Member In Cart
|
|
1590
|
+
* 判断购物车中是否包含年费会员或月费会员产品
|
|
1591
|
+
*/
|
|
1592
|
+
|
|
1593
|
+
interface HasPlusMemberInCartProps {
|
|
1594
|
+
/** Plus Member 配置 */
|
|
1595
|
+
memberSetting?: PlusMemberSettingsMetafields;
|
|
1596
|
+
/** 购物车数据 */
|
|
1597
|
+
cart?: NormalizedCart;
|
|
1598
|
+
}
|
|
1599
|
+
interface HasPlusMemberInCartResult {
|
|
1600
|
+
/** 购物车中是否有任何会员产品 */
|
|
1601
|
+
hasPlusMember: boolean;
|
|
1602
|
+
/** 购物车中是否有月费会员产品 */
|
|
1603
|
+
hasMonthlyPlus: boolean;
|
|
1604
|
+
/** 购物车中是否有年费会员产品 */
|
|
1605
|
+
hasAnnualPlus: boolean;
|
|
1606
|
+
/** 月费会员产品的 line item */
|
|
1607
|
+
monthlyPlusItem?: {
|
|
1608
|
+
id: string;
|
|
1609
|
+
quantity: number;
|
|
1610
|
+
handle?: string;
|
|
1611
|
+
sku?: string;
|
|
1612
|
+
};
|
|
1613
|
+
/** 年费会员产品的 line item */
|
|
1614
|
+
annualPlusItem?: {
|
|
1615
|
+
id: string;
|
|
1616
|
+
quantity: number;
|
|
1617
|
+
handle?: string;
|
|
1618
|
+
sku?: string;
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* 判断购物车中是否包含年费会员或月费会员产品(纯函数版本)
|
|
1623
|
+
*
|
|
1624
|
+
* @param props - 函数参数
|
|
1625
|
+
* @param props.memberSetting - Plus Member 配置
|
|
1626
|
+
* @param props.cart - 购物车数据
|
|
1627
|
+
* @returns 会员产品信息
|
|
1628
|
+
*
|
|
1629
|
+
* @example
|
|
1630
|
+
* ```tsx
|
|
1631
|
+
* const {
|
|
1632
|
+
* hasPlusMember,
|
|
1633
|
+
* hasMonthlyPlus,
|
|
1634
|
+
* hasAnnualPlus,
|
|
1635
|
+
* monthlyPlusItem,
|
|
1636
|
+
* annualPlusItem,
|
|
1637
|
+
* } = hasPlusMemberInCart({
|
|
1638
|
+
* memberSetting: plusMemberSettings,
|
|
1639
|
+
* cart: currentCart,
|
|
1640
|
+
* })
|
|
1641
|
+
*
|
|
1642
|
+
* if (hasPlusMember) {
|
|
1643
|
+
* console.log('购物车中有会员产品')
|
|
1644
|
+
* }
|
|
1645
|
+
* ```
|
|
1646
|
+
*/
|
|
1647
|
+
declare function hasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
|
|
1648
|
+
/**
|
|
1649
|
+
* 判断购物车中是否包含年费会员或月费会员产品(Hook 版本)
|
|
1650
|
+
*
|
|
1651
|
+
* 内部使用 hasPlusMemberInCart 纯函数,并通过 useMemo 优化性能
|
|
1652
|
+
*
|
|
1653
|
+
* @param props - Hook 参数
|
|
1654
|
+
* @param props.memberSetting - Plus Member 配置
|
|
1655
|
+
* @param props.cart - 购物车数据
|
|
1656
|
+
* @returns 会员产品信息
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```tsx
|
|
1660
|
+
* const {
|
|
1661
|
+
* hasPlusMember,
|
|
1662
|
+
* hasMonthlyPlus,
|
|
1663
|
+
* hasAnnualPlus,
|
|
1664
|
+
* monthlyPlusItem,
|
|
1665
|
+
* annualPlusItem,
|
|
1666
|
+
* } = useHasPlusMemberInCart({
|
|
1667
|
+
* memberSetting: plusMemberSettings,
|
|
1668
|
+
* cart: currentCart,
|
|
1669
|
+
* })
|
|
1670
|
+
*
|
|
1671
|
+
* if (hasPlusMember) {
|
|
1672
|
+
* console.log('购物车中有会员产品')
|
|
1673
|
+
* }
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
declare function useHasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
|
|
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
|
+
|
|
1755
1752
|
/**
|
|
1756
1753
|
* useIntersection Hook
|
|
1757
1754
|
*
|
|
@@ -1987,4 +1984,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1987
1984
|
*/
|
|
1988
1985
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1989
1986
|
|
|
1990
|
-
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,
|
|
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 };
|