@anker-in/shopify-react 0.1.1-beta.1 → 0.1.1-beta.3
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 +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +242 -47
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +237 -46
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-RevQokdZ.d.mts → index-Utuz9i5x.d.mts} +165 -49
- package/dist/{index-CCMIeIUh.d.ts → index-aSsTcW2O.d.ts} +165 -49
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +265 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -56
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +138 -34
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +138 -34
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, d as ApplyCartCodesInput,
|
|
4
|
+
export { A as AddCartLinesInput, d as ApplyCartCodesInput, by as Attribute, w as AutoFreeGift, y as AutoFreeGiftConfig, Q as AutoFreeGiftItem, T as AutoFreeGiftList, x as AutoFreeGiftMainProduct, B as BuyNowInput, K as BuyRuleType, a5 as CODE_AMOUNT_KEY, a3 as CUSTOMER_ATTRIBUTE_KEY, a4 as CUSTOMER_SCRIPT_GIFT_KEY, P as CartLineInput, E as Config, C as CreateCartInput, bd as Customer, bc as CustomerOrder, bz as Discount, D as DiscountLabel, bH as ExportCart, bE as ExportDiscountAllocations, bG as ExportDiscounts, bF as ExportLineItem, bD as ExportProductVariant, bC as ExportSelectedOption, N as FormattedGift, L as FunctionGiftResult, bs as GeoLocationData, G as GiftProduct, I as GiftProductItem, F as GiftTier, bi as HasPlusMemberInCartResult, bA as Image, az as ImageMedia, bt as LocaleMapping, a7 as MAIN_PRODUCT_CODE, M as MainProductInfo, bB as Measurement, as as Options, X as OrderBasePriceType, Z as OrderDiscountConfig, O as OrderDiscountResult, W as OrderDiscountType, b1 as PlusMemberContext, b0 as PlusMemberContextValue, bn as PlusMemberProvider, bm as PlusMemberProviderProps, $ as PriceBasePriceType, a0 as PriceDiscountConfig, _ as PriceDiscountType, f as RemoveCartCodesInput, R as RemoveCartLinesInput, H as RewardItem, z as RuleCondition, J as RuleType, a6 as SCRIPT_CODE_AMOUNT_KEY, aV as SearchResult, aU as SearchResultItem, aT as SearchResultType, al as SelectedOptionsResult, a$ as ShippingMethodsContext, aY as SiteInfo, S as SpendMoneyType, Y as TieredDiscount, U as UpdateCartAttributesInput, bk as UseAddPlusMemberProductsToCartProps, aL as UseAllBlogsOptions, aF as UseAllCollectionsOptions, ao as UseAllProductsOptions, aN as UseArticleOptions, aR as UseArticlesInBlogOptions, aP as UseArticlesOptions, bf as UseAutoRemovePlusMemberInCartProps, aJ as UseBlogOptions, i as UseBuyNowOptions, l as UseCalcGiftsFromLinesOptions, m as UseCalcGiftsFromLinesResult, aD as UseCollectionOptions, aH as UseCollectionsOptions, bq as UseExposureOptions, bu as UseGeoLocationOptions, bh as UseHasPlusMemberInCartProps, bo as UseIntersectionOptions, au as UsePriceOptions, av as UsePriceResult, am as UseProductOptions, aq as UseProductsByHandlesOptions, s as UseScriptAutoFreeGiftResult, aW as UseSearchOptions, b5 as UseShippingMethodsOptions, b6 as UseShippingMethodsResult, aZ as UseSiteOptions, V as VariantItem, aB as VariantMedia, aA as VideoMedia, a9 as atobID, aa as btoaID, ag as checkAttributesUpdateNeeded, bx as clearGeoLocationCache, ac as createMockCartFromLines, a1 as currencyCodeMapping, a2 as defaultSWRMutationConfiguration, aj as formatFunctionAutoFreeGift, ai as formatScriptAutoFreeGift, bw as getCachedGeoLocation, af as getDiscountEnvAttributeValue, ad as getMatchedMainProductSubTotal, a8 as getQuery, p as getReferralAttributes, ab as normalizeAddToCartLines, ah as preCheck, ae as safeParse, a as useAddCartLines, bl as useAddPlusMemberProductsToCart, aM as useAllBlogs, aG as useAllCollections, ap as useAllProducts, e as useApplyCartCodes, aO as useArticle, aQ as useArticles, aS as useArticlesInBlog, bg as useAutoRemovePlusMemberInCart, aK as useBlog, j as useBuyNow, k as useCalcAutoFreeGift, n as useCalcGiftsFromLines, o as useCalcOrderDiscount, q as useCartAttributes, r as useCartItemQuantityLimit, aE as useCollection, aI as useCollections, u as useCreateCart, br as useExposure, bv as useGeoLocation, bj as useHasPlusMemberInCart, bp as useIntersection, b4 as usePlusAnnualProductVariant, be as usePlusMemberCheckoutCustomAttributes, b2 as usePlusMemberContext, ba as usePlusMemberDeliveryCodes, bb as usePlusMemberItemCustomAttributes, b3 as usePlusMonthlyProductVariant, aw as usePrice, an as useProduct, ax as useProductUrl, ar as useProductsByHandles, g as useRemoveCartCodes, c as useRemoveCartLines, b9 as useReplaceCartPlusMember, t as useScriptAutoFreeGift, aX as useSearch, ak as useSelectedOptions, b8 as useShippingMethodAvailableCheck, b7 as useShippingMethods, a_ as useSite, h as useUpdateCartAttributes, b as useUpdateCartLines, v as useUpdateLineCodeAmountAttributes, ay as useUpdateVariantQuery, at as useVariant, aC as useVariantMedia } from './index-aSsTcW2O.js';
|
|
5
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';
|
package/dist/index.js
CHANGED
|
@@ -142,6 +142,81 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
142
142
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
143
143
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
144
144
|
|
|
145
|
+
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
146
|
+
function normalizeAddToCartLines(lines) {
|
|
147
|
+
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
148
|
+
const variant = line.variant;
|
|
149
|
+
const product = variant.product;
|
|
150
|
+
const quantity = line.quantity || 1;
|
|
151
|
+
const price = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
152
|
+
const subtotalAmount = price * quantity;
|
|
153
|
+
const totalAmount = subtotalAmount;
|
|
154
|
+
return {
|
|
155
|
+
id: `temp-line-${index}-${variant.id}`,
|
|
156
|
+
// Temporary ID for pre-cart lines
|
|
157
|
+
name: product?.title || variant.title || "",
|
|
158
|
+
quantity,
|
|
159
|
+
variantId: variant.id,
|
|
160
|
+
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
161
|
+
totalAmount,
|
|
162
|
+
subtotalAmount,
|
|
163
|
+
discountAllocations: [],
|
|
164
|
+
customAttributes: line.attributes || [],
|
|
165
|
+
variant: {
|
|
166
|
+
id: variant.id,
|
|
167
|
+
price,
|
|
168
|
+
listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
|
|
169
|
+
sku: variant.sku || "",
|
|
170
|
+
name: variant.title || "",
|
|
171
|
+
image: variant.image ? {
|
|
172
|
+
url: variant.image.url,
|
|
173
|
+
altText: variant.image.altText || void 0
|
|
174
|
+
} : void 0,
|
|
175
|
+
requiresShipping: false,
|
|
176
|
+
// Default value, not available in NormalizedProductVariant
|
|
177
|
+
availableForSale: variant.availableForSale ?? true,
|
|
178
|
+
quantityAvailable: variant.quantityAvailable ?? 0,
|
|
179
|
+
currentlyNotInStock: false,
|
|
180
|
+
// Default value, will be updated when added to cart
|
|
181
|
+
weight: variant.weight,
|
|
182
|
+
metafields: variant.metafields
|
|
183
|
+
},
|
|
184
|
+
product,
|
|
185
|
+
path: product?.handle ? `/products/${product.handle}` : "",
|
|
186
|
+
discounts: [],
|
|
187
|
+
options: variant.selectedOptions?.map((opt) => ({
|
|
188
|
+
name: opt.name,
|
|
189
|
+
value: opt.value
|
|
190
|
+
}))
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function createMockCartFromLines(lines, existingCart) {
|
|
195
|
+
const normalizedLines = normalizeAddToCartLines(lines);
|
|
196
|
+
const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
|
|
197
|
+
const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
|
|
198
|
+
return {
|
|
199
|
+
id: existingCart?.id || "temp-cart-id",
|
|
200
|
+
customerId: existingCart?.customerId,
|
|
201
|
+
email: existingCart?.email,
|
|
202
|
+
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
203
|
+
currency: existingCart?.currency || { code: "USD" },
|
|
204
|
+
taxesIncluded: existingCart?.taxesIncluded,
|
|
205
|
+
lineItems: normalizedLines,
|
|
206
|
+
totallineItemsDiscount: 0,
|
|
207
|
+
orderDiscounts: 0,
|
|
208
|
+
lineItemsSubtotalPrice: subtotalPrice,
|
|
209
|
+
subtotalPrice,
|
|
210
|
+
totalPrice,
|
|
211
|
+
totalTaxAmount: 0,
|
|
212
|
+
discountCodes: existingCart?.discountCodes || [],
|
|
213
|
+
discountAllocations: [],
|
|
214
|
+
url: existingCart?.url || "",
|
|
215
|
+
ready: true,
|
|
216
|
+
customAttributes: existingCart?.customAttributes
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
145
220
|
// src/hooks/cart/utils/index.ts
|
|
146
221
|
var getQuery = () => {
|
|
147
222
|
const url = typeof window !== "undefined" ? window.location.search : "";
|
|
@@ -181,25 +256,25 @@ var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
|
|
|
181
256
|
return acc + (main_product?.spend_money_type === 1 /* ORIGIN_PRICE */ ? Number(line.subtotalAmount) || 0 : Number(line.totalAmount) || 0);
|
|
182
257
|
}, 0) || 0;
|
|
183
258
|
};
|
|
184
|
-
var
|
|
185
|
-
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
186
|
-
return safeParseJson(attr?.value ?? "") ?? {};
|
|
187
|
-
};
|
|
188
|
-
var isAttributesEqual = (attrs1 = [], attrs2 = []) => {
|
|
189
|
-
if (attrs1.length !== attrs2.length) return false;
|
|
190
|
-
const sorted1 = [...attrs1].sort((a, b) => a.key.localeCompare(b.key));
|
|
191
|
-
const sorted2 = [...attrs2].sort((a, b) => a.key.localeCompare(b.key));
|
|
192
|
-
return sorted1.every(
|
|
193
|
-
(attr, i) => attr.key === sorted2[i]?.key && attr.value === sorted2[i]?.value
|
|
194
|
-
);
|
|
195
|
-
};
|
|
196
|
-
var safeParseJson = (str) => {
|
|
259
|
+
var safeParse = (str) => {
|
|
197
260
|
try {
|
|
198
261
|
return JSON.parse(str);
|
|
199
262
|
} catch (err) {
|
|
200
263
|
return {};
|
|
201
264
|
}
|
|
202
265
|
};
|
|
266
|
+
var getDiscountEnvAttributeValue = (attributes = []) => {
|
|
267
|
+
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
268
|
+
return safeParse(attr?.value ?? "") ?? {};
|
|
269
|
+
};
|
|
270
|
+
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
271
|
+
return oldAttributes.some((attr) => {
|
|
272
|
+
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
273
|
+
return newAttr ? newAttr.value !== attr.value : true;
|
|
274
|
+
}) || newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || customAttributesNeedRemove.some(
|
|
275
|
+
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
276
|
+
);
|
|
277
|
+
};
|
|
203
278
|
var containsAll = (source, requiredItems = []) => {
|
|
204
279
|
if (!requiredItems?.length) return true;
|
|
205
280
|
const sourceSet = new Set(source);
|
|
@@ -366,12 +441,18 @@ var formatFunctionAutoFreeGift = ({
|
|
|
366
441
|
};
|
|
367
442
|
return result;
|
|
368
443
|
};
|
|
369
|
-
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
444
|
+
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
370
445
|
const tags = react.useMemo(() => customer?.tags || [], [customer?.tags]);
|
|
371
446
|
const isCustomerLoading = react.useMemo(() => !customer ? true : false, [customer]);
|
|
372
447
|
const dealsType = "";
|
|
373
448
|
const { client, locale } = useShopify();
|
|
374
449
|
const giftProductsCache = react.useRef(null);
|
|
450
|
+
const effectiveCart = react.useMemo(() => {
|
|
451
|
+
if (lines && lines.length > 0) {
|
|
452
|
+
return createMockCartFromLines(lines, cart);
|
|
453
|
+
}
|
|
454
|
+
return cart;
|
|
455
|
+
}, [lines, cart]);
|
|
375
456
|
const { activeCampaign, subtotal } = react.useMemo(() => {
|
|
376
457
|
for (const campaign of autoFreeGiftConfig) {
|
|
377
458
|
const { rule_conditions = [], rule_result } = campaign;
|
|
@@ -379,7 +460,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
379
460
|
const isPreCheckPassed = preCheck(rule_conditions, tags, []);
|
|
380
461
|
if (isPreCheckPassed && spend_get_reward) {
|
|
381
462
|
const matchedSubtotal = getMatchedMainProductSubTotal(
|
|
382
|
-
|
|
463
|
+
effectiveCart,
|
|
383
464
|
spend_get_reward.main_product?.variant_list?.map((v) => v.variant_id) || [],
|
|
384
465
|
{
|
|
385
466
|
spend_money_type: spend_get_reward.main_product?.spend_money_type || 1,
|
|
@@ -393,7 +474,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
393
474
|
}
|
|
394
475
|
}
|
|
395
476
|
return { activeCampaign: null, subtotal: 0 };
|
|
396
|
-
}, [autoFreeGiftConfig,
|
|
477
|
+
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
397
478
|
const { qualifyingGift, nextTierGoal } = react.useMemo(() => {
|
|
398
479
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
399
480
|
return { qualifyingGift: null, nextTierGoal: null };
|
|
@@ -476,18 +557,33 @@ var useScriptAutoFreeGift = ({
|
|
|
476
557
|
campaign,
|
|
477
558
|
_giveaway,
|
|
478
559
|
cart,
|
|
479
|
-
locale: providedLocale
|
|
560
|
+
locale: providedLocale,
|
|
561
|
+
lines
|
|
480
562
|
}) => {
|
|
481
563
|
const { client, locale: contextLocale } = useShopify();
|
|
482
564
|
const locale = providedLocale || contextLocale;
|
|
483
565
|
const [points_subscribe, set_points_subscribe] = react.useState(false);
|
|
484
566
|
const giftProductsCache = react.useRef(null);
|
|
567
|
+
const effectiveCart = react.useMemo(() => {
|
|
568
|
+
if (lines && lines.length > 0) {
|
|
569
|
+
return createMockCartFromLines(lines, cart);
|
|
570
|
+
}
|
|
571
|
+
return cart;
|
|
572
|
+
}, [lines, cart]);
|
|
485
573
|
react.useEffect(() => {
|
|
486
574
|
if (locale === "au") {
|
|
487
575
|
const isPointsSubscribe = Cookies5__default.default.get("points_subscribe");
|
|
488
576
|
set_points_subscribe(!!isPointsSubscribe);
|
|
489
577
|
}
|
|
490
578
|
}, [locale]);
|
|
579
|
+
const isActivityAvailable = react.useMemo(() => {
|
|
580
|
+
if (!campaign) return false;
|
|
581
|
+
const query = getQuery();
|
|
582
|
+
const utmCampaign = Cookies5__default.default.get("utm_campaign") || query?.utm_campaign;
|
|
583
|
+
if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
|
|
584
|
+
return false;
|
|
585
|
+
return true;
|
|
586
|
+
}, [campaign]);
|
|
491
587
|
const [upgrade_multiple, upgrade_value] = react.useMemo(() => {
|
|
492
588
|
let upgrade_multiple2 = 1;
|
|
493
589
|
let upgrade_value2 = 0;
|
|
@@ -495,17 +591,17 @@ var useScriptAutoFreeGift = ({
|
|
|
495
591
|
upgrade_multiple2 = 1.2;
|
|
496
592
|
upgrade_value2 = 40;
|
|
497
593
|
}
|
|
498
|
-
|
|
594
|
+
effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
|
|
499
595
|
customAttributes?.forEach(({ key, value }) => {
|
|
500
596
|
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
501
597
|
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
502
598
|
});
|
|
503
599
|
});
|
|
504
600
|
return [upgrade_multiple2, upgrade_value2];
|
|
505
|
-
}, [
|
|
601
|
+
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
506
602
|
const breakpoints = react.useMemo(() => {
|
|
507
|
-
if (!
|
|
508
|
-
return (campaign
|
|
603
|
+
if (!isActivityAvailable) return [];
|
|
604
|
+
return (campaign?.breakpoints || []).map((item) => ({
|
|
509
605
|
breakpoint: new Decimal2__default.default(item.breakpoint).minus(new Decimal2__default.default(upgrade_value)).dividedBy(new Decimal2__default.default(upgrade_multiple)).toFixed(2, Decimal2__default.default.ROUND_DOWN),
|
|
510
606
|
giveawayProducts: item.giveawayProducts || []
|
|
511
607
|
}));
|
|
@@ -529,25 +625,26 @@ var useScriptAutoFreeGift = ({
|
|
|
529
625
|
return true;
|
|
530
626
|
}, [giftHandles]);
|
|
531
627
|
const involvedLines = react.useMemo(() => {
|
|
532
|
-
if (!
|
|
533
|
-
return (
|
|
628
|
+
if (!isActivityAvailable) return [];
|
|
629
|
+
return (effectiveCart?.lineItems || []).filter((line) => {
|
|
534
630
|
const isNotGift = line?.totalAmount && Number(line.totalAmount) > 0 && line.customAttributes?.every(
|
|
535
631
|
(item) => item.key !== _giveaway
|
|
536
632
|
);
|
|
537
633
|
const hasCampaignTag = line.product?.tags?.some(
|
|
538
|
-
(tag) => campaign
|
|
634
|
+
(tag) => campaign?.includeTags?.includes(tag.trim()) && line.variant?.availableForSale
|
|
539
635
|
);
|
|
540
636
|
return isNotGift && hasCampaignTag;
|
|
541
637
|
});
|
|
542
|
-
}, [
|
|
638
|
+
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
543
639
|
const involvedSubTotal = react.useMemo(() => {
|
|
544
|
-
if (!
|
|
640
|
+
if (!isActivityAvailable) return new Decimal2__default.default(0);
|
|
545
641
|
return involvedLines.reduce((prev, item) => {
|
|
546
|
-
const amount = campaign
|
|
642
|
+
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
547
643
|
return new Decimal2__default.default(prev).plus(new Decimal2__default.default(amount || 0));
|
|
548
644
|
}, new Decimal2__default.default(0));
|
|
549
|
-
}, [involvedLines,
|
|
645
|
+
}, [involvedLines, isActivityAvailable]);
|
|
550
646
|
const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
|
|
647
|
+
if (!isActivityAvailable) return [null, null];
|
|
551
648
|
const sortedLevels = [...breakpoints].sort(
|
|
552
649
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
553
650
|
);
|
|
@@ -691,8 +788,12 @@ var trackAddToCartGA = ({
|
|
|
691
788
|
}
|
|
692
789
|
const { variant } = lineItems[0];
|
|
693
790
|
const currencyCode = variant.product?.price?.currencyCode;
|
|
694
|
-
const
|
|
695
|
-
|
|
791
|
+
const totalPrice = lineItems?.reduce(
|
|
792
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
793
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? variant2?.price?.amount ?? 0
|
|
794
|
+
),
|
|
795
|
+
new Decimal2__default.default(0)
|
|
796
|
+
).toNumber();
|
|
696
797
|
gaTrack({
|
|
697
798
|
event: "ga4Event",
|
|
698
799
|
event_name: "add_to_cart",
|
|
@@ -707,7 +808,7 @@ var trackAddToCartGA = ({
|
|
|
707
808
|
item_brand: gtmParams?.brand || "",
|
|
708
809
|
item_category: variant2?.product?.productType || "",
|
|
709
810
|
item_variant: variant2?.title || variant2?.title,
|
|
710
|
-
price,
|
|
811
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
711
812
|
quantity: quantity || 1
|
|
712
813
|
})),
|
|
713
814
|
...gtmParams?.ga4Params
|
|
@@ -722,9 +823,12 @@ var trackBeginCheckoutGA = ({
|
|
|
722
823
|
if (!lineItems.length) {
|
|
723
824
|
return;
|
|
724
825
|
}
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
826
|
+
const totalPrice = lineItems?.reduce(
|
|
827
|
+
(prev, { variant }) => prev.plus(
|
|
828
|
+
variant?.finalPrice?.amount ?? variant?.compareAtPrice?.amount ?? variant?.price?.amount ?? 0
|
|
829
|
+
),
|
|
830
|
+
new Decimal2__default.default(0)
|
|
831
|
+
).toNumber();
|
|
728
832
|
gaTrack({
|
|
729
833
|
event: "ga4Event",
|
|
730
834
|
event_name: "begin_checkout",
|
|
@@ -739,7 +843,7 @@ var trackBeginCheckoutGA = ({
|
|
|
739
843
|
item_brand: gtmParams?.brand || "",
|
|
740
844
|
item_category: item.variant?.product?.productType,
|
|
741
845
|
item_variant: item.variant?.title,
|
|
742
|
-
price,
|
|
846
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
743
847
|
quantity: item.quantity || 1
|
|
744
848
|
})),
|
|
745
849
|
...gtmParams?.ga4Params
|
|
@@ -755,8 +859,12 @@ var trackBuyNowGA = ({
|
|
|
755
859
|
}
|
|
756
860
|
const { variant } = lineItems[0];
|
|
757
861
|
const currencyCode = variant.price?.currencyCode;
|
|
758
|
-
const
|
|
759
|
-
|
|
862
|
+
const totalPrice = lineItems?.reduce(
|
|
863
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
864
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? (variant2?.price?.amount || 0)
|
|
865
|
+
),
|
|
866
|
+
new Decimal2__default.default(0)
|
|
867
|
+
).toNumber();
|
|
760
868
|
gaTrack({
|
|
761
869
|
event: "ga4Event",
|
|
762
870
|
event_name: "begin_checkout",
|
|
@@ -771,7 +879,7 @@ var trackBuyNowGA = ({
|
|
|
771
879
|
item_brand: gtmParams?.brand || "",
|
|
772
880
|
item_category: item.variant?.product?.productType || "",
|
|
773
881
|
item_variant: item.variant?.title,
|
|
774
|
-
price,
|
|
882
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
775
883
|
quantity: item.quantity || 1
|
|
776
884
|
})),
|
|
777
885
|
...gtmParams?.ga4Params
|
|
@@ -914,6 +1022,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
914
1022
|
if (!resultCart) {
|
|
915
1023
|
return void 0;
|
|
916
1024
|
}
|
|
1025
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
917
1026
|
if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
918
1027
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
919
1028
|
if (unapplicableCodes.length > 0) {
|
|
@@ -1087,6 +1196,60 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
|
1087
1196
|
);
|
|
1088
1197
|
return useSWRMutation__default.default("buy-now", buyNow, swrOptions);
|
|
1089
1198
|
}
|
|
1199
|
+
function useCalcGiftsFromLines({
|
|
1200
|
+
lines,
|
|
1201
|
+
customer,
|
|
1202
|
+
scriptGiveawayKey = CUSTOMER_SCRIPT_GIFT_KEY
|
|
1203
|
+
}) {
|
|
1204
|
+
const { locale } = useShopify();
|
|
1205
|
+
const { cart, autoFreeGiftConfig, gradientGiftsConfig } = useCartContext();
|
|
1206
|
+
const functionGift = useCalcAutoFreeGift(cart, autoFreeGiftConfig || [], customer, lines);
|
|
1207
|
+
const scriptGift = useScriptAutoFreeGift({
|
|
1208
|
+
campaign: gradientGiftsConfig || null,
|
|
1209
|
+
_giveaway: scriptGiveawayKey,
|
|
1210
|
+
cart,
|
|
1211
|
+
locale,
|
|
1212
|
+
lines
|
|
1213
|
+
});
|
|
1214
|
+
const allGiftLines = react.useMemo(() => {
|
|
1215
|
+
const functionGiftLines = functionGift.qualifyingGift?.itemsToAdd || [];
|
|
1216
|
+
const scriptGiftLines = scriptGift.freeGiftLevel ? scriptGift.freeGiftLevel.giveawayProducts.map((product) => {
|
|
1217
|
+
const giftProduct = scriptGift.giftProductsResult?.find(
|
|
1218
|
+
(p) => p.handle === product.handle
|
|
1219
|
+
);
|
|
1220
|
+
const variant = giftProduct?.variants?.[0];
|
|
1221
|
+
return {
|
|
1222
|
+
variant: {
|
|
1223
|
+
id: variant?.id || "",
|
|
1224
|
+
handle: product.handle,
|
|
1225
|
+
sku: product.sku
|
|
1226
|
+
},
|
|
1227
|
+
quantity: 1,
|
|
1228
|
+
attributes: [
|
|
1229
|
+
{
|
|
1230
|
+
key: scriptGiveawayKey,
|
|
1231
|
+
value: "true"
|
|
1232
|
+
}
|
|
1233
|
+
]
|
|
1234
|
+
};
|
|
1235
|
+
}).filter((item) => item.variant.id) : [];
|
|
1236
|
+
return [...functionGiftLines, ...scriptGiftLines];
|
|
1237
|
+
}, [
|
|
1238
|
+
functionGift.qualifyingGift,
|
|
1239
|
+
scriptGift.freeGiftLevel,
|
|
1240
|
+
scriptGift.giftProductsResult,
|
|
1241
|
+
scriptGiveawayKey
|
|
1242
|
+
]);
|
|
1243
|
+
const hasGifts = react.useMemo(() => {
|
|
1244
|
+
return allGiftLines.length > 0;
|
|
1245
|
+
}, [allGiftLines]);
|
|
1246
|
+
return {
|
|
1247
|
+
functionGift,
|
|
1248
|
+
scriptGift,
|
|
1249
|
+
allGiftLines,
|
|
1250
|
+
hasGifts
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1090
1253
|
|
|
1091
1254
|
// src/hooks/cart/types/order-discount.ts
|
|
1092
1255
|
var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
|
|
@@ -2592,11 +2755,43 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2592
2755
|
removeCartLines2
|
|
2593
2756
|
]);
|
|
2594
2757
|
}
|
|
2758
|
+
function useAddPlusMemberProductsToCart({
|
|
2759
|
+
cart,
|
|
2760
|
+
memberSetting,
|
|
2761
|
+
selectedPlusMemberMode,
|
|
2762
|
+
selectedPlusMemberProduct
|
|
2763
|
+
}) {
|
|
2764
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2765
|
+
cart,
|
|
2766
|
+
memberSetting
|
|
2767
|
+
});
|
|
2768
|
+
const plusMemberProduct = react.useMemo(() => {
|
|
2769
|
+
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2770
|
+
return void 0;
|
|
2771
|
+
}
|
|
2772
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2773
|
+
return void 0;
|
|
2774
|
+
}
|
|
2775
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2776
|
+
return void 0;
|
|
2777
|
+
}
|
|
2778
|
+
if (!selectedPlusMemberProduct) {
|
|
2779
|
+
return void 0;
|
|
2780
|
+
}
|
|
2781
|
+
return selectedPlusMemberProduct;
|
|
2782
|
+
}, [
|
|
2783
|
+
selectedPlusMemberMode,
|
|
2784
|
+
selectedPlusMemberProduct?.variant,
|
|
2785
|
+
selectedPlusMemberProduct?.product,
|
|
2786
|
+
hasMonthlyPlus,
|
|
2787
|
+
hasAnnualPlus
|
|
2788
|
+
]);
|
|
2789
|
+
return plusMemberProduct;
|
|
2790
|
+
}
|
|
2595
2791
|
var PlusMemberProvider = ({
|
|
2596
2792
|
variant,
|
|
2597
2793
|
product,
|
|
2598
|
-
|
|
2599
|
-
metafields,
|
|
2794
|
+
memberSetting,
|
|
2600
2795
|
initialSelectedPlusMemberMode = "free",
|
|
2601
2796
|
profile,
|
|
2602
2797
|
locale,
|
|
@@ -2616,14 +2811,14 @@ var PlusMemberProvider = ({
|
|
|
2616
2811
|
const [deleteMarginBottom, setDeleteMarginBottom] = react.useState(false);
|
|
2617
2812
|
const shippingMethodsContext = useShippingMethods({
|
|
2618
2813
|
variant,
|
|
2619
|
-
plusMemberMetafields:
|
|
2814
|
+
plusMemberMetafields: memberSetting,
|
|
2620
2815
|
selectedPlusMemberMode});
|
|
2621
2816
|
const plusMemberHandles = react.useMemo(() => {
|
|
2622
2817
|
return [
|
|
2623
|
-
|
|
2624
|
-
|
|
2818
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2819
|
+
memberSetting?.plus_annual_product?.handle
|
|
2625
2820
|
].filter(Boolean);
|
|
2626
|
-
}, [
|
|
2821
|
+
}, [memberSetting]);
|
|
2627
2822
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2628
2823
|
handles: plusMemberHandles
|
|
2629
2824
|
});
|
|
@@ -2631,25 +2826,24 @@ var PlusMemberProvider = ({
|
|
|
2631
2826
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2632
2827
|
return null;
|
|
2633
2828
|
}
|
|
2634
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2635
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2829
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2830
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2636
2831
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2637
2832
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2638
2833
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2639
|
-
}, [plusMemberProducts,
|
|
2834
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2640
2835
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2641
2836
|
PlusMemberContext.Provider,
|
|
2642
2837
|
{
|
|
2643
2838
|
value: {
|
|
2644
2839
|
variant,
|
|
2645
|
-
shopCommon,
|
|
2646
2840
|
zipCode,
|
|
2647
2841
|
setZipCode,
|
|
2648
2842
|
allowNextDayDelivery,
|
|
2649
2843
|
setAllowNextDayDelivery,
|
|
2650
2844
|
allowThirdDayDelivery,
|
|
2651
2845
|
setAllowThirdDayDelivery,
|
|
2652
|
-
plusMemberMetafields:
|
|
2846
|
+
plusMemberMetafields: memberSetting,
|
|
2653
2847
|
selectedPlusMemberMode,
|
|
2654
2848
|
setSelectedPlusMemberMode,
|
|
2655
2849
|
showAreaCheckModal,
|
|
@@ -2868,6 +3062,9 @@ function CartProvider({
|
|
|
2868
3062
|
}) {
|
|
2869
3063
|
const { client, cartCookieAdapter } = useShopify();
|
|
2870
3064
|
const [customAttributes, setCustomAttributes] = react.useState([]);
|
|
3065
|
+
const [customAttributesNeedDelete, setCustomAttributesNeedDelete] = react.useState(
|
|
3066
|
+
[]
|
|
3067
|
+
);
|
|
2871
3068
|
const [isCodeChanging, setIsCodeChanging] = react.useState(false);
|
|
2872
3069
|
const [loadingState, setLoadingState] = react.useState({
|
|
2873
3070
|
editLineQuantityLoading: false,
|
|
@@ -2898,7 +3095,11 @@ function CartProvider({
|
|
|
2898
3095
|
ahooks.useRequest(
|
|
2899
3096
|
() => {
|
|
2900
3097
|
const newAttributes = [...attributes, ...customAttributes];
|
|
2901
|
-
const needUpdate = cart && !
|
|
3098
|
+
const needUpdate = cart && !checkAttributesUpdateNeeded(
|
|
3099
|
+
cart.customAttributes,
|
|
3100
|
+
newAttributes,
|
|
3101
|
+
customAttributesNeedDelete
|
|
3102
|
+
);
|
|
2902
3103
|
if (needUpdate) {
|
|
2903
3104
|
return updateAttributes({ attributes: newAttributes });
|
|
2904
3105
|
} else {
|
|
@@ -2919,11 +3120,12 @@ function CartProvider({
|
|
|
2919
3120
|
isCartLoading: isCartLoading || isCodeChanging,
|
|
2920
3121
|
setLoadingState
|
|
2921
3122
|
});
|
|
2922
|
-
const removeCustomAttributes = react.useCallback(
|
|
2923
|
-
|
|
2924
|
-
(
|
|
2925
|
-
|
|
2926
|
-
|
|
3123
|
+
const removeCustomAttributes = react.useCallback(
|
|
3124
|
+
(attributes2) => {
|
|
3125
|
+
setCustomAttributesNeedDelete(attributes2);
|
|
3126
|
+
},
|
|
3127
|
+
[setCustomAttributesNeedDelete]
|
|
3128
|
+
);
|
|
2927
3129
|
const addCustomAttributes = react.useCallback(
|
|
2928
3130
|
(attributes2) => {
|
|
2929
3131
|
const sameAttributes = attributes2.filter(
|
|
@@ -3010,6 +3212,7 @@ function CartProvider({
|
|
|
3010
3212
|
isCodeChanging,
|
|
3011
3213
|
setIsCodeChanging,
|
|
3012
3214
|
autoFreeGiftConfig,
|
|
3215
|
+
gradientGiftsConfig,
|
|
3013
3216
|
setLoadingState,
|
|
3014
3217
|
loadingState,
|
|
3015
3218
|
// function满赠
|
|
@@ -3033,6 +3236,7 @@ function CartProvider({
|
|
|
3033
3236
|
locale,
|
|
3034
3237
|
isCodeChanging,
|
|
3035
3238
|
autoFreeGiftConfig,
|
|
3239
|
+
gradientGiftsConfig,
|
|
3036
3240
|
loadingState,
|
|
3037
3241
|
// function满赠
|
|
3038
3242
|
functionAutoFreeGift,
|
|
@@ -3105,7 +3309,9 @@ exports.atobID = atobID;
|
|
|
3105
3309
|
exports.browserCartCookieAdapter = browserCartCookieAdapter;
|
|
3106
3310
|
exports.browserCookieAdapter = browserCookieAdapter;
|
|
3107
3311
|
exports.btoaID = btoaID;
|
|
3312
|
+
exports.checkAttributesUpdateNeeded = checkAttributesUpdateNeeded;
|
|
3108
3313
|
exports.clearGeoLocationCache = clearGeoLocationCache;
|
|
3314
|
+
exports.createMockCartFromLines = createMockCartFromLines;
|
|
3109
3315
|
exports.currencyCodeMapping = currencyCodeMapping;
|
|
3110
3316
|
exports.defaultSWRMutationConfiguration = defaultSWRMutationConfiguration;
|
|
3111
3317
|
exports.formatFunctionAutoFreeGift = formatFunctionAutoFreeGift;
|
|
@@ -3116,15 +3322,16 @@ exports.getDiscountEnvAttributeValue = getDiscountEnvAttributeValue;
|
|
|
3116
3322
|
exports.getMatchedMainProductSubTotal = getMatchedMainProductSubTotal;
|
|
3117
3323
|
exports.getQuery = getQuery;
|
|
3118
3324
|
exports.getReferralAttributes = getReferralAttributes;
|
|
3119
|
-
exports.
|
|
3325
|
+
exports.normalizeAddToCartLines = normalizeAddToCartLines;
|
|
3120
3326
|
exports.preCheck = preCheck;
|
|
3121
|
-
exports.
|
|
3327
|
+
exports.safeParse = safeParse;
|
|
3122
3328
|
exports.trackAddToCartFBQ = trackAddToCartFBQ;
|
|
3123
3329
|
exports.trackAddToCartGA = trackAddToCartGA;
|
|
3124
3330
|
exports.trackBeginCheckoutGA = trackBeginCheckoutGA;
|
|
3125
3331
|
exports.trackBuyNowFBQ = trackBuyNowFBQ;
|
|
3126
3332
|
exports.trackBuyNowGA = trackBuyNowGA;
|
|
3127
3333
|
exports.useAddCartLines = useAddCartLines;
|
|
3334
|
+
exports.useAddPlusMemberProductsToCart = useAddPlusMemberProductsToCart;
|
|
3128
3335
|
exports.useAddToCart = useAddToCart;
|
|
3129
3336
|
exports.useAllBlogs = useAllBlogs;
|
|
3130
3337
|
exports.useAllCollections = useAllCollections;
|
|
@@ -3137,6 +3344,7 @@ exports.useAutoRemovePlusMemberInCart = useAutoRemovePlusMemberInCart;
|
|
|
3137
3344
|
exports.useBlog = useBlog;
|
|
3138
3345
|
exports.useBuyNow = useBuyNow;
|
|
3139
3346
|
exports.useCalcAutoFreeGift = useCalcAutoFreeGift;
|
|
3347
|
+
exports.useCalcGiftsFromLines = useCalcGiftsFromLines;
|
|
3140
3348
|
exports.useCalcOrderDiscount = useCalcOrderDiscount;
|
|
3141
3349
|
exports.useCartAttributes = useCartAttributes;
|
|
3142
3350
|
exports.useCartContext = useCartContext;
|