@anker-in/shopify-react 0.1.1-beta.0 → 0.1.1-beta.1
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 +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +33 -76
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +33 -76
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-BUWkkUdh.d.ts → index-CCMIeIUh.d.ts} +5 -91
- package/dist/{index-DenyuVGJ.d.mts → index-RevQokdZ.d.mts} +5 -91
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -81
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +2 -1
- package/dist/provider/index.d.ts +2 -1
- package/dist/{types-CMA6_FML.d.mts → types-CICUnw0v.d.mts} +85 -76
- package/dist/{types-CMA6_FML.d.ts → types-CICUnw0v.d.ts} +85 -76
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as swr_mutation from 'swr/mutation';
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
|
-
import { CartLineInput as CartLineInput$1, NormalizedCart,
|
|
4
|
-
import { G as GtmParams, B as BuyNowTrackConfig,
|
|
3
|
+
import { CartLineInput as CartLineInput$1, NormalizedCart, UpdateCartLinesOptions, HasMetafieldsIdentifier, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle } from '@anker-in/shopify-sdk';
|
|
4
|
+
import { A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, d as PlusMemberShippingMethodConfig, e as PlusMemberSettingsMetafields, D as DeliveryPlusType, f as SelectedPlusMemberProduct, i as DeliveryData } from './types-CICUnw0v.js';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
6
|
import * as swr from 'swr';
|
|
7
7
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
@@ -90,79 +90,6 @@ interface AddCartLinesInput {
|
|
|
90
90
|
*/
|
|
91
91
|
declare function useAddCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'add-cart-lines', AddCartLinesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "add-cart-lines", AddCartLinesInput>;
|
|
92
92
|
|
|
93
|
-
interface AddToCartInput {
|
|
94
|
-
/** Lines to add */
|
|
95
|
-
lineItems: Array<{
|
|
96
|
-
variant?: NormalizedProductVariant;
|
|
97
|
-
finalPrice?: MoneyV2;
|
|
98
|
-
sellingPlanId?: string;
|
|
99
|
-
quantity?: number;
|
|
100
|
-
attributes?: Array<{
|
|
101
|
-
key: string;
|
|
102
|
-
value: string;
|
|
103
|
-
}>;
|
|
104
|
-
}>;
|
|
105
|
-
/** Cart ID (optional) */
|
|
106
|
-
cartId?: string;
|
|
107
|
-
/** Discount codes to apply */
|
|
108
|
-
discountCodes?: string[];
|
|
109
|
-
/** Custom attributes for the cart */
|
|
110
|
-
customAttributes?: Array<{
|
|
111
|
-
key: string;
|
|
112
|
-
value: string;
|
|
113
|
-
}>;
|
|
114
|
-
/** 全量更新 codes,默认是追加 */
|
|
115
|
-
replaceExistingCodes?: boolean;
|
|
116
|
-
/** Buyer identity for cart creation */
|
|
117
|
-
buyerIdentity?: {
|
|
118
|
-
email?: string;
|
|
119
|
-
countryCode?: string;
|
|
120
|
-
};
|
|
121
|
-
/** GTM tracking parameters */
|
|
122
|
-
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
123
|
-
/** Force create new cart */
|
|
124
|
-
needCreateCart?: boolean;
|
|
125
|
-
/** Callback when discount codes are invalid */
|
|
126
|
-
onCodesInvalid?: (updatedCart: NormalizedCart, invalidCodes: string[]) => Promise<NormalizedCart | undefined>;
|
|
127
|
-
}
|
|
128
|
-
interface UseAddToCartOptions {
|
|
129
|
-
/** Enable tracking (GA and FBQ) */
|
|
130
|
-
withTrack?: boolean;
|
|
131
|
-
/** Brand name for tracking */
|
|
132
|
-
brand?: string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Hook for adding items to cart with tracking support
|
|
136
|
-
*
|
|
137
|
-
* This is the enhanced version that includes:
|
|
138
|
-
* - Automatic cart creation if needed
|
|
139
|
-
* - Discount code validation
|
|
140
|
-
* - Google Analytics tracking
|
|
141
|
-
* - Facebook Pixel tracking
|
|
142
|
-
* - Invalid code handling
|
|
143
|
-
*
|
|
144
|
-
* @param options - Hook configuration
|
|
145
|
-
* @param swrOptions - SWR mutation configuration
|
|
146
|
-
* @returns SWR mutation with trigger function
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```tsx
|
|
150
|
-
* const { trigger, isMutating } = useAddToCart({ withTrack: true, brand: 'Anker' })
|
|
151
|
-
*
|
|
152
|
-
* await trigger({
|
|
153
|
-
* lineItems: [{
|
|
154
|
-
* variantId: 'gid://shopify/ProductVariant/123',
|
|
155
|
-
* quantity: 2
|
|
156
|
-
* }],
|
|
157
|
-
* gtmParams: {
|
|
158
|
-
* pageGroup: 'PDP',
|
|
159
|
-
* position: 'Add to Cart Button'
|
|
160
|
-
* }
|
|
161
|
-
* })
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
declare function useAddToCart({ withTrack, brand }?: UseAddToCartOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, AddToCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, AddToCartInput>;
|
|
165
|
-
|
|
166
93
|
/**
|
|
167
94
|
* Hook for updating cart line quantities
|
|
168
95
|
*
|
|
@@ -307,17 +234,7 @@ interface BuyNowInput {
|
|
|
307
234
|
product: HasMetafieldsIdentifier[];
|
|
308
235
|
};
|
|
309
236
|
/** Line items to add to the new cart */
|
|
310
|
-
lineItems: Array<
|
|
311
|
-
variant?: {
|
|
312
|
-
id: string;
|
|
313
|
-
};
|
|
314
|
-
variantId?: string;
|
|
315
|
-
quantity?: number;
|
|
316
|
-
attributes?: Array<{
|
|
317
|
-
key: string;
|
|
318
|
-
value: string;
|
|
319
|
-
}>;
|
|
320
|
-
}>;
|
|
237
|
+
lineItems: Array<AddToCartLineItem>;
|
|
321
238
|
/** Discount codes to apply */
|
|
322
239
|
discountCodes?: string[];
|
|
323
240
|
/** Custom attributes for the cart */
|
|
@@ -340,8 +257,6 @@ interface BuyNowInput {
|
|
|
340
257
|
interface UseBuyNowOptions {
|
|
341
258
|
/** Enable tracking (GA and FBQ) */
|
|
342
259
|
withTrack?: boolean;
|
|
343
|
-
/** Brand name for tracking */
|
|
344
|
-
brand?: string;
|
|
345
260
|
}
|
|
346
261
|
/**
|
|
347
262
|
* Hook for buy now functionality
|
|
@@ -358,7 +273,6 @@ interface UseBuyNowOptions {
|
|
|
358
273
|
* const { trigger, isMutating } = useBuyNow({
|
|
359
274
|
* withTrack: true,
|
|
360
275
|
* redirectToCheckout: true,
|
|
361
|
-
* brand: 'Anker'
|
|
362
276
|
* })
|
|
363
277
|
*
|
|
364
278
|
* await trigger({
|
|
@@ -373,7 +287,7 @@ interface UseBuyNowOptions {
|
|
|
373
287
|
* })
|
|
374
288
|
* ```
|
|
375
289
|
*/
|
|
376
|
-
declare function useBuyNow({ withTrack
|
|
290
|
+
declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, BuyNowInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, BuyNowInput>;
|
|
377
291
|
|
|
378
292
|
type AutoFreeGift = {
|
|
379
293
|
currentTier: {
|
|
@@ -1933,4 +1847,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1933
1847
|
*/
|
|
1934
1848
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1935
1849
|
|
|
1936
|
-
export {
|
|
1850
|
+
export { defaultSWRMutationConfiguration as $, type AddCartLinesInput as A, type BuyNowInput as B, type CreateCartInput as C, type DiscountLabel as D, type GiftProductItem as E, RuleType as F, type GiftProduct as G, BuyRuleType as H, type FunctionGiftResult as I, type FormattedGift as J, type CartLineInput as K, type AutoFreeGiftItem as L, type MainProductInfo as M, type AutoFreeGiftList as N, type OrderDiscountResult as O, OrderDiscountType as P, OrderBasePriceType as Q, type RemoveCartLinesInput as R, SpendMoneyType as S, type TieredDiscount as T, type UpdateCartAttributesInput as U, type VariantItem as V, type OrderDiscountConfig as W, PriceDiscountType as X, PriceBasePriceType as Y, type PriceDiscountConfig as Z, currencyCodeMapping as _, useAddCartLines as a, usePlusAnnualProductVariant as a$, CUSTOMER_ATTRIBUTE_KEY as a0, CUSTOMER_SCRIPT_GIFT_KEY as a1, CODE_AMOUNT_KEY as a2, SCRIPT_CODE_AMOUNT_KEY as a3, MAIN_PRODUCT_CODE as a4, getQuery as a5, atobID as a6, btoaID as a7, getMatchedMainProductSubTotal as a8, getDiscountEnvAttributeValue as a9, type UseAllCollectionsOptions as aA, useAllCollections as aB, type UseCollectionsOptions as aC, useCollections as aD, type UseBlogOptions as aE, useBlog as aF, type UseAllBlogsOptions as aG, useAllBlogs as aH, type UseArticleOptions as aI, useArticle as aJ, type UseArticlesOptions as aK, useArticles as aL, type UseArticlesInBlogOptions as aM, useArticlesInBlog as aN, type SearchResultType as aO, type SearchResultItem as aP, type SearchResult as aQ, type UseSearchOptions as aR, useSearch as aS, type SiteInfo as aT, type UseSiteOptions as aU, useSite as aV, type ShippingMethodsContext as aW, type PlusMemberContextValue as aX, PlusMemberContext as aY, usePlusMemberContext as aZ, usePlusMonthlyProductVariant as a_, isAttributesEqual as aa, safeParseJson as ab, preCheck as ac, formatScriptAutoFreeGift as ad, formatFunctionAutoFreeGift as ae, useSelectedOptions as af, type SelectedOptionsResult as ag, type UseProductOptions as ah, useProduct as ai, type UseAllProductsOptions as aj, useAllProducts as ak, type UseProductsByHandlesOptions as al, useProductsByHandles as am, type Options as an, useVariant as ao, type UsePriceOptions as ap, type UsePriceResult as aq, usePrice as ar, useProductUrl as as, useUpdateVariantQuery as at, type ImageMedia as au, type VideoMedia as av, type VariantMedia as aw, useVariantMedia as ax, type UseCollectionOptions as ay, useCollection as az, useUpdateCartLines as b, type UseShippingMethodsOptions as b0, type UseShippingMethodsResult as b1, useShippingMethods as b2, useShippingMethodAvailableCheck as b3, useReplaceCartPlusMember as b4, usePlusMemberDeliveryCodes as b5, usePlusMemberItemCustomAttributes as b6, type CustomerOrder as b7, type Customer as b8, usePlusMemberCheckoutCustomAttributes as b9, type ExportCart as bA, type UseAutoRemovePlusMemberInCartProps as ba, useAutoRemovePlusMemberInCart as bb, type UseHasPlusMemberInCartProps as bc, type HasPlusMemberInCartResult as bd, useHasPlusMemberInCart as be, type PlusMemberProviderProps as bf, PlusMemberProvider as bg, type UseIntersectionOptions as bh, useIntersection as bi, type UseExposureOptions as bj, useExposure as bk, type GeoLocationData as bl, type LocaleMapping as bm, type UseGeoLocationOptions as bn, useGeoLocation as bo, getCachedGeoLocation as bp, clearGeoLocationCache as bq, type Attribute as br, type Discount as bs, type Image as bt, type Measurement as bu, type ExportSelectedOption as bv, type ExportProductVariant as bw, type ExportDiscountAllocations as bx, type ExportLineItem as by, type ExportDiscounts as bz, useRemoveCartLines as c, type ApplyCartCodesInput as d, useApplyCartCodes as e, type RemoveCartCodesInput as f, useRemoveCartCodes as g, useUpdateCartAttributes as h, type UseBuyNowOptions as i, useBuyNow as j, useCalcAutoFreeGift as k, useCalcOrderDiscount as l, getReferralAttributes as m, useCartAttributes as n, useCartItemQuantityLimit as o, type UseScriptAutoFreeGiftResult as p, useScriptAutoFreeGift as q, useUpdateLineCodeAmountAttributes as r, type AutoFreeGift as s, type AutoFreeGiftMainProduct as t, useCreateCart as u, type AutoFreeGiftConfig as v, type RuleCondition as w, type Config as x, type GiftTier as y, type RewardItem as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as swr_mutation from 'swr/mutation';
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
|
-
import { CartLineInput as CartLineInput$1, NormalizedCart,
|
|
4
|
-
import { G as GtmParams, B as BuyNowTrackConfig,
|
|
3
|
+
import { CartLineInput as CartLineInput$1, NormalizedCart, UpdateCartLinesOptions, HasMetafieldsIdentifier, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle } from '@anker-in/shopify-sdk';
|
|
4
|
+
import { A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, d as PlusMemberShippingMethodConfig, e as PlusMemberSettingsMetafields, D as DeliveryPlusType, f as SelectedPlusMemberProduct, i as DeliveryData } from './types-CICUnw0v.mjs';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
6
|
import * as swr from 'swr';
|
|
7
7
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
@@ -90,79 +90,6 @@ interface AddCartLinesInput {
|
|
|
90
90
|
*/
|
|
91
91
|
declare function useAddCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'add-cart-lines', AddCartLinesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "add-cart-lines", AddCartLinesInput>;
|
|
92
92
|
|
|
93
|
-
interface AddToCartInput {
|
|
94
|
-
/** Lines to add */
|
|
95
|
-
lineItems: Array<{
|
|
96
|
-
variant?: NormalizedProductVariant;
|
|
97
|
-
finalPrice?: MoneyV2;
|
|
98
|
-
sellingPlanId?: string;
|
|
99
|
-
quantity?: number;
|
|
100
|
-
attributes?: Array<{
|
|
101
|
-
key: string;
|
|
102
|
-
value: string;
|
|
103
|
-
}>;
|
|
104
|
-
}>;
|
|
105
|
-
/** Cart ID (optional) */
|
|
106
|
-
cartId?: string;
|
|
107
|
-
/** Discount codes to apply */
|
|
108
|
-
discountCodes?: string[];
|
|
109
|
-
/** Custom attributes for the cart */
|
|
110
|
-
customAttributes?: Array<{
|
|
111
|
-
key: string;
|
|
112
|
-
value: string;
|
|
113
|
-
}>;
|
|
114
|
-
/** 全量更新 codes,默认是追加 */
|
|
115
|
-
replaceExistingCodes?: boolean;
|
|
116
|
-
/** Buyer identity for cart creation */
|
|
117
|
-
buyerIdentity?: {
|
|
118
|
-
email?: string;
|
|
119
|
-
countryCode?: string;
|
|
120
|
-
};
|
|
121
|
-
/** GTM tracking parameters */
|
|
122
|
-
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
123
|
-
/** Force create new cart */
|
|
124
|
-
needCreateCart?: boolean;
|
|
125
|
-
/** Callback when discount codes are invalid */
|
|
126
|
-
onCodesInvalid?: (updatedCart: NormalizedCart, invalidCodes: string[]) => Promise<NormalizedCart | undefined>;
|
|
127
|
-
}
|
|
128
|
-
interface UseAddToCartOptions {
|
|
129
|
-
/** Enable tracking (GA and FBQ) */
|
|
130
|
-
withTrack?: boolean;
|
|
131
|
-
/** Brand name for tracking */
|
|
132
|
-
brand?: string;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Hook for adding items to cart with tracking support
|
|
136
|
-
*
|
|
137
|
-
* This is the enhanced version that includes:
|
|
138
|
-
* - Automatic cart creation if needed
|
|
139
|
-
* - Discount code validation
|
|
140
|
-
* - Google Analytics tracking
|
|
141
|
-
* - Facebook Pixel tracking
|
|
142
|
-
* - Invalid code handling
|
|
143
|
-
*
|
|
144
|
-
* @param options - Hook configuration
|
|
145
|
-
* @param swrOptions - SWR mutation configuration
|
|
146
|
-
* @returns SWR mutation with trigger function
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```tsx
|
|
150
|
-
* const { trigger, isMutating } = useAddToCart({ withTrack: true, brand: 'Anker' })
|
|
151
|
-
*
|
|
152
|
-
* await trigger({
|
|
153
|
-
* lineItems: [{
|
|
154
|
-
* variantId: 'gid://shopify/ProductVariant/123',
|
|
155
|
-
* quantity: 2
|
|
156
|
-
* }],
|
|
157
|
-
* gtmParams: {
|
|
158
|
-
* pageGroup: 'PDP',
|
|
159
|
-
* position: 'Add to Cart Button'
|
|
160
|
-
* }
|
|
161
|
-
* })
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
declare function useAddToCart({ withTrack, brand }?: UseAddToCartOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, AddToCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, AddToCartInput>;
|
|
165
|
-
|
|
166
93
|
/**
|
|
167
94
|
* Hook for updating cart line quantities
|
|
168
95
|
*
|
|
@@ -307,17 +234,7 @@ interface BuyNowInput {
|
|
|
307
234
|
product: HasMetafieldsIdentifier[];
|
|
308
235
|
};
|
|
309
236
|
/** Line items to add to the new cart */
|
|
310
|
-
lineItems: Array<
|
|
311
|
-
variant?: {
|
|
312
|
-
id: string;
|
|
313
|
-
};
|
|
314
|
-
variantId?: string;
|
|
315
|
-
quantity?: number;
|
|
316
|
-
attributes?: Array<{
|
|
317
|
-
key: string;
|
|
318
|
-
value: string;
|
|
319
|
-
}>;
|
|
320
|
-
}>;
|
|
237
|
+
lineItems: Array<AddToCartLineItem>;
|
|
321
238
|
/** Discount codes to apply */
|
|
322
239
|
discountCodes?: string[];
|
|
323
240
|
/** Custom attributes for the cart */
|
|
@@ -340,8 +257,6 @@ interface BuyNowInput {
|
|
|
340
257
|
interface UseBuyNowOptions {
|
|
341
258
|
/** Enable tracking (GA and FBQ) */
|
|
342
259
|
withTrack?: boolean;
|
|
343
|
-
/** Brand name for tracking */
|
|
344
|
-
brand?: string;
|
|
345
260
|
}
|
|
346
261
|
/**
|
|
347
262
|
* Hook for buy now functionality
|
|
@@ -358,7 +273,6 @@ interface UseBuyNowOptions {
|
|
|
358
273
|
* const { trigger, isMutating } = useBuyNow({
|
|
359
274
|
* withTrack: true,
|
|
360
275
|
* redirectToCheckout: true,
|
|
361
|
-
* brand: 'Anker'
|
|
362
276
|
* })
|
|
363
277
|
*
|
|
364
278
|
* await trigger({
|
|
@@ -373,7 +287,7 @@ interface UseBuyNowOptions {
|
|
|
373
287
|
* })
|
|
374
288
|
* ```
|
|
375
289
|
*/
|
|
376
|
-
declare function useBuyNow({ withTrack
|
|
290
|
+
declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, BuyNowInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, BuyNowInput>;
|
|
377
291
|
|
|
378
292
|
type AutoFreeGift = {
|
|
379
293
|
currentTier: {
|
|
@@ -1933,4 +1847,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1933
1847
|
*/
|
|
1934
1848
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1935
1849
|
|
|
1936
|
-
export {
|
|
1850
|
+
export { defaultSWRMutationConfiguration as $, type AddCartLinesInput as A, type BuyNowInput as B, type CreateCartInput as C, type DiscountLabel as D, type GiftProductItem as E, RuleType as F, type GiftProduct as G, BuyRuleType as H, type FunctionGiftResult as I, type FormattedGift as J, type CartLineInput as K, type AutoFreeGiftItem as L, type MainProductInfo as M, type AutoFreeGiftList as N, type OrderDiscountResult as O, OrderDiscountType as P, OrderBasePriceType as Q, type RemoveCartLinesInput as R, SpendMoneyType as S, type TieredDiscount as T, type UpdateCartAttributesInput as U, type VariantItem as V, type OrderDiscountConfig as W, PriceDiscountType as X, PriceBasePriceType as Y, type PriceDiscountConfig as Z, currencyCodeMapping as _, useAddCartLines as a, usePlusAnnualProductVariant as a$, CUSTOMER_ATTRIBUTE_KEY as a0, CUSTOMER_SCRIPT_GIFT_KEY as a1, CODE_AMOUNT_KEY as a2, SCRIPT_CODE_AMOUNT_KEY as a3, MAIN_PRODUCT_CODE as a4, getQuery as a5, atobID as a6, btoaID as a7, getMatchedMainProductSubTotal as a8, getDiscountEnvAttributeValue as a9, type UseAllCollectionsOptions as aA, useAllCollections as aB, type UseCollectionsOptions as aC, useCollections as aD, type UseBlogOptions as aE, useBlog as aF, type UseAllBlogsOptions as aG, useAllBlogs as aH, type UseArticleOptions as aI, useArticle as aJ, type UseArticlesOptions as aK, useArticles as aL, type UseArticlesInBlogOptions as aM, useArticlesInBlog as aN, type SearchResultType as aO, type SearchResultItem as aP, type SearchResult as aQ, type UseSearchOptions as aR, useSearch as aS, type SiteInfo as aT, type UseSiteOptions as aU, useSite as aV, type ShippingMethodsContext as aW, type PlusMemberContextValue as aX, PlusMemberContext as aY, usePlusMemberContext as aZ, usePlusMonthlyProductVariant as a_, isAttributesEqual as aa, safeParseJson as ab, preCheck as ac, formatScriptAutoFreeGift as ad, formatFunctionAutoFreeGift as ae, useSelectedOptions as af, type SelectedOptionsResult as ag, type UseProductOptions as ah, useProduct as ai, type UseAllProductsOptions as aj, useAllProducts as ak, type UseProductsByHandlesOptions as al, useProductsByHandles as am, type Options as an, useVariant as ao, type UsePriceOptions as ap, type UsePriceResult as aq, usePrice as ar, useProductUrl as as, useUpdateVariantQuery as at, type ImageMedia as au, type VideoMedia as av, type VariantMedia as aw, useVariantMedia as ax, type UseCollectionOptions as ay, useCollection as az, useUpdateCartLines as b, type UseShippingMethodsOptions as b0, type UseShippingMethodsResult as b1, useShippingMethods as b2, useShippingMethodAvailableCheck as b3, useReplaceCartPlusMember as b4, usePlusMemberDeliveryCodes as b5, usePlusMemberItemCustomAttributes as b6, type CustomerOrder as b7, type Customer as b8, usePlusMemberCheckoutCustomAttributes as b9, type ExportCart as bA, type UseAutoRemovePlusMemberInCartProps as ba, useAutoRemovePlusMemberInCart as bb, type UseHasPlusMemberInCartProps as bc, type HasPlusMemberInCartResult as bd, useHasPlusMemberInCart as be, type PlusMemberProviderProps as bf, PlusMemberProvider as bg, type UseIntersectionOptions as bh, useIntersection as bi, type UseExposureOptions as bj, useExposure as bk, type GeoLocationData as bl, type LocaleMapping as bm, type UseGeoLocationOptions as bn, useGeoLocation as bo, getCachedGeoLocation as bp, clearGeoLocationCache as bq, type Attribute as br, type Discount as bs, type Image as bt, type Measurement as bu, type ExportSelectedOption as bv, type ExportProductVariant as bw, type ExportDiscountAllocations as bx, type ExportLineItem as by, type ExportDiscounts as bz, useRemoveCartLines as c, type ApplyCartCodesInput as d, useApplyCartCodes as e, type RemoveCartCodesInput as f, useRemoveCartCodes as g, useUpdateCartAttributes as h, type UseBuyNowOptions as i, useBuyNow as j, useCalcAutoFreeGift as k, useCalcOrderDiscount as l, getReferralAttributes as m, useCartAttributes as n, useCartItemQuantityLimit as o, type UseScriptAutoFreeGiftResult as p, useScriptAutoFreeGift as q, useUpdateLineCodeAmountAttributes as r, type AutoFreeGift as s, type AutoFreeGiftMainProduct as t, useCreateCart as u, type AutoFreeGiftConfig as v, type RuleCondition as w, type Config as x, type GiftTier as y, type RewardItem as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { AttributeInput, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.mjs';
|
|
2
2
|
export { b as CartCookieAdapter, C as CookieAdapter, a as CookieOptions, R as RouterAdapter, U as UserContextAdapter } from './types-BLMoxbOk.mjs';
|
|
3
3
|
export { browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.mjs';
|
|
4
|
-
export { A as AddCartLinesInput,
|
|
5
|
-
export { B as BuyNowTrackConfig,
|
|
4
|
+
export { A as AddCartLinesInput, d as ApplyCartCodesInput, br as Attribute, s as AutoFreeGift, v as AutoFreeGiftConfig, L as AutoFreeGiftItem, N as AutoFreeGiftList, t as AutoFreeGiftMainProduct, B as BuyNowInput, H as BuyRuleType, a2 as CODE_AMOUNT_KEY, a0 as CUSTOMER_ATTRIBUTE_KEY, a1 as CUSTOMER_SCRIPT_GIFT_KEY, K as CartLineInput, x as Config, C as CreateCartInput, b8 as Customer, b7 as CustomerOrder, bs as Discount, D as DiscountLabel, bA as ExportCart, bx as ExportDiscountAllocations, bz as ExportDiscounts, by as ExportLineItem, bw as ExportProductVariant, bv as ExportSelectedOption, J as FormattedGift, I as FunctionGiftResult, bl as GeoLocationData, G as GiftProduct, E as GiftProductItem, y as GiftTier, bd as HasPlusMemberInCartResult, bt as Image, au as ImageMedia, bm as LocaleMapping, a4 as MAIN_PRODUCT_CODE, M as MainProductInfo, bu as Measurement, an as Options, Q as OrderBasePriceType, W as OrderDiscountConfig, O as OrderDiscountResult, P as OrderDiscountType, aY as PlusMemberContext, aX as PlusMemberContextValue, bg as PlusMemberProvider, bf as PlusMemberProviderProps, Y as PriceBasePriceType, Z as PriceDiscountConfig, X as PriceDiscountType, f as RemoveCartCodesInput, R as RemoveCartLinesInput, z as RewardItem, w as RuleCondition, F as RuleType, a3 as SCRIPT_CODE_AMOUNT_KEY, aQ as SearchResult, aP as SearchResultItem, aO as SearchResultType, ag as SelectedOptionsResult, aW as ShippingMethodsContext, aT as SiteInfo, S as SpendMoneyType, T as TieredDiscount, U as UpdateCartAttributesInput, aG as UseAllBlogsOptions, aA as UseAllCollectionsOptions, aj as UseAllProductsOptions, aI as UseArticleOptions, aM as UseArticlesInBlogOptions, aK as UseArticlesOptions, ba as UseAutoRemovePlusMemberInCartProps, aE as UseBlogOptions, i as UseBuyNowOptions, ay as UseCollectionOptions, aC as UseCollectionsOptions, bj as UseExposureOptions, bn as UseGeoLocationOptions, bc as UseHasPlusMemberInCartProps, bh as UseIntersectionOptions, ap as UsePriceOptions, aq as UsePriceResult, ah as UseProductOptions, al as UseProductsByHandlesOptions, p as UseScriptAutoFreeGiftResult, aR as UseSearchOptions, b0 as UseShippingMethodsOptions, b1 as UseShippingMethodsResult, aU as UseSiteOptions, V as VariantItem, aw as VariantMedia, av as VideoMedia, a6 as atobID, a7 as btoaID, bq as clearGeoLocationCache, _ as currencyCodeMapping, $ as defaultSWRMutationConfiguration, ae as formatFunctionAutoFreeGift, ad as formatScriptAutoFreeGift, bp as getCachedGeoLocation, a9 as getDiscountEnvAttributeValue, a8 as getMatchedMainProductSubTotal, a5 as getQuery, m as getReferralAttributes, aa as isAttributesEqual, ac as preCheck, ab as safeParseJson, a as useAddCartLines, aH as useAllBlogs, aB as useAllCollections, ak as useAllProducts, e as useApplyCartCodes, aJ as useArticle, aL as useArticles, aN as useArticlesInBlog, bb as useAutoRemovePlusMemberInCart, aF as useBlog, j as useBuyNow, k as useCalcAutoFreeGift, l as useCalcOrderDiscount, n as useCartAttributes, o as useCartItemQuantityLimit, az as useCollection, aD as useCollections, u as useCreateCart, bk as useExposure, bo as useGeoLocation, be as useHasPlusMemberInCart, bi as useIntersection, a$ as usePlusAnnualProductVariant, b9 as usePlusMemberCheckoutCustomAttributes, aZ as usePlusMemberContext, b5 as usePlusMemberDeliveryCodes, b6 as usePlusMemberItemCustomAttributes, a_ as usePlusMonthlyProductVariant, ar as usePrice, ai as useProduct, as as useProductUrl, am as useProductsByHandles, g as useRemoveCartCodes, c as useRemoveCartLines, b4 as useReplaceCartPlusMember, q as useScriptAutoFreeGift, aS as useSearch, af as useSelectedOptions, b3 as useShippingMethodAvailableCheck, b2 as useShippingMethods, aV as useSite, h as useUpdateCartAttributes, b as useUpdateCartLines, r as useUpdateLineCodeAmountAttributes, at as useUpdateVariantQuery, ao as useVariant, ax as useVariantMedia } from './index-RevQokdZ.mjs';
|
|
5
|
+
export { a as AddToCartInput, A as AddToCartLineItem, B as BuyNowTrackConfig, h as DeliveryCustomData, i as DeliveryData, g as DeliveryOption, D as DeliveryPlusType, G as GtmParams, M as MailingAddress, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, e as PlusMemberSettingsMetafields, d as PlusMemberShippingMethodConfig, c as PlusMemberShippingMethodMetafields, f as SelectedPlusMemberProduct, S as ShippingMethodMode, U as UseAddToCartOptions, j as gaTrack, m as trackAddToCartFBQ, t as trackAddToCartGA, k as trackBeginCheckoutGA, n as trackBuyNowFBQ, l as trackBuyNowGA, u as useAddToCart } from './types-CICUnw0v.mjs';
|
|
6
6
|
export { ShopifyConfig, clearLocalStorage, createShopifyClient, getLocalStorage, removeLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { AttributeInput, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.js';
|
|
2
2
|
export { b as CartCookieAdapter, C as CookieAdapter, a as CookieOptions, R as RouterAdapter, U as UserContextAdapter } from './types-BLMoxbOk.js';
|
|
3
3
|
export { browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.js';
|
|
4
|
-
export { A as AddCartLinesInput,
|
|
5
|
-
export { B as BuyNowTrackConfig,
|
|
4
|
+
export { A as AddCartLinesInput, d as ApplyCartCodesInput, br as Attribute, s as AutoFreeGift, v as AutoFreeGiftConfig, L as AutoFreeGiftItem, N as AutoFreeGiftList, t as AutoFreeGiftMainProduct, B as BuyNowInput, H as BuyRuleType, a2 as CODE_AMOUNT_KEY, a0 as CUSTOMER_ATTRIBUTE_KEY, a1 as CUSTOMER_SCRIPT_GIFT_KEY, K as CartLineInput, x as Config, C as CreateCartInput, b8 as Customer, b7 as CustomerOrder, bs as Discount, D as DiscountLabel, bA as ExportCart, bx as ExportDiscountAllocations, bz as ExportDiscounts, by as ExportLineItem, bw as ExportProductVariant, bv as ExportSelectedOption, J as FormattedGift, I as FunctionGiftResult, bl as GeoLocationData, G as GiftProduct, E as GiftProductItem, y as GiftTier, bd as HasPlusMemberInCartResult, bt as Image, au as ImageMedia, bm as LocaleMapping, a4 as MAIN_PRODUCT_CODE, M as MainProductInfo, bu as Measurement, an as Options, Q as OrderBasePriceType, W as OrderDiscountConfig, O as OrderDiscountResult, P as OrderDiscountType, aY as PlusMemberContext, aX as PlusMemberContextValue, bg as PlusMemberProvider, bf as PlusMemberProviderProps, Y as PriceBasePriceType, Z as PriceDiscountConfig, X as PriceDiscountType, f as RemoveCartCodesInput, R as RemoveCartLinesInput, z as RewardItem, w as RuleCondition, F as RuleType, a3 as SCRIPT_CODE_AMOUNT_KEY, aQ as SearchResult, aP as SearchResultItem, aO as SearchResultType, ag as SelectedOptionsResult, aW as ShippingMethodsContext, aT as SiteInfo, S as SpendMoneyType, T as TieredDiscount, U as UpdateCartAttributesInput, aG as UseAllBlogsOptions, aA as UseAllCollectionsOptions, aj as UseAllProductsOptions, aI as UseArticleOptions, aM as UseArticlesInBlogOptions, aK as UseArticlesOptions, ba as UseAutoRemovePlusMemberInCartProps, aE as UseBlogOptions, i as UseBuyNowOptions, ay as UseCollectionOptions, aC as UseCollectionsOptions, bj as UseExposureOptions, bn as UseGeoLocationOptions, bc as UseHasPlusMemberInCartProps, bh as UseIntersectionOptions, ap as UsePriceOptions, aq as UsePriceResult, ah as UseProductOptions, al as UseProductsByHandlesOptions, p as UseScriptAutoFreeGiftResult, aR as UseSearchOptions, b0 as UseShippingMethodsOptions, b1 as UseShippingMethodsResult, aU as UseSiteOptions, V as VariantItem, aw as VariantMedia, av as VideoMedia, a6 as atobID, a7 as btoaID, bq as clearGeoLocationCache, _ as currencyCodeMapping, $ as defaultSWRMutationConfiguration, ae as formatFunctionAutoFreeGift, ad as formatScriptAutoFreeGift, bp as getCachedGeoLocation, a9 as getDiscountEnvAttributeValue, a8 as getMatchedMainProductSubTotal, a5 as getQuery, m as getReferralAttributes, aa as isAttributesEqual, ac as preCheck, ab as safeParseJson, a as useAddCartLines, aH as useAllBlogs, aB as useAllCollections, ak as useAllProducts, e as useApplyCartCodes, aJ as useArticle, aL as useArticles, aN as useArticlesInBlog, bb as useAutoRemovePlusMemberInCart, aF as useBlog, j as useBuyNow, k as useCalcAutoFreeGift, l as useCalcOrderDiscount, n as useCartAttributes, o as useCartItemQuantityLimit, az as useCollection, aD as useCollections, u as useCreateCart, bk as useExposure, bo as useGeoLocation, be as useHasPlusMemberInCart, bi as useIntersection, a$ as usePlusAnnualProductVariant, b9 as usePlusMemberCheckoutCustomAttributes, aZ as usePlusMemberContext, b5 as usePlusMemberDeliveryCodes, b6 as usePlusMemberItemCustomAttributes, a_ as usePlusMonthlyProductVariant, ar as usePrice, ai as useProduct, as as useProductUrl, am as useProductsByHandles, g as useRemoveCartCodes, c as useRemoveCartLines, b4 as useReplaceCartPlusMember, q as useScriptAutoFreeGift, aS as useSearch, af as useSelectedOptions, b3 as useShippingMethodAvailableCheck, b2 as useShippingMethods, aV as useSite, h as useUpdateCartAttributes, b as useUpdateCartLines, r as useUpdateLineCodeAmountAttributes, at as useUpdateVariantQuery, ao as useVariant, ax as useVariantMedia } from './index-CCMIeIUh.js';
|
|
5
|
+
export { a as AddToCartInput, A as AddToCartLineItem, B as BuyNowTrackConfig, h as DeliveryCustomData, i as DeliveryData, g as DeliveryOption, D as DeliveryPlusType, G as GtmParams, M as MailingAddress, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, e as PlusMemberSettingsMetafields, d as PlusMemberShippingMethodConfig, c as PlusMemberShippingMethodMetafields, f as SelectedPlusMemberProduct, S as ShippingMethodMode, U as UseAddToCartOptions, j as gaTrack, m as trackAddToCartFBQ, t as trackAddToCartGA, k as trackBeginCheckoutGA, n as trackBuyNowFBQ, l as trackBuyNowGA, u as useAddToCart } from './types-CICUnw0v.js';
|
|
6
6
|
export { ShopifyConfig, clearLocalStorage, createShopifyClient, getLocalStorage, removeLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'react/jsx-runtime';
|
package/dist/index.js
CHANGED
|
@@ -667,8 +667,6 @@ function useAddCartLines(options) {
|
|
|
667
667
|
);
|
|
668
668
|
return useSWRMutation__default.default("add-cart-lines", addLines, options);
|
|
669
669
|
}
|
|
670
|
-
|
|
671
|
-
// src/tracking/ga.ts
|
|
672
670
|
var gaTrack = (data) => {
|
|
673
671
|
if (typeof window === "undefined") {
|
|
674
672
|
return;
|
|
@@ -686,18 +684,15 @@ var gaTrack = (data) => {
|
|
|
686
684
|
};
|
|
687
685
|
var trackAddToCartGA = ({
|
|
688
686
|
lineItems = [],
|
|
689
|
-
gtmParams = {}
|
|
690
|
-
brand
|
|
687
|
+
gtmParams = {}
|
|
691
688
|
}) => {
|
|
692
689
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
693
690
|
return;
|
|
694
691
|
}
|
|
695
692
|
const { variant } = lineItems[0];
|
|
696
|
-
const currencyCode = variant?.price?.currencyCode;
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
return sum + price;
|
|
700
|
-
}, 0);
|
|
693
|
+
const currencyCode = variant.product?.price?.currencyCode;
|
|
694
|
+
const price = variant.compareAtPrice?.amount ?? (variant.price?.amount || 0);
|
|
695
|
+
const totalPrice = lineItems?.reduce((prev, { variant: variant2 }) => prev.plus(variant2?.finalPrice?.amount ?? price), new Decimal2__default.default(0)).toNumber();
|
|
701
696
|
gaTrack({
|
|
702
697
|
event: "ga4Event",
|
|
703
698
|
event_name: "add_to_cart",
|
|
@@ -708,11 +703,11 @@ var trackAddToCartGA = ({
|
|
|
708
703
|
position: gtmParams?.position || "",
|
|
709
704
|
items: lineItems.map(({ variant: variant2, quantity }) => ({
|
|
710
705
|
item_id: variant2?.sku,
|
|
711
|
-
item_name: variant2?.product?.title || variant2?.product?.
|
|
712
|
-
item_brand:
|
|
706
|
+
item_name: variant2?.product?.title || variant2?.product?.title,
|
|
707
|
+
item_brand: gtmParams?.brand || "",
|
|
713
708
|
item_category: variant2?.product?.productType || "",
|
|
714
|
-
item_variant: variant2?.title || variant2?.
|
|
715
|
-
price
|
|
709
|
+
item_variant: variant2?.title || variant2?.title,
|
|
710
|
+
price,
|
|
716
711
|
quantity: quantity || 1
|
|
717
712
|
})),
|
|
718
713
|
...gtmParams?.ga4Params
|
|
@@ -722,13 +717,14 @@ var trackAddToCartGA = ({
|
|
|
722
717
|
var trackBeginCheckoutGA = ({
|
|
723
718
|
lineItems = [],
|
|
724
719
|
currencyCode,
|
|
725
|
-
|
|
726
|
-
gtmParams = {},
|
|
727
|
-
brand
|
|
720
|
+
gtmParams = {}
|
|
728
721
|
}) => {
|
|
729
722
|
if (!lineItems.length) {
|
|
730
723
|
return;
|
|
731
724
|
}
|
|
725
|
+
const { variant } = lineItems[0] || {};
|
|
726
|
+
const price = variant?.compareAtPrice?.amount ?? (variant?.price?.amount || 0);
|
|
727
|
+
const totalPrice = lineItems?.reduce((prev, { variant: variant2 }) => prev.plus(variant2?.finalPrice?.amount ?? price), new Decimal2__default.default(0)).toNumber();
|
|
732
728
|
gaTrack({
|
|
733
729
|
event: "ga4Event",
|
|
734
730
|
event_name: "begin_checkout",
|
|
@@ -740,10 +736,10 @@ var trackBeginCheckoutGA = ({
|
|
|
740
736
|
items: lineItems.map((item) => ({
|
|
741
737
|
item_id: item.variant?.sku,
|
|
742
738
|
item_name: item.variant?.product?.title,
|
|
743
|
-
item_brand:
|
|
739
|
+
item_brand: gtmParams?.brand || "",
|
|
744
740
|
item_category: item.variant?.product?.productType,
|
|
745
741
|
item_variant: item.variant?.title,
|
|
746
|
-
price
|
|
742
|
+
price,
|
|
747
743
|
quantity: item.quantity || 1
|
|
748
744
|
})),
|
|
749
745
|
...gtmParams?.ga4Params
|
|
@@ -752,19 +748,15 @@ var trackBeginCheckoutGA = ({
|
|
|
752
748
|
};
|
|
753
749
|
var trackBuyNowGA = ({
|
|
754
750
|
lineItems = [],
|
|
755
|
-
gtmParams = {}
|
|
756
|
-
brand
|
|
751
|
+
gtmParams = {}
|
|
757
752
|
}) => {
|
|
758
753
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
759
754
|
return;
|
|
760
755
|
}
|
|
761
756
|
const { variant } = lineItems[0];
|
|
762
757
|
const currencyCode = variant.price?.currencyCode;
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
const quantity = item.quantity || 1;
|
|
766
|
-
return sum + price * quantity;
|
|
767
|
-
}, 0);
|
|
758
|
+
const price = variant.compareAtPrice?.amount ?? (variant.price?.amount || 0);
|
|
759
|
+
const totalPrice = lineItems?.reduce((prev, { variant: variant2 }) => prev.plus(variant2?.finalPrice?.amount ?? price), new Decimal2__default.default(0)).toNumber();
|
|
768
760
|
gaTrack({
|
|
769
761
|
event: "ga4Event",
|
|
770
762
|
event_name: "begin_checkout",
|
|
@@ -776,10 +768,10 @@ var trackBuyNowGA = ({
|
|
|
776
768
|
items: lineItems.map((item) => ({
|
|
777
769
|
item_id: item.variant?.sku,
|
|
778
770
|
item_name: item.variant?.product?.title || item.variant?.title,
|
|
779
|
-
item_brand:
|
|
771
|
+
item_brand: gtmParams?.brand || "",
|
|
780
772
|
item_category: item.variant?.product?.productType || "",
|
|
781
773
|
item_variant: item.variant?.title,
|
|
782
|
-
price
|
|
774
|
+
price,
|
|
783
775
|
quantity: item.quantity || 1
|
|
784
776
|
})),
|
|
785
777
|
...gtmParams?.ga4Params
|
|
@@ -793,10 +785,10 @@ var trackAddToCartFBQ = ({ lineItems = [] }) => {
|
|
|
793
785
|
return;
|
|
794
786
|
}
|
|
795
787
|
if (lineItems.length && lineItems[0]?.variant) {
|
|
796
|
-
const { variant, quantity
|
|
788
|
+
const { variant, quantity } = lineItems[0];
|
|
797
789
|
try {
|
|
798
790
|
window.fbq("track", "AddToCart", {
|
|
799
|
-
value:
|
|
791
|
+
value: variant?.compareAtPrice?.amount ?? (variant?.price?.amount || variant?.price || 0),
|
|
800
792
|
num_items: quantity,
|
|
801
793
|
currency: variant?.price?.currencyCode,
|
|
802
794
|
content_name: variant?.product?.title,
|
|
@@ -883,9 +875,9 @@ function useRemoveCartCodes(options) {
|
|
|
883
875
|
}
|
|
884
876
|
|
|
885
877
|
// src/hooks/cart/use-add-to-cart.ts
|
|
886
|
-
function useAddToCart({ withTrack = true
|
|
887
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
888
|
-
const {
|
|
878
|
+
function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
879
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
880
|
+
const { cart } = useCartContext();
|
|
889
881
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
890
882
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
891
883
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
@@ -907,7 +899,8 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
907
899
|
const lines = lineItems.map((item) => ({
|
|
908
900
|
merchandiseId: item.variant?.id || "",
|
|
909
901
|
quantity: item.quantity || 1,
|
|
910
|
-
attributes: item.attributes
|
|
902
|
+
attributes: item.attributes,
|
|
903
|
+
sellingPlanId: item.sellingPlanId
|
|
911
904
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
912
905
|
if (lines.length === 0) {
|
|
913
906
|
return;
|
|
@@ -942,34 +935,16 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
942
935
|
discountCodes
|
|
943
936
|
});
|
|
944
937
|
}
|
|
945
|
-
if (withTrack
|
|
946
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
947
|
-
variant: {
|
|
948
|
-
id: line.variant.id,
|
|
949
|
-
sku: line.variant.sku || "",
|
|
950
|
-
title: line.variant.name,
|
|
951
|
-
price: {
|
|
952
|
-
amount: String(line.variant.price),
|
|
953
|
-
currencyCode: resultCart.currency.code
|
|
954
|
-
},
|
|
955
|
-
product: line.product ? {
|
|
956
|
-
title: line.product.title || line.name,
|
|
957
|
-
productType: line.product.productType,
|
|
958
|
-
vendor: line.product.vendor
|
|
959
|
-
} : void 0
|
|
960
|
-
},
|
|
961
|
-
quantity: line.quantity
|
|
962
|
-
}));
|
|
938
|
+
if (withTrack) {
|
|
963
939
|
trackAddToCartGA({
|
|
964
|
-
lineItems
|
|
965
|
-
gtmParams: { ...gtmParams, brand }
|
|
966
|
-
brand
|
|
940
|
+
lineItems,
|
|
941
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
967
942
|
});
|
|
968
|
-
trackAddToCartFBQ({ lineItems
|
|
943
|
+
trackAddToCartFBQ({ lineItems });
|
|
969
944
|
}
|
|
970
945
|
return resultCart;
|
|
971
946
|
},
|
|
972
|
-
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack
|
|
947
|
+
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack]
|
|
973
948
|
);
|
|
974
949
|
return useSWRMutation__default.default("add-to-cart", addToCart, swrOptions);
|
|
975
950
|
}
|
|
@@ -1050,8 +1025,8 @@ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
|
|
|
1050
1025
|
);
|
|
1051
1026
|
return useSWRMutation__default.default("update-cart-attributes", updateAttributes, options);
|
|
1052
1027
|
}
|
|
1053
|
-
function useBuyNow({ withTrack = true
|
|
1054
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
1028
|
+
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
1029
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
1055
1030
|
const isLoggedIn = userAdapter?.isLoggedIn || false;
|
|
1056
1031
|
const buyNow = react.useCallback(
|
|
1057
1032
|
async (_key, { arg }) => {
|
|
@@ -1069,9 +1044,10 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1069
1044
|
return;
|
|
1070
1045
|
}
|
|
1071
1046
|
const lines = lineItems.map((item) => ({
|
|
1072
|
-
merchandiseId: item.variant?.id ||
|
|
1047
|
+
merchandiseId: item.variant?.id || "",
|
|
1073
1048
|
quantity: item.quantity || 1,
|
|
1074
|
-
attributes: item.attributes
|
|
1049
|
+
attributes: item.attributes,
|
|
1050
|
+
sellingPlanId: item.sellingPlanId
|
|
1075
1051
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
1076
1052
|
if (lines.length === 0) {
|
|
1077
1053
|
return;
|
|
@@ -1088,27 +1064,9 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1088
1064
|
throw new Error("Failed to create cart for buy now");
|
|
1089
1065
|
}
|
|
1090
1066
|
if (withTrack && resultCart.lineItems) {
|
|
1091
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
1092
|
-
variant: {
|
|
1093
|
-
id: line.variantId,
|
|
1094
|
-
sku: line.variant.sku || "",
|
|
1095
|
-
title: line.variant.name,
|
|
1096
|
-
price: {
|
|
1097
|
-
amount: String(line.variant.price),
|
|
1098
|
-
currencyCode: resultCart.currency.code
|
|
1099
|
-
},
|
|
1100
|
-
product: line.product ? {
|
|
1101
|
-
title: line.product.title || line.name,
|
|
1102
|
-
productType: line.product.productType,
|
|
1103
|
-
vendor: line.product.vendor
|
|
1104
|
-
} : void 0
|
|
1105
|
-
},
|
|
1106
|
-
quantity: line.quantity
|
|
1107
|
-
}));
|
|
1108
1067
|
trackBuyNowGA({
|
|
1109
|
-
lineItems
|
|
1110
|
-
gtmParams: { ...gtmParams, brand }
|
|
1111
|
-
brand
|
|
1068
|
+
lineItems,
|
|
1069
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
1112
1070
|
});
|
|
1113
1071
|
if (fbqTrackConfig) {
|
|
1114
1072
|
trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
|
|
@@ -1125,7 +1083,7 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1125
1083
|
}
|
|
1126
1084
|
return resultCart;
|
|
1127
1085
|
},
|
|
1128
|
-
[client, locale, isLoggedIn, cartCookieAdapter, withTrack
|
|
1086
|
+
[client, locale, isLoggedIn, cartCookieAdapter, withTrack]
|
|
1129
1087
|
);
|
|
1130
1088
|
return useSWRMutation__default.default("buy-now", buyNow, swrOptions);
|
|
1131
1089
|
}
|