@anker-in/shopify-react 0.1.1-beta.0

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.
@@ -0,0 +1,2890 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var useSWRMutation = require('swr/mutation');
5
+ var shopifySdk = require('@anker-in/shopify-sdk');
6
+ var Cookies5 = require('js-cookie');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+ var Decimal2 = require('decimal.js');
9
+ var useSWR = require('swr');
10
+ var ahooks = require('ahooks');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
15
+ var Cookies5__default = /*#__PURE__*/_interopDefault(Cookies5);
16
+ var Decimal2__default = /*#__PURE__*/_interopDefault(Decimal2);
17
+ var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
18
+
19
+ // src/hooks/cart/use-create-cart.ts
20
+ var ShopifyContext = react.createContext(null);
21
+ function useShopify() {
22
+ const context = react.useContext(ShopifyContext);
23
+ if (!context) {
24
+ throw new Error("useShopify must be used within a ShopifyProvider");
25
+ }
26
+ return context;
27
+ }
28
+
29
+ // src/hooks/cart/types/auto-free-gift.ts
30
+ var RuleType = /* @__PURE__ */ ((RuleType2) => {
31
+ RuleType2[RuleType2["AUTO_FREE_GIFT"] = 1] = "AUTO_FREE_GIFT";
32
+ RuleType2[RuleType2["BUNDLE"] = 2] = "BUNDLE";
33
+ RuleType2[RuleType2["VOLUME_DISCOUNT"] = 3] = "VOLUME_DISCOUNT";
34
+ RuleType2[RuleType2["ORDER_DISCOUNT"] = 4] = "ORDER_DISCOUNT";
35
+ RuleType2[RuleType2["PRICE_DISCOUNT"] = 5] = "PRICE_DISCOUNT";
36
+ return RuleType2;
37
+ })(RuleType || {});
38
+ var BuyRuleType = /* @__PURE__ */ ((BuyRuleType2) => {
39
+ BuyRuleType2[BuyRuleType2["BUY_GET_GIFT"] = 1] = "BUY_GET_GIFT";
40
+ BuyRuleType2[BuyRuleType2["SPEND_GET_GIFT"] = 2] = "SPEND_GET_GIFT";
41
+ return BuyRuleType2;
42
+ })(BuyRuleType || {});
43
+ var SpendMoneyType = /* @__PURE__ */ ((SpendMoneyType2) => {
44
+ SpendMoneyType2[SpendMoneyType2["ORIGIN_PRICE"] = 1] = "ORIGIN_PRICE";
45
+ SpendMoneyType2[SpendMoneyType2["DISCOUNT_PRICE"] = 2] = "DISCOUNT_PRICE";
46
+ return SpendMoneyType2;
47
+ })(SpendMoneyType || {});
48
+
49
+ // src/hooks/cart/const.ts
50
+ var currencyCodeMapping = {
51
+ us: "USD",
52
+ ca: "CAD",
53
+ gb: "GBP",
54
+ eu: "EUR",
55
+ au: "AUD",
56
+ nz: "NZD",
57
+ de: "EUR",
58
+ fr: "EUR",
59
+ es: "EUR",
60
+ it: "EUR",
61
+ nl: "EUR",
62
+ pl: "EUR",
63
+ ro: "EUR"
64
+ };
65
+ var defaultSWRMutationConfiguration = {
66
+ throwOnError: false
67
+ };
68
+ var CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
69
+ var CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
70
+ var CODE_AMOUNT_KEY = "_sku_code_money";
71
+ var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
72
+ var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
73
+
74
+ // src/hooks/cart/utils/index.ts
75
+ var getQuery = () => {
76
+ const url = typeof window !== "undefined" ? window.location.search : "";
77
+ const theRequest = {};
78
+ if (url.indexOf("?") != -1) {
79
+ const str = url.substr(1), strs = str.split("&");
80
+ for (let i = 0; i < strs.length; i++) {
81
+ const parts = strs[i]?.split("=");
82
+ const key = parts?.[0];
83
+ const value = parts?.[1];
84
+ if (key && value) {
85
+ theRequest[key] = decodeURIComponent(value);
86
+ }
87
+ }
88
+ }
89
+ return theRequest;
90
+ };
91
+ function atobID(id) {
92
+ if (id && typeof id === "string" && id.includes("/")) {
93
+ return id.split("/").pop()?.split("?")?.shift();
94
+ } else {
95
+ return id;
96
+ }
97
+ }
98
+ function btoaID(id, type = "ProductVariant") {
99
+ return `gid://shopify/${type}/${id}`;
100
+ }
101
+ var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
102
+ const isAllStoreVariant = main_product?.all_store_variant ?? false;
103
+ const matchedList = cartData?.lineItems?.filter((line) => {
104
+ const { is_gift } = getDiscountEnvAttributeValue(line.customAttributes);
105
+ return isAllStoreVariant ? !is_gift : variant_list?.find((item) => {
106
+ return !is_gift && atobID(line.variantId) === item;
107
+ });
108
+ });
109
+ return matchedList?.reduce((acc, line) => {
110
+ return acc + (main_product?.spend_money_type === 1 /* ORIGIN_PRICE */ ? Number(line.subtotalAmount) || 0 : Number(line.totalAmount) || 0);
111
+ }, 0) || 0;
112
+ };
113
+ var getDiscountEnvAttributeValue = (attributes = []) => {
114
+ const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
115
+ return safeParseJson(attr?.value ?? "") ?? {};
116
+ };
117
+ var isAttributesEqual = (attrs1 = [], attrs2 = []) => {
118
+ if (attrs1.length !== attrs2.length) return false;
119
+ const sorted1 = [...attrs1].sort((a, b) => a.key.localeCompare(b.key));
120
+ const sorted2 = [...attrs2].sort((a, b) => a.key.localeCompare(b.key));
121
+ return sorted1.every(
122
+ (attr, i) => attr.key === sorted2[i]?.key && attr.value === sorted2[i]?.value
123
+ );
124
+ };
125
+ var safeParseJson = (str) => {
126
+ try {
127
+ return JSON.parse(str);
128
+ } catch (err) {
129
+ return {};
130
+ }
131
+ };
132
+ var containsAll = (source, requiredItems = []) => {
133
+ if (!requiredItems?.length) return true;
134
+ const sourceSet = new Set(source);
135
+ return requiredItems.every((item) => sourceSet.has(item));
136
+ };
137
+ var containsNone = (source, forbiddenItems = []) => {
138
+ if (!forbiddenItems?.length) return true;
139
+ const sourceSet = new Set(source);
140
+ return !forbiddenItems.some((item) => sourceSet.has(item));
141
+ };
142
+ function preCheck(rule_conditions, userTags, currentDealsTypes) {
143
+ if (!Array.isArray(rule_conditions)) return false;
144
+ if (rule_conditions.length === 0) return true;
145
+ return rule_conditions.some((rule) => {
146
+ const tagsAreValid = containsAll(userTags, rule.with_user_tags) && containsNone(userTags, rule.without_user_tags);
147
+ const paramsAreValid = containsAll(currentDealsTypes, rule.with_special_url_params) && containsNone(currentDealsTypes, rule.without_special_url_params);
148
+ return tagsAreValid && paramsAreValid;
149
+ });
150
+ }
151
+ var formatScriptAutoFreeGiftCache = null;
152
+ var formatScriptAutoFreeGift = ({
153
+ scriptAutoFreeGiftResult,
154
+ gradient_gifts,
155
+ locale
156
+ }) => {
157
+ const cacheKey = JSON.stringify({
158
+ freeGiftLevel: scriptAutoFreeGiftResult?.freeGiftLevel ? {
159
+ items: scriptAutoFreeGiftResult.freeGiftLevel.giveawayProducts?.map((item) => ({
160
+ handle: item.handle,
161
+ sku: item.sku,
162
+ quantity: 1
163
+ })) || []
164
+ } : null,
165
+ giftProductsLength: scriptAutoFreeGiftResult?.giftProductsResult?.length || 0,
166
+ giftProductsIds: scriptAutoFreeGiftResult?.giftProductsResult?.map((p) => p.id).sort() || [],
167
+ gradientGiftsId: gradient_gifts?.id || gradient_gifts?.name || "",
168
+ locale
169
+ });
170
+ if (formatScriptAutoFreeGiftCache && formatScriptAutoFreeGiftCache.key === cacheKey) {
171
+ return formatScriptAutoFreeGiftCache.result;
172
+ }
173
+ const result = scriptAutoFreeGiftResult?.freeGiftLevel?.giveawayProducts?.filter(
174
+ (item) => scriptAutoFreeGiftResult?.giftProductsResult?.some(
175
+ (product) => product.handle === item.handle
176
+ )
177
+ ).map((item, index) => {
178
+ const product = scriptAutoFreeGiftResult?.giftProductsResult?.find(
179
+ (product2) => product2.handle === item.handle
180
+ );
181
+ const variants = product?.variants;
182
+ const variant = Array.isArray(variants) ? variants.find((v) => v.sku === item.sku) : void 0;
183
+ const query = getQuery();
184
+ const utmCampaign = Cookies5__default.default.get("utm_campaign") || query?.utm_campaign;
185
+ const addUTMFreeItem = gradient_gifts.activityAvailableQuery && utmCampaign?.includes(gradient_gifts.activityAvailableQuery);
186
+ let points_subscribe = false;
187
+ if (locale === "au") {
188
+ const isPointsSubscribe = Cookies5__default.default.get("points_subscribe");
189
+ points_subscribe = !!isPointsSubscribe;
190
+ }
191
+ const customAttributes = [
192
+ {
193
+ key: "_giveaway_gradient_gifts",
194
+ value: "_giveaway_gradient_gifts"
195
+ },
196
+ ...points_subscribe ? [
197
+ { key: "_amount_upgrade_multiple", value: "1.2" },
198
+ { key: "_amount_upgrade_value", value: "40" }
199
+ ] : [],
200
+ ...addUTMFreeItem && gradient_gifts?.activityQroperty ? [
201
+ {
202
+ key: gradient_gifts.activityQroperty,
203
+ value: gradient_gifts.activityQroperty
204
+ }
205
+ ] : []
206
+ ];
207
+ const line = {
208
+ id: product?.id + "_" + index,
209
+ variantId: String(variant?.id),
210
+ productId: String(product?.id),
211
+ name: product?.name || product?.title || "",
212
+ quantity: 1,
213
+ discounts: [],
214
+ path: product?.handle || "",
215
+ variant,
216
+ totalAmount: 0,
217
+ subtotalAmount: new Decimal2__default.default(
218
+ typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
219
+ ).toNumber(),
220
+ options: [],
221
+ discountAllocations: [],
222
+ product,
223
+ customAttributes,
224
+ freeGiftVariant: void 0,
225
+ relatedVariant: void 0
226
+ };
227
+ return {
228
+ line,
229
+ isSoldOut: !variant?.availableForSale
230
+ };
231
+ }) || [];
232
+ formatScriptAutoFreeGiftCache = {
233
+ key: cacheKey,
234
+ result
235
+ };
236
+ return result;
237
+ };
238
+ var formatFunctionAutoFreeGiftCache = null;
239
+ var formatFunctionAutoFreeGift = ({
240
+ qualifyingGift,
241
+ giftProductsResult,
242
+ locale
243
+ }) => {
244
+ const cacheKey = JSON.stringify({
245
+ qualifyingGift: qualifyingGift ? {
246
+ spend: qualifyingGift.tier?.spend_sum_money,
247
+ items: qualifyingGift.itemsToAdd?.map((item) => ({
248
+ variantId: item.variant.id,
249
+ handle: item.variant.handle,
250
+ sku: item.variant.sku,
251
+ quantity: item.quantity ?? 1,
252
+ attributes: item.attributes
253
+ })) || []
254
+ } : null,
255
+ giftProductsLength: giftProductsResult?.length || 0,
256
+ giftProductsIds: giftProductsResult?.map((p) => p.id).sort() || [],
257
+ locale
258
+ });
259
+ if (formatFunctionAutoFreeGiftCache && formatFunctionAutoFreeGiftCache.key === cacheKey) {
260
+ return formatFunctionAutoFreeGiftCache.result;
261
+ }
262
+ const result = qualifyingGift?.itemsToAdd?.map((item, index) => {
263
+ const product = giftProductsResult?.find((product2) => product2.handle === item.variant.handle);
264
+ const variants = product?.variants;
265
+ const variant = Array.isArray(variants) ? variants.find((v) => v.sku === item.variant.sku) : void 0;
266
+ console.log("qualifyingGift variant", product, variant);
267
+ const line = {
268
+ id: product?.id + "_" + index,
269
+ variantId: String(variant?.id),
270
+ productId: String(product?.id),
271
+ name: product?.name || product?.title || "",
272
+ quantity: 1,
273
+ discounts: [],
274
+ path: product?.handle || "",
275
+ variant,
276
+ totalAmount: 0,
277
+ subtotalAmount: new Decimal2__default.default(
278
+ typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
279
+ ).toNumber(),
280
+ options: [],
281
+ discountAllocations: [],
282
+ product,
283
+ customAttributes: item.attributes,
284
+ freeGiftVariant: void 0,
285
+ relatedVariant: void 0
286
+ };
287
+ return {
288
+ line,
289
+ isSoldOut: !variant?.availableForSale
290
+ };
291
+ }) || [];
292
+ formatFunctionAutoFreeGiftCache = {
293
+ key: cacheKey,
294
+ result
295
+ };
296
+ return result;
297
+ };
298
+ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
299
+ const tags = react.useMemo(() => customer?.tags || [], [customer?.tags]);
300
+ const isCustomerLoading = react.useMemo(() => !customer ? true : false, [customer]);
301
+ const dealsType = "";
302
+ const { client, locale } = useShopify();
303
+ const giftProductsCache = react.useRef(null);
304
+ const { activeCampaign, subtotal } = react.useMemo(() => {
305
+ for (const campaign of autoFreeGiftConfig) {
306
+ const { rule_conditions = [], rule_result } = campaign;
307
+ const { spend_get_reward } = rule_result || {};
308
+ const isPreCheckPassed = preCheck(rule_conditions, tags, []);
309
+ if (isPreCheckPassed && spend_get_reward) {
310
+ const matchedSubtotal = getMatchedMainProductSubTotal(
311
+ cart,
312
+ spend_get_reward.main_product?.variant_list?.map((v) => v.variant_id) || [],
313
+ {
314
+ spend_money_type: spend_get_reward.main_product?.spend_money_type || 1,
315
+ variant_id_list: spend_get_reward.main_product?.variant_list?.map((v) => v.variant_id) || [],
316
+ all_store_variant: spend_get_reward.main_product?.all_store_variant || false
317
+ }
318
+ );
319
+ if (matchedSubtotal > 0) {
320
+ return { activeCampaign: campaign, subtotal: matchedSubtotal };
321
+ }
322
+ }
323
+ }
324
+ return { activeCampaign: null, subtotal: 0 };
325
+ }, [autoFreeGiftConfig, cart, tags, dealsType]);
326
+ const { qualifyingGift, nextTierGoal } = react.useMemo(() => {
327
+ if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
328
+ return { qualifyingGift: null, nextTierGoal: null };
329
+ }
330
+ const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
331
+ const qualifyingTier = [...giftTiers].reverse().find((tier) => subtotal >= Number(tier.spend_sum_money));
332
+ const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
333
+ if (!qualifyingTier) {
334
+ return { qualifyingGift: null, nextTierGoal: nextGoal || null };
335
+ }
336
+ const formattedGift = {
337
+ tier: qualifyingTier,
338
+ itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
339
+ const giftProduct = reward?.variant_list?.[0];
340
+ if (!giftProduct) return null;
341
+ return {
342
+ variant: {
343
+ id: btoaID(giftProduct.variant_id),
344
+ handle: giftProduct.handle,
345
+ sku: giftProduct.sku
346
+ },
347
+ quantity: reward?.get_unit || 1,
348
+ attributes: [
349
+ {
350
+ key: CUSTOMER_ATTRIBUTE_KEY,
351
+ value: JSON.stringify({
352
+ is_gift: true,
353
+ rule_id: activeCampaign.rule_id,
354
+ spend_sum_money: qualifyingTier.spend_sum_money
355
+ })
356
+ }
357
+ ]
358
+ };
359
+ }).filter((item) => item !== null)
360
+ };
361
+ return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
362
+ }, [activeCampaign, subtotal]);
363
+ const giftHandles = react.useMemo(() => {
364
+ const giftVariant = autoFreeGiftConfig.map(
365
+ (item) => item.rule_result?.spend_get_reward?.gift_product?.map(
366
+ (v) => v.reward_list.map((reward) => reward.variant_list.map((variant) => variant.handle))
367
+ ).flat()
368
+ ).flat();
369
+ return giftVariant.flat(2).filter(Boolean);
370
+ }, [autoFreeGiftConfig]);
371
+ const shouldFetch = react.useMemo(() => {
372
+ if (!giftHandles.length) return false;
373
+ if (giftProductsCache.current && JSON.stringify(giftProductsCache.current.giftHandles) === JSON.stringify(giftHandles)) {
374
+ return false;
375
+ }
376
+ return true;
377
+ }, [giftHandles]);
378
+ const { data: giftProductsResult } = useSWR__default.default(shouldFetch ? giftHandles : null, async () => {
379
+ const res = await shopifySdk.getProductsByHandles(client, {
380
+ handles: giftHandles,
381
+ locale
382
+ });
383
+ const result = Array.isArray(res) ? res : [];
384
+ giftProductsCache.current = {
385
+ data: result,
386
+ giftHandles: [...giftHandles]
387
+ };
388
+ return result;
389
+ });
390
+ const finalGiftProductsResult = react.useMemo(() => {
391
+ if (giftProductsCache.current && !shouldFetch) {
392
+ return giftProductsCache.current.data || void 0;
393
+ }
394
+ return giftProductsResult;
395
+ }, [giftProductsResult, shouldFetch]);
396
+ return {
397
+ qualifyingGift,
398
+ nextTierGoal,
399
+ activeCampaign,
400
+ isLoading: isCustomerLoading,
401
+ giftProductsResult: finalGiftProductsResult
402
+ };
403
+ };
404
+ var useScriptAutoFreeGift = ({
405
+ campaign,
406
+ _giveaway,
407
+ cart,
408
+ locale: providedLocale
409
+ }) => {
410
+ const { client, locale: contextLocale } = useShopify();
411
+ const locale = providedLocale || contextLocale;
412
+ const [points_subscribe, set_points_subscribe] = react.useState(false);
413
+ const giftProductsCache = react.useRef(null);
414
+ react.useEffect(() => {
415
+ if (locale === "au") {
416
+ const isPointsSubscribe = Cookies5__default.default.get("points_subscribe");
417
+ set_points_subscribe(!!isPointsSubscribe);
418
+ }
419
+ }, [locale]);
420
+ const [upgrade_multiple, upgrade_value] = react.useMemo(() => {
421
+ let upgrade_multiple2 = 1;
422
+ let upgrade_value2 = 0;
423
+ if (points_subscribe) {
424
+ upgrade_multiple2 = 1.2;
425
+ upgrade_value2 = 40;
426
+ }
427
+ cart?.lineItems?.forEach(({ customAttributes }) => {
428
+ customAttributes?.forEach(({ key, value }) => {
429
+ if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
430
+ if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
431
+ });
432
+ });
433
+ return [upgrade_multiple2, upgrade_value2];
434
+ }, [cart?.lineItems, points_subscribe]);
435
+ const breakpoints = react.useMemo(() => {
436
+ if (!campaign) return [];
437
+ return (campaign.breakpoints || []).map((item) => ({
438
+ 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),
439
+ giveawayProducts: item.giveawayProducts || []
440
+ }));
441
+ }, [campaign, upgrade_multiple, upgrade_value]);
442
+ const giftHandles = react.useMemo(
443
+ () => (
444
+ // 使用 Set 去重,然后拼接字符串
445
+ [
446
+ ...new Set(
447
+ breakpoints.flatMap((b) => b.giveawayProducts.map((p) => p.handle)).filter(Boolean)
448
+ )
449
+ ]
450
+ ),
451
+ [breakpoints]
452
+ );
453
+ const shouldFetch = react.useMemo(() => {
454
+ if (!giftHandles.length) return false;
455
+ if (giftProductsCache.current && JSON.stringify(giftProductsCache.current.giftHandles) === JSON.stringify(giftHandles)) {
456
+ return false;
457
+ }
458
+ return true;
459
+ }, [giftHandles]);
460
+ const involvedLines = react.useMemo(() => {
461
+ if (!campaign) return [];
462
+ return (cart?.lineItems || []).filter((line) => {
463
+ const isNotGift = line?.totalAmount && Number(line.totalAmount) > 0 && line.customAttributes?.every(
464
+ (item) => item.key !== _giveaway
465
+ );
466
+ const hasCampaignTag = line.product?.tags?.some(
467
+ (tag) => campaign.includeTags?.includes(tag.trim()) && line.variant?.availableForSale
468
+ );
469
+ return isNotGift && hasCampaignTag;
470
+ });
471
+ }, [cart?.lineItems, campaign, _giveaway]);
472
+ const involvedSubTotal = react.useMemo(() => {
473
+ if (!campaign) return new Decimal2__default.default(0);
474
+ return involvedLines.reduce((prev, item) => {
475
+ const amount = campaign.useTotalAmount ? item.totalAmount : item.subtotalAmount;
476
+ return new Decimal2__default.default(prev).plus(new Decimal2__default.default(amount || 0));
477
+ }, new Decimal2__default.default(0));
478
+ }, [involvedLines, campaign]);
479
+ const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
480
+ const sortedLevels = [...breakpoints].sort(
481
+ (a, b) => Number(b.breakpoint) - Number(a.breakpoint)
482
+ );
483
+ const levelIndex = sortedLevels.findIndex(
484
+ (level) => involvedSubTotal.gte(new Decimal2__default.default(level.breakpoint)) && involvedLines.length > 0
485
+ );
486
+ if (levelIndex === -1) {
487
+ return [
488
+ null,
489
+ sortedLevels.length > 0 ? sortedLevels[sortedLevels.length - 1] ?? null : null
490
+ ];
491
+ }
492
+ const currentLevel = sortedLevels[levelIndex] ?? null;
493
+ const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
494
+ return [currentLevel, nextLevel];
495
+ }, [breakpoints, involvedSubTotal, involvedLines.length]);
496
+ const { data: giftProductsResult } = useSWR__default.default(shouldFetch ? giftHandles : null, async () => {
497
+ const res = await shopifySdk.getProductsByHandles(client, {
498
+ handles: giftHandles,
499
+ locale
500
+ });
501
+ const result = Array.isArray(res) ? res : [];
502
+ giftProductsCache.current = {
503
+ data: result,
504
+ giftHandles: [...giftHandles]
505
+ };
506
+ return result;
507
+ });
508
+ const finalGiftProductsResult = react.useMemo(() => {
509
+ if (giftProductsCache.current && !shouldFetch) {
510
+ return giftProductsCache.current.data || void 0;
511
+ }
512
+ return giftProductsResult;
513
+ }, [giftProductsResult, shouldFetch]);
514
+ const reorder = react.useCallback(
515
+ (a, b) => {
516
+ const getPriority = (item) => {
517
+ if (item.customAttributes?.some(
518
+ (attribute) => attribute.key === _giveaway
519
+ ))
520
+ return 0;
521
+ if (item.product?.tags?.some((tag) => campaign?.includeTags?.includes(tag)))
522
+ return 1;
523
+ return 2;
524
+ };
525
+ return getPriority(b) - getPriority(a);
526
+ },
527
+ [campaign?.includeTags, _giveaway]
528
+ );
529
+ return {
530
+ involvedLines,
531
+ reorder,
532
+ disableCodeRemove: involvedLines.length > 0,
533
+ nextFreeGiftLevel,
534
+ freeGiftLevel,
535
+ involvedSubTotal,
536
+ giftProductsResult: finalGiftProductsResult
537
+ };
538
+ };
539
+ var CartContext = react.createContext(null);
540
+ function useCartContext() {
541
+ const context = react.useContext(CartContext);
542
+ if (!context) {
543
+ throw new Error("useCartContext must be used within a CartProvider");
544
+ }
545
+ return context;
546
+ }
547
+
548
+ // src/hooks/cart/use-create-cart.ts
549
+ function useCreateCart(options) {
550
+ const { client, locale, cartCookieAdapter } = useShopify();
551
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
552
+ const createNewCart = react.useCallback(
553
+ async (_key, { arg }) => {
554
+ let newCart = await shopifySdk.createCart(client, {
555
+ ...arg,
556
+ metafieldIdentifiers,
557
+ cookieAdapter: cartCookieAdapter
558
+ });
559
+ if (newCart) {
560
+ const unApplicableCodes = newCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
561
+ if (unApplicableCodes.length > 0) {
562
+ newCart = await shopifySdk.updateCartCodes(client, {
563
+ cartId: newCart.id,
564
+ discountCodes: newCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
565
+ metafieldIdentifiers,
566
+ cookieAdapter: cartCookieAdapter
567
+ });
568
+ }
569
+ }
570
+ if (newCart) {
571
+ mutateCart(newCart);
572
+ }
573
+ return newCart;
574
+ },
575
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
576
+ );
577
+ return useSWRMutation__default.default("create-cart", createNewCart, options);
578
+ }
579
+ function useAddCartLines(options) {
580
+ const { client, locale, cartCookieAdapter } = useShopify();
581
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
582
+ const addLines = react.useCallback(
583
+ async (_key, { arg }) => {
584
+ let updatedCart = await shopifySdk.addCartLines(client, {
585
+ ...arg,
586
+ metafieldIdentifiers,
587
+ cookieAdapter: cartCookieAdapter
588
+ });
589
+ if (updatedCart) {
590
+ const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
591
+ if (unApplicableCodes.length > 0) {
592
+ updatedCart = await shopifySdk.updateCartCodes(client, {
593
+ cartId: updatedCart.id,
594
+ discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
595
+ metafieldIdentifiers,
596
+ cookieAdapter: cartCookieAdapter
597
+ });
598
+ }
599
+ }
600
+ if (updatedCart) {
601
+ mutateCart(updatedCart);
602
+ }
603
+ return updatedCart;
604
+ },
605
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
606
+ );
607
+ return useSWRMutation__default.default("add-cart-lines", addLines, options);
608
+ }
609
+
610
+ // src/tracking/ga.ts
611
+ var gaTrack = (data) => {
612
+ if (typeof window === "undefined") {
613
+ return;
614
+ }
615
+ window.dataLayer = window?.dataLayer || [];
616
+ if (!Array.isArray(window.dataLayer)) {
617
+ return;
618
+ }
619
+ try {
620
+ window?.dataLayer?.push({ event_parameters: null });
621
+ window?.dataLayer?.push(data || {});
622
+ } catch (error) {
623
+ console.error("GA tracking error:", error);
624
+ }
625
+ };
626
+ var trackAddToCartGA = ({
627
+ lineItems = [],
628
+ gtmParams = {},
629
+ brand
630
+ }) => {
631
+ if (!lineItems.length || !lineItems[0]?.variant) {
632
+ return;
633
+ }
634
+ const { variant } = lineItems[0];
635
+ const currencyCode = variant?.price?.currencyCode;
636
+ const totalPrice = lineItems.reduce((sum, item) => {
637
+ const price = parseFloat(item.variant?.price?.amount || "0");
638
+ return sum + price;
639
+ }, 0);
640
+ gaTrack({
641
+ event: "ga4Event",
642
+ event_name: "add_to_cart",
643
+ event_parameters: {
644
+ page_group: gtmParams?.pageGroup,
645
+ currency: currencyCode,
646
+ value: totalPrice,
647
+ position: gtmParams?.position || "",
648
+ items: lineItems.map(({ variant: variant2, quantity }) => ({
649
+ item_id: variant2?.sku,
650
+ item_name: variant2?.product?.title || variant2?.product?.name,
651
+ item_brand: brand || gtmParams?.brand || "",
652
+ item_category: variant2?.product?.productType || "",
653
+ item_variant: variant2?.title || variant2?.name,
654
+ price: variant2?.finalPrice?.amount ?? variant2?.price?.amount,
655
+ quantity: quantity || 1
656
+ })),
657
+ ...gtmParams?.ga4Params
658
+ }
659
+ });
660
+ };
661
+ var trackBuyNowGA = ({
662
+ lineItems = [],
663
+ gtmParams = {},
664
+ brand
665
+ }) => {
666
+ if (!lineItems.length || !lineItems[0]?.variant) {
667
+ return;
668
+ }
669
+ const { variant } = lineItems[0];
670
+ const currencyCode = variant.price?.currencyCode;
671
+ const totalPrice = lineItems.reduce((sum, item) => {
672
+ const price = parseFloat(item.finalPrice?.amount || item.variant?.price?.amount || "0");
673
+ const quantity = item.quantity || 1;
674
+ return sum + price * quantity;
675
+ }, 0);
676
+ gaTrack({
677
+ event: "ga4Event",
678
+ event_name: "begin_checkout",
679
+ event_parameters: {
680
+ page_group: gtmParams?.pageGroup,
681
+ position: gtmParams?.position,
682
+ currency: currencyCode,
683
+ value: totalPrice,
684
+ items: lineItems.map((item) => ({
685
+ item_id: item.variant?.sku,
686
+ item_name: item.variant?.product?.title || item.variant?.title,
687
+ item_brand: item.variant?.product?.vendor || brand || gtmParams?.brand || "",
688
+ item_category: item.variant?.product?.productType || "",
689
+ item_variant: item.variant?.title,
690
+ price: item.finalPrice?.amount || item.variant?.price?.amount,
691
+ quantity: item.quantity || 1
692
+ })),
693
+ ...gtmParams?.ga4Params
694
+ }
695
+ });
696
+ };
697
+
698
+ // src/tracking/fbq.ts
699
+ var trackAddToCartFBQ = ({ lineItems = [] }) => {
700
+ if (typeof window === "undefined" || !window.fbq) {
701
+ return;
702
+ }
703
+ if (lineItems.length && lineItems[0]?.variant) {
704
+ const { variant, quantity, finalPrice } = lineItems[0];
705
+ try {
706
+ window.fbq("track", "AddToCart", {
707
+ value: finalPrice?.amount || variant?.price?.amount,
708
+ num_items: quantity,
709
+ currency: variant?.price?.currencyCode,
710
+ content_name: variant?.product?.title,
711
+ content_type: "product_group",
712
+ content_ids: String(variant?.id),
713
+ content_category: variant?.product?.metafields?.global?.trafficType || "public"
714
+ });
715
+ } catch (error) {
716
+ console.error("FBQ tracking error:", error);
717
+ }
718
+ }
719
+ };
720
+ var trackBuyNowFBQ = ({ trackConfig }) => {
721
+ if (typeof window === "undefined") {
722
+ return;
723
+ }
724
+ try {
725
+ if (trackConfig?.fbqBuyNowEvent && window.fbq) {
726
+ window.fbq("trackCustom", trackConfig.fbqBuyNowEvent);
727
+ }
728
+ if (trackConfig?.gtagBuyNowLabel && trackConfig?.gtagId && window.gtag) {
729
+ window.gtag("event", trackConfig.gtagBuyNowConversion || "conversion", {
730
+ send_to: `${trackConfig.gtagId}/${trackConfig.gtagBuyNowLabel}`
731
+ });
732
+ }
733
+ } catch (error) {
734
+ console.error("Buy Now tracking error:", error);
735
+ }
736
+ };
737
+ function useApplyCartCodes(options) {
738
+ const { client, locale, cartCookieAdapter } = useShopify();
739
+ const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
740
+ const applyCodes = react.useCallback(
741
+ async (_key, { arg }) => {
742
+ const { cartId: providedCartId, discountCodes, replaceExistingCodes } = arg;
743
+ if (!discountCodes?.length) {
744
+ throw new Error("Invalid input used for this operation: Miss discountCode");
745
+ }
746
+ const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
747
+ if (!cartId) {
748
+ return void 0;
749
+ }
750
+ const updatedCart = await shopifySdk.updateCartCodes(client, {
751
+ cartId,
752
+ discountCodes: replaceExistingCodes ? discountCodes : [
753
+ ...discountCodes,
754
+ ...cart?.discountCodes?.filter((item) => item.applicable).map((item) => item.code) || []
755
+ ],
756
+ cookieAdapter: cartCookieAdapter,
757
+ metafieldIdentifiers
758
+ });
759
+ if (updatedCart) {
760
+ mutateCart(updatedCart);
761
+ }
762
+ return updatedCart;
763
+ },
764
+ [client, locale, cartCookieAdapter, mutateCart, cart]
765
+ );
766
+ return useSWRMutation__default.default("apply-codes", applyCodes, options);
767
+ }
768
+ function useRemoveCartCodes(options) {
769
+ const { client, locale, cartCookieAdapter } = useShopify();
770
+ const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
771
+ const removeCodes = react.useCallback(
772
+ async (_key, { arg }) => {
773
+ const { cartId: providedCartId, discountCodes } = arg;
774
+ const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
775
+ const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
776
+ const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
777
+ const updatedCart = await shopifySdk.updateCartCodes(client, {
778
+ cartId,
779
+ discountCodes: leftCodes,
780
+ metafieldIdentifiers,
781
+ cookieAdapter: cartCookieAdapter
782
+ });
783
+ if (updatedCart) {
784
+ mutateCart(updatedCart);
785
+ }
786
+ return updatedCart;
787
+ },
788
+ [client, locale, cartCookieAdapter, mutateCart, cart]
789
+ );
790
+ return useSWRMutation__default.default("remove-codes", removeCodes, options);
791
+ }
792
+
793
+ // src/hooks/cart/use-add-to-cart.ts
794
+ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
795
+ const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
796
+ const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
797
+ const { trigger: applyCartCodes } = useApplyCartCodes();
798
+ const { trigger: removeInvalidCodes } = useRemoveCartCodes();
799
+ const { trigger: addCartLines2 } = useAddCartLines();
800
+ const addToCart = react.useCallback(
801
+ async (_key, { arg }) => {
802
+ const {
803
+ lineItems,
804
+ cartId: providedCartId,
805
+ discountCodes,
806
+ gtmParams = {},
807
+ buyerIdentity,
808
+ needCreateCart = false,
809
+ onCodesInvalid,
810
+ replaceExistingCodes
811
+ } = arg;
812
+ if (!lineItems || lineItems.length === 0) {
813
+ return;
814
+ }
815
+ const lines = lineItems.map((item) => ({
816
+ merchandiseId: item.variant?.id || "",
817
+ quantity: item.quantity || 1,
818
+ attributes: item.attributes
819
+ })).filter((item) => item.merchandiseId && item.quantity);
820
+ if (lines.length === 0) {
821
+ return;
822
+ }
823
+ const cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
824
+ let resultCart = await addCartLines2({
825
+ cartId,
826
+ lines,
827
+ buyerIdentity
828
+ });
829
+ if (!resultCart) {
830
+ return void 0;
831
+ }
832
+ if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
833
+ const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
834
+ if (unapplicableCodes.length > 0) {
835
+ if (onCodesInvalid) {
836
+ const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
837
+ if (handledCart) {
838
+ resultCart = handledCart;
839
+ }
840
+ } else {
841
+ await removeInvalidCodes({
842
+ discountCodes: unapplicableCodes
843
+ });
844
+ }
845
+ }
846
+ }
847
+ if (discountCodes && discountCodes.length > 0) {
848
+ applyCartCodes({
849
+ replaceExistingCodes,
850
+ discountCodes
851
+ });
852
+ }
853
+ if (withTrack && resultCart.lineItems) {
854
+ const trackingLineItems = resultCart.lineItems.map((line) => ({
855
+ variant: {
856
+ id: line.variant.id,
857
+ sku: line.variant.sku || "",
858
+ title: line.variant.name,
859
+ price: {
860
+ amount: String(line.variant.price),
861
+ currencyCode: resultCart.currency.code
862
+ },
863
+ product: line.product ? {
864
+ title: line.product.title || line.name,
865
+ productType: line.product.productType,
866
+ vendor: line.product.vendor
867
+ } : void 0
868
+ },
869
+ quantity: line.quantity
870
+ }));
871
+ trackAddToCartGA({
872
+ lineItems: trackingLineItems,
873
+ gtmParams: { ...gtmParams, brand },
874
+ brand
875
+ });
876
+ trackAddToCartFBQ({ lineItems: trackingLineItems });
877
+ }
878
+ return resultCart;
879
+ },
880
+ [client, locale, cartCookieAdapter, userAdapter, cart, withTrack, brand]
881
+ );
882
+ return useSWRMutation__default.default("add-to-cart", addToCart, swrOptions);
883
+ }
884
+ function useUpdateCartLines(options) {
885
+ const { client, locale, cartCookieAdapter } = useShopify();
886
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
887
+ const updateLines = react.useCallback(
888
+ async (_key, { arg }) => {
889
+ const updatedCart = await shopifySdk.updateCartLines(client, {
890
+ ...arg,
891
+ metafieldIdentifiers,
892
+ cookieAdapter: cartCookieAdapter
893
+ });
894
+ if (updatedCart) {
895
+ mutateCart(updatedCart);
896
+ }
897
+ return updatedCart;
898
+ },
899
+ [client, locale, cartCookieAdapter, mutateCart]
900
+ );
901
+ return useSWRMutation__default.default("update-cart-lines", updateLines, options);
902
+ }
903
+ function useRemoveCartLines(options) {
904
+ const { client, locale, cartCookieAdapter } = useShopify();
905
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
906
+ const removeLines = react.useCallback(
907
+ async (_key, { arg }) => {
908
+ const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
909
+ let updatedCart = await shopifySdk.removeCartLines(client, {
910
+ cartId,
911
+ lineIds,
912
+ metafieldIdentifiers,
913
+ cookieAdapter: cartCookieAdapter
914
+ });
915
+ if (updatedCart && autoRemoveInvalidCodes) {
916
+ const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
917
+ if (unApplicableCodes.length > 0) {
918
+ if (onCodesRemoved) {
919
+ const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
920
+ if (handledCart) {
921
+ updatedCart = handledCart;
922
+ }
923
+ } else {
924
+ updatedCart = await shopifySdk.updateCartCodes(client, {
925
+ cartId: updatedCart.id,
926
+ discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
927
+ metafieldIdentifiers,
928
+ cookieAdapter: cartCookieAdapter
929
+ }) || updatedCart;
930
+ }
931
+ }
932
+ }
933
+ if (updatedCart) {
934
+ mutateCart(updatedCart);
935
+ }
936
+ return updatedCart;
937
+ },
938
+ [client, locale, cartCookieAdapter, mutateCart]
939
+ );
940
+ return useSWRMutation__default.default("remove-cart-lines", removeLines, options);
941
+ }
942
+ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
943
+ const { client, locale, cartCookieAdapter } = useShopify();
944
+ const updateAttributes = react.useCallback(
945
+ async (_key, { arg }) => {
946
+ const updatedCart = await shopifySdk.updateCartAttributes(client, {
947
+ ...arg,
948
+ metafieldIdentifiers,
949
+ cookieAdapter: cartCookieAdapter
950
+ });
951
+ console.log("useUpdateCartAttributes updatedCart", updatedCart);
952
+ if (updatedCart) {
953
+ mutate(updatedCart);
954
+ }
955
+ return updatedCart;
956
+ },
957
+ [client, locale, cartCookieAdapter, mutate]
958
+ );
959
+ return useSWRMutation__default.default("update-cart-attributes", updateAttributes, options);
960
+ }
961
+ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
962
+ const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
963
+ const isLoggedIn = userAdapter?.isLoggedIn || false;
964
+ const buyNow = react.useCallback(
965
+ async (_key, { arg }) => {
966
+ const {
967
+ lineItems,
968
+ discountCodes,
969
+ gtmParams = {},
970
+ buyerIdentity,
971
+ fbqTrackConfig,
972
+ customAttributes,
973
+ metafieldIdentifiers,
974
+ redirectToCheckout
975
+ } = arg;
976
+ if (!lineItems || lineItems.length === 0) {
977
+ return;
978
+ }
979
+ const lines = lineItems.map((item) => ({
980
+ merchandiseId: item.variant?.id || item.variantId || "",
981
+ quantity: item.quantity || 1,
982
+ attributes: item.attributes
983
+ })).filter((item) => item.merchandiseId && item.quantity);
984
+ if (lines.length === 0) {
985
+ return;
986
+ }
987
+ const resultCart = await shopifySdk.createCart(client, {
988
+ lines,
989
+ metafieldIdentifiers,
990
+ cookieAdapter: cartCookieAdapter,
991
+ buyerIdentity,
992
+ discountCodes,
993
+ customAttributes
994
+ });
995
+ if (!resultCart) {
996
+ throw new Error("Failed to create cart for buy now");
997
+ }
998
+ if (withTrack && resultCart.lineItems) {
999
+ const trackingLineItems = resultCart.lineItems.map((line) => ({
1000
+ variant: {
1001
+ id: line.variantId,
1002
+ sku: line.variant.sku || "",
1003
+ title: line.variant.name,
1004
+ price: {
1005
+ amount: String(line.variant.price),
1006
+ currencyCode: resultCart.currency.code
1007
+ },
1008
+ product: line.product ? {
1009
+ title: line.product.title || line.name,
1010
+ productType: line.product.productType,
1011
+ vendor: line.product.vendor
1012
+ } : void 0
1013
+ },
1014
+ quantity: line.quantity
1015
+ }));
1016
+ trackBuyNowGA({
1017
+ lineItems: trackingLineItems,
1018
+ gtmParams: { ...gtmParams, brand },
1019
+ brand
1020
+ });
1021
+ if (fbqTrackConfig) {
1022
+ trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
1023
+ }
1024
+ }
1025
+ if (redirectToCheckout) {
1026
+ if (resultCart.url) {
1027
+ if (typeof window !== "undefined") {
1028
+ window.location.href = resultCart.url;
1029
+ }
1030
+ } else {
1031
+ throw new Error("Failed to get checkout URL");
1032
+ }
1033
+ }
1034
+ return resultCart;
1035
+ },
1036
+ [client, locale, isLoggedIn, cartCookieAdapter, withTrack, brand]
1037
+ );
1038
+ return useSWRMutation__default.default("buy-now", buyNow, swrOptions);
1039
+ }
1040
+
1041
+ // src/hooks/cart/types/order-discount.ts
1042
+ var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
1043
+ OrderDiscountType2[OrderDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
1044
+ OrderDiscountType2[OrderDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
1045
+ OrderDiscountType2[OrderDiscountType2["REDUCE_PRICE"] = 3] = "REDUCE_PRICE";
1046
+ return OrderDiscountType2;
1047
+ })(OrderDiscountType || {});
1048
+ var OrderBasePriceType = /* @__PURE__ */ ((OrderBasePriceType2) => {
1049
+ OrderBasePriceType2[OrderBasePriceType2["ORIGIN_PRICE"] = 1] = "ORIGIN_PRICE";
1050
+ OrderBasePriceType2[OrderBasePriceType2["MIN_DISCOUNTED_PRICE"] = 2] = "MIN_DISCOUNTED_PRICE";
1051
+ return OrderBasePriceType2;
1052
+ })(OrderBasePriceType || {});
1053
+
1054
+ // src/hooks/cart/feature/use-calc-order-discount.ts
1055
+ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1056
+ const tags = react.useMemo(() => customer?.tags || [], [customer?.tags]);
1057
+ const isCustomerLoading = react.useMemo(() => !customer ? true : false, [customer]);
1058
+ const dealsType = "";
1059
+ const { activeCampaign, subtotal } = react.useMemo(() => {
1060
+ for (const campaign of orderDiscountConfig) {
1061
+ const { rule_conditions = [], result_detail } = campaign;
1062
+ const { main_product, order_discount_conf } = result_detail || {};
1063
+ const isPreCheckPassed = preCheck(rule_conditions, tags, []);
1064
+ if (isPreCheckPassed && main_product && order_discount_conf) {
1065
+ const matchedSubtotal = getMatchedMainProductSubTotal(
1066
+ cart,
1067
+ main_product?.variant_list?.map((v) => v.variant_id) || [],
1068
+ {
1069
+ spend_money_type: order_discount_conf.base_price === 2 /* MIN_DISCOUNTED_PRICE */ ? 2 : 1,
1070
+ // 根据基础价格类型设置
1071
+ variant_id_list: main_product?.variant_list?.map((v) => v.variant_id) || [],
1072
+ all_store_variant: main_product?.all_store_variant || false
1073
+ }
1074
+ );
1075
+ if (matchedSubtotal > 0) {
1076
+ return { activeCampaign: campaign, subtotal: matchedSubtotal };
1077
+ }
1078
+ }
1079
+ }
1080
+ return { activeCampaign: null, subtotal: 0 };
1081
+ }, [orderDiscountConfig, cart, tags, dealsType]);
1082
+ const { qualifyingDiscount, nextTierGoal, discountAmount } = react.useMemo(() => {
1083
+ if (!activeCampaign || !activeCampaign.result_detail?.order_discount_conf?.tiered_discounts) {
1084
+ return {
1085
+ qualifyingDiscount: null,
1086
+ nextTierGoal: null,
1087
+ discountAmount: 0
1088
+ };
1089
+ }
1090
+ const tieredDiscounts = activeCampaign.result_detail.order_discount_conf.tiered_discounts;
1091
+ const qualifyingTier = [...tieredDiscounts].reverse().find((tier) => subtotal >= Number(tier.amount));
1092
+ const nextGoal = tieredDiscounts.find((tier) => subtotal < Number(tier.amount));
1093
+ if (!qualifyingTier) {
1094
+ return {
1095
+ qualifyingDiscount: null,
1096
+ nextTierGoal: nextGoal || null,
1097
+ discountAmount: 0
1098
+ };
1099
+ }
1100
+ let calculatedDiscount = 0;
1101
+ switch (qualifyingTier.discount_type) {
1102
+ case 1 /* PERCENTAGE */:
1103
+ calculatedDiscount = subtotal * qualifyingTier.discount / 100;
1104
+ break;
1105
+ case 2 /* FIXED_AMOUNT */:
1106
+ calculatedDiscount = qualifyingTier.discount;
1107
+ break;
1108
+ case 3 /* REDUCE_PRICE */:
1109
+ calculatedDiscount = Math.min(subtotal, qualifyingTier.discount);
1110
+ break;
1111
+ default:
1112
+ calculatedDiscount = 0;
1113
+ }
1114
+ return {
1115
+ qualifyingDiscount: qualifyingTier,
1116
+ nextTierGoal: nextGoal || null,
1117
+ discountAmount: calculatedDiscount
1118
+ };
1119
+ }, [activeCampaign, subtotal]);
1120
+ return {
1121
+ qualifyingDiscount,
1122
+ nextTierGoal,
1123
+ activeCampaign,
1124
+ discountAmount,
1125
+ cartTotalForDiscount: subtotal,
1126
+ isLoading: isCustomerLoading
1127
+ };
1128
+ };
1129
+ function useHasPlusMemberInCart({
1130
+ memberSetting,
1131
+ cart
1132
+ }) {
1133
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1134
+ return react.useMemo(() => {
1135
+ if (!cart?.lineItems) {
1136
+ return {
1137
+ hasPlusMember: false,
1138
+ hasMonthlyPlus: false,
1139
+ hasAnnualPlus: false
1140
+ };
1141
+ }
1142
+ const monthlyPlusItem = cart.lineItems.find(
1143
+ (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
1144
+ );
1145
+ const annualPlusItem = cart.lineItems.find(
1146
+ (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
1147
+ );
1148
+ const hasMonthlyPlus = !!monthlyPlusItem;
1149
+ const hasAnnualPlus = !!annualPlusItem;
1150
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1151
+ return {
1152
+ hasPlusMember,
1153
+ hasMonthlyPlus,
1154
+ hasAnnualPlus,
1155
+ monthlyPlusItem,
1156
+ annualPlusItem
1157
+ };
1158
+ }, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
1159
+ }
1160
+
1161
+ // src/hooks/cart/feature/use-cart-attributes.ts
1162
+ var getReferralAttributes = () => {
1163
+ const inviteCode = Cookies5__default.default.get("invite_code");
1164
+ const playModeId = Cookies5__default.default.get("playModeId");
1165
+ const popup = Cookies5__default.default.get("_popup");
1166
+ if (inviteCode && playModeId) {
1167
+ return popup ? [
1168
+ { key: "_invite_code", value: inviteCode ? inviteCode : "" },
1169
+ { key: "_play_mode_id", value: playModeId ? playModeId : "" },
1170
+ { key: "_popup", value: popup }
1171
+ ] : [
1172
+ { key: "_invite_code", value: inviteCode ? inviteCode : "" },
1173
+ { key: "_play_mode_id", value: playModeId ? playModeId : "" }
1174
+ ];
1175
+ }
1176
+ return [];
1177
+ };
1178
+ var useCartAttributes = ({
1179
+ profile,
1180
+ customer,
1181
+ cart,
1182
+ memberSetting
1183
+ }) => {
1184
+ const [currentUrl, setCurrentUrl] = react.useState("");
1185
+ const { hasPlusMember } = useHasPlusMemberInCart({
1186
+ memberSetting,
1187
+ cart
1188
+ });
1189
+ console.log("memberSetting", memberSetting);
1190
+ console.log("hasPlusMember", hasPlusMember);
1191
+ react.useEffect(() => {
1192
+ setCurrentUrl(window.location.href);
1193
+ }, []);
1194
+ const userType = react.useMemo(() => {
1195
+ let userInfo = Cookies5__default.default.get("userInfo");
1196
+ if (userInfo) {
1197
+ userInfo = JSON.parse(userInfo);
1198
+ let arr = typeof userInfo?.id == "string" && userInfo?.id.split("/");
1199
+ userInfo.setId = arr[arr.length - 1];
1200
+ }
1201
+ const customerInfo = userInfo || customer;
1202
+ if (!customerInfo) {
1203
+ return "new_user_unlogin";
1204
+ }
1205
+ if (customer) {
1206
+ const { orders = {} } = customer;
1207
+ if (orders?.edges?.length === 1) {
1208
+ return "old_user_orders_once";
1209
+ } else if (orders?.edges?.length > 1) {
1210
+ return "old_user_orders_twice";
1211
+ }
1212
+ }
1213
+ return "new_user_login";
1214
+ }, [customer]);
1215
+ const memberAttributes = react.useMemo(() => {
1216
+ return [
1217
+ {
1218
+ key: "_token",
1219
+ value: profile?.token
1220
+ //是否登录
1221
+ },
1222
+ {
1223
+ key: "_member_type",
1224
+ value: hasPlusMember ? "2" : profile?.memberType
1225
+ //:0(游客),1(普通会员),2(付费会员)
1226
+ },
1227
+ {
1228
+ key: "_user_type",
1229
+ value: userType
1230
+ // n
1231
+ },
1232
+ {
1233
+ key: "_is_login",
1234
+ value: profile?.token ? "true" : "false"
1235
+ }
1236
+ ];
1237
+ }, [profile?.memberType, profile?.token, userType, hasPlusMember]);
1238
+ const functionAttributes = react.useMemo(() => {
1239
+ return [
1240
+ cart?.discountCodes && {
1241
+ key: "_discounts_function_env",
1242
+ value: JSON.stringify({
1243
+ discount_code: cart?.discountCodes.map((item) => item.code),
1244
+ user_tags: customer?.tags || []
1245
+ })
1246
+ }
1247
+ ];
1248
+ }, [cart]);
1249
+ const presellAttributes = react.useMemo(() => {
1250
+ return [
1251
+ {
1252
+ key: "_presale",
1253
+ value: cart?.lineItems.some((item) => item?.variant?.metafields?.presell === "presell")
1254
+ }
1255
+ ];
1256
+ }, [cart]);
1257
+ const weightAttributes = react.useMemo(() => {
1258
+ return [
1259
+ {
1260
+ key: "_weight",
1261
+ value: cart?.lineItems.reduce((acc, item) => {
1262
+ return new Decimal2__default.default(acc).plus(item.variant.weight ?? 0).toNumber();
1263
+ }, 0).toString()
1264
+ },
1265
+ {
1266
+ key: "_app_source_name",
1267
+ value: "dtc"
1268
+ }
1269
+ ];
1270
+ }, [cart]);
1271
+ const trackingAttributes = react.useMemo(() => {
1272
+ return [
1273
+ {
1274
+ key: "utm_params",
1275
+ value: currentUrl
1276
+ }
1277
+ ];
1278
+ }, [currentUrl]);
1279
+ return react.useMemo(
1280
+ () => ({
1281
+ attributes: [
1282
+ ...memberAttributes,
1283
+ ...functionAttributes,
1284
+ ...presellAttributes,
1285
+ ...weightAttributes,
1286
+ ...trackingAttributes,
1287
+ ...getReferralAttributes()
1288
+ ].filter((item) => item?.value)
1289
+ }),
1290
+ [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
1291
+ );
1292
+ };
1293
+ var DEFAULT_MIN = 1;
1294
+ var DEFAULT_MAX = 999;
1295
+ var useCartItemQuantityLimit = ({
1296
+ cart,
1297
+ cartItem,
1298
+ config
1299
+ }) => {
1300
+ const quantityLimit = react.useMemo(() => {
1301
+ if (config?.handle) {
1302
+ const cartItemQuantityLimit = config?.handle?.[cartItem?.product?.handle || ""];
1303
+ const sameHandleTotalQuantity = cart?.lineItems.reduce((acc, item) => {
1304
+ if (item.product?.handle === cartItem?.product?.handle && item.variant.sku !== cartItem.variant.sku) {
1305
+ acc += item.quantity;
1306
+ }
1307
+ return acc;
1308
+ }, 0) || 0;
1309
+ return {
1310
+ min: cartItemQuantityLimit?.min || DEFAULT_MIN,
1311
+ max: cartItemQuantityLimit?.max ? cartItemQuantityLimit?.max - sameHandleTotalQuantity : DEFAULT_MAX
1312
+ };
1313
+ } else if (config?.sku) {
1314
+ const cartItemQuantityLimit = config?.sku?.[cartItem?.variant?.sku];
1315
+ return {
1316
+ min: cartItemQuantityLimit?.min || DEFAULT_MIN,
1317
+ max: cartItemQuantityLimit?.max || DEFAULT_MAX
1318
+ };
1319
+ }
1320
+ return {
1321
+ min: DEFAULT_MIN,
1322
+ max: DEFAULT_MAX
1323
+ };
1324
+ }, [cartItem, cart]);
1325
+ return quantityLimit;
1326
+ };
1327
+ var useUpdateLineCodeAmountAttributes = ({
1328
+ cart,
1329
+ mutateCart,
1330
+ isCartLoading,
1331
+ setLoadingState,
1332
+ metafieldIdentifiers
1333
+ }) => {
1334
+ const { client, cartCookieAdapter } = useShopify();
1335
+ const mainProductDiscountCodes = react.useMemo(
1336
+ () => cart?.discountCodes.filter(
1337
+ ({ code, applicable }) => applicable && MAIN_PRODUCT_CODE.some((codePrefix) => code.startsWith(codePrefix))
1338
+ ).map(({ code }) => code),
1339
+ [cart]
1340
+ );
1341
+ const linesNeedUpdate = react.useMemo(
1342
+ () => cart?.lineItems.map((line) => {
1343
+ const attrNeedUpdate = [];
1344
+ const attrNeedDelete = [];
1345
+ const codeDiscount = line.discountAllocations?.find(
1346
+ (allocation) => mainProductDiscountCodes?.includes(allocation.code)
1347
+ );
1348
+ const hasFunctionEnvAttribute = line.customAttributes?.find(
1349
+ (attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY
1350
+ );
1351
+ const functionEnvValue = getDiscountEnvAttributeValue(line.customAttributes);
1352
+ const hasSameFunctionEnvAttribute = Number(functionEnvValue.discounted_amount) === Number(line.totalAmount);
1353
+ if (!hasSameFunctionEnvAttribute && hasFunctionEnvAttribute) {
1354
+ attrNeedUpdate.push({
1355
+ key: CUSTOMER_ATTRIBUTE_KEY,
1356
+ value: JSON.stringify({
1357
+ ...functionEnvValue,
1358
+ discounted_amount: Number(line.totalAmount)
1359
+ })
1360
+ });
1361
+ }
1362
+ const codeDiscountAmount = codeDiscount?.amount || 0;
1363
+ const hasCodeAmountAttribute = line.customAttributes?.find(
1364
+ (attr) => attr.key === CODE_AMOUNT_KEY || attr.key === SCRIPT_CODE_AMOUNT_KEY
1365
+ );
1366
+ const hasSameCodeAmountAttribute = line.customAttributes?.find(
1367
+ (attr) => attr.key === CODE_AMOUNT_KEY && attr.value === String(codeDiscountAmount)
1368
+ ) && line.customAttributes?.find(
1369
+ (attr) => attr.key === SCRIPT_CODE_AMOUNT_KEY && attr.value === String(codeDiscountAmount)
1370
+ );
1371
+ if (codeDiscount && !hasSameCodeAmountAttribute) {
1372
+ attrNeedUpdate.push({
1373
+ key: CODE_AMOUNT_KEY,
1374
+ value: String(codeDiscountAmount)
1375
+ });
1376
+ attrNeedUpdate.push({
1377
+ key: SCRIPT_CODE_AMOUNT_KEY,
1378
+ value: String(codeDiscountAmount)
1379
+ });
1380
+ } else if (!codeDiscount && hasCodeAmountAttribute) {
1381
+ attrNeedDelete.push(CODE_AMOUNT_KEY);
1382
+ attrNeedDelete.push(SCRIPT_CODE_AMOUNT_KEY);
1383
+ }
1384
+ return {
1385
+ line,
1386
+ attrNeedUpdate,
1387
+ attrNeedDelete
1388
+ };
1389
+ }).filter(
1390
+ ({ attrNeedUpdate, attrNeedDelete }) => attrNeedUpdate.length || attrNeedDelete.length
1391
+ ).map(({ line, attrNeedUpdate, attrNeedDelete }) => {
1392
+ if (attrNeedUpdate.length) {
1393
+ return {
1394
+ id: line.id,
1395
+ attributes: [
1396
+ ...line.customAttributes?.filter(
1397
+ (attr) => !attrNeedUpdate.some((updateAttr) => updateAttr.key === attr.key)
1398
+ ) || [],
1399
+ ...attrNeedUpdate
1400
+ ]
1401
+ };
1402
+ } else if (attrNeedDelete.length) {
1403
+ return {
1404
+ id: line.id,
1405
+ attributes: line.customAttributes?.filter(
1406
+ (attr) => !attrNeedDelete.includes(attr.key)
1407
+ ) || []
1408
+ };
1409
+ } else {
1410
+ return {
1411
+ id: line.id,
1412
+ attributes: line.customAttributes || []
1413
+ };
1414
+ }
1415
+ }),
1416
+ [cart?.lineItems, mainProductDiscountCodes]
1417
+ );
1418
+ const { loading } = ahooks.useRequest(
1419
+ async () => {
1420
+ if (linesNeedUpdate?.length && !isCartLoading) {
1421
+ const result = await shopifySdk.updateCartLines(client, {
1422
+ cartId: cart?.id || "",
1423
+ lines: linesNeedUpdate,
1424
+ metafieldIdentifiers,
1425
+ cookieAdapter: cartCookieAdapter
1426
+ });
1427
+ if (result) {
1428
+ mutateCart(result);
1429
+ }
1430
+ }
1431
+ },
1432
+ {
1433
+ throttleWait: 3e3,
1434
+ // 3 秒内只触发最后一次更新
1435
+ throttleTrailing: true,
1436
+ refreshDeps: [linesNeedUpdate, isCartLoading]
1437
+ }
1438
+ );
1439
+ react.useEffect(() => {
1440
+ setLoadingState((prev) => {
1441
+ return {
1442
+ ...prev,
1443
+ editLineCodeAmountLoading: loading
1444
+ };
1445
+ });
1446
+ }, [loading, setLoadingState]);
1447
+ };
1448
+
1449
+ // src/hooks/cart/types/price-discount.ts
1450
+ var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
1451
+ PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
1452
+ PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
1453
+ return PriceDiscountType2;
1454
+ })(PriceDiscountType || {});
1455
+ var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
1456
+ PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
1457
+ PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
1458
+ return PriceBasePriceType2;
1459
+ })(PriceBasePriceType || {});
1460
+ function useProduct(options = {}) {
1461
+ const { client, locale } = useShopify();
1462
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
1463
+ return useSWR__default.default(
1464
+ handle ? ["product", locale, handle, metafieldIdentifiers] : null,
1465
+ () => shopifySdk.getProduct(client, {
1466
+ handle,
1467
+ locale,
1468
+ metafieldIdentifiers
1469
+ }),
1470
+ swrOptions
1471
+ );
1472
+ }
1473
+ function useAllProducts(options = {}) {
1474
+ const { client, locale } = useShopify();
1475
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1476
+ return useSWR__default.default(
1477
+ ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
1478
+ () => shopifySdk.getAllProducts(client, {
1479
+ locale,
1480
+ first,
1481
+ query,
1482
+ sortKey,
1483
+ reverse,
1484
+ metafieldIdentifiers
1485
+ }),
1486
+ swrOptions
1487
+ );
1488
+ }
1489
+ function useProductsByHandles(options = {}) {
1490
+ const { client, locale } = useShopify();
1491
+ const { handles: originHandles, metafieldIdentifiers, ...swrOptions } = options;
1492
+ const handles = new Set(originHandles || []);
1493
+ const sortedHandles = handles ? [...handles].sort() : void 0;
1494
+ return useSWR__default.default(
1495
+ sortedHandles && sortedHandles.length > 0 ? ["products-by-handles", locale, sortedHandles.join(","), metafieldIdentifiers] : null,
1496
+ () => {
1497
+ const handlesArray = [...handles];
1498
+ if (handlesArray?.length === 0) {
1499
+ throw new Error("Handles are required");
1500
+ }
1501
+ return shopifySdk.getProductsByHandles(client, {
1502
+ handles: [...handles],
1503
+ locale,
1504
+ metafieldIdentifiers
1505
+ });
1506
+ },
1507
+ swrOptions || {
1508
+ revalidateOnFocus: false
1509
+ }
1510
+ );
1511
+ }
1512
+ function getFirstAvailableVariant(product) {
1513
+ const availableVariant = product.variants.find((v) => v.availableForSale);
1514
+ return availableVariant || product.variants[0];
1515
+ }
1516
+ function getVariantFromSelectedOptions(product, selectedOptions) {
1517
+ return product.variants.find((variant) => {
1518
+ return variant.selectedOptions.every((option) => {
1519
+ return selectedOptions[option.name] === option.value;
1520
+ });
1521
+ });
1522
+ }
1523
+ function useVariant({
1524
+ product,
1525
+ selectedOptions
1526
+ }) {
1527
+ const [variant, setVariant] = react.useState(
1528
+ product ? getFirstAvailableVariant(product) : void 0
1529
+ );
1530
+ react.useEffect(() => {
1531
+ if (!product) {
1532
+ setVariant(void 0);
1533
+ return;
1534
+ }
1535
+ const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
1536
+ if (newVariant && newVariant.id !== variant?.id) {
1537
+ setVariant(newVariant);
1538
+ } else if (!newVariant) {
1539
+ setVariant(getFirstAvailableVariant(product));
1540
+ }
1541
+ }, [selectedOptions, product, variant?.id]);
1542
+ return variant;
1543
+ }
1544
+ var FAKE_PRICE = 999999999e-2;
1545
+ function formatPrice({
1546
+ amount,
1547
+ currencyCode,
1548
+ locale,
1549
+ maximumFractionDigits,
1550
+ minimumFractionDigits,
1551
+ removeTrailingZeros
1552
+ }) {
1553
+ const formatter = new Intl.NumberFormat(locale, {
1554
+ style: "currency",
1555
+ currency: currencyCode,
1556
+ maximumFractionDigits: maximumFractionDigits ?? 2,
1557
+ minimumFractionDigits: minimumFractionDigits ?? 2
1558
+ });
1559
+ let formatted = formatter.format(amount);
1560
+ if (removeTrailingZeros) {
1561
+ formatted = formatted.replace(/\.00$/, "");
1562
+ }
1563
+ return formatted;
1564
+ }
1565
+ function formatVariantPrice({
1566
+ amount,
1567
+ baseAmount,
1568
+ currencyCode,
1569
+ locale,
1570
+ maximumFractionDigits,
1571
+ minimumFractionDigits,
1572
+ removeTrailingZeros
1573
+ }) {
1574
+ return {
1575
+ price: formatPrice({
1576
+ amount,
1577
+ currencyCode,
1578
+ locale,
1579
+ maximumFractionDigits,
1580
+ minimumFractionDigits,
1581
+ removeTrailingZeros
1582
+ }),
1583
+ basePrice: formatPrice({
1584
+ amount: baseAmount,
1585
+ currencyCode,
1586
+ locale,
1587
+ maximumFractionDigits,
1588
+ minimumFractionDigits,
1589
+ removeTrailingZeros
1590
+ })
1591
+ };
1592
+ }
1593
+ function usePrice({
1594
+ amount,
1595
+ baseAmount,
1596
+ currencyCode,
1597
+ soldOutDescription = "",
1598
+ maximumFractionDigits,
1599
+ minimumFractionDigits,
1600
+ removeTrailingZeros
1601
+ }) {
1602
+ const { locale } = useShopify();
1603
+ const value = react.useMemo(() => {
1604
+ if (typeof amount !== "number" || !currencyCode) {
1605
+ return "";
1606
+ }
1607
+ if (soldOutDescription && amount >= FAKE_PRICE) {
1608
+ return soldOutDescription;
1609
+ }
1610
+ return baseAmount ? formatVariantPrice({
1611
+ amount,
1612
+ baseAmount,
1613
+ currencyCode,
1614
+ locale,
1615
+ maximumFractionDigits,
1616
+ minimumFractionDigits,
1617
+ removeTrailingZeros
1618
+ }) : formatPrice({
1619
+ amount,
1620
+ currencyCode,
1621
+ locale,
1622
+ maximumFractionDigits,
1623
+ minimumFractionDigits,
1624
+ removeTrailingZeros
1625
+ });
1626
+ }, [
1627
+ amount,
1628
+ baseAmount,
1629
+ currencyCode,
1630
+ locale,
1631
+ maximumFractionDigits,
1632
+ minimumFractionDigits,
1633
+ soldOutDescription,
1634
+ removeTrailingZeros
1635
+ ]);
1636
+ const result = react.useMemo(() => {
1637
+ const free = Boolean(amount && amount <= 0);
1638
+ return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
1639
+ }, [value, amount]);
1640
+ return result;
1641
+ }
1642
+ function optionsConstructor(selectedOptions) {
1643
+ return selectedOptions.reduce((acc, option) => {
1644
+ acc[option.name] = option.value;
1645
+ return acc;
1646
+ }, {});
1647
+ }
1648
+ function decodeShopifyId(gid) {
1649
+ try {
1650
+ const base64 = gid.split("/").pop() || "";
1651
+ return atob(base64);
1652
+ } catch {
1653
+ return gid;
1654
+ }
1655
+ }
1656
+ function useSelectedOptions(product, sku) {
1657
+ const [options, setOptions] = react.useState({});
1658
+ react.useEffect(() => {
1659
+ if (!product || !product.variants.length) {
1660
+ setOptions({});
1661
+ return;
1662
+ }
1663
+ let variant = product.variants[0];
1664
+ if (typeof window !== "undefined") {
1665
+ const searchParams = new URLSearchParams(window.location.search);
1666
+ const variantIdParam = searchParams.get("variant");
1667
+ if (variantIdParam) {
1668
+ const foundVariant = product.variants.find((v) => {
1669
+ if (sku) return v.sku === sku;
1670
+ return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
1671
+ });
1672
+ if (foundVariant) {
1673
+ variant = foundVariant;
1674
+ }
1675
+ }
1676
+ }
1677
+ if (variant) {
1678
+ const newOptions = optionsConstructor(variant.selectedOptions);
1679
+ setOptions(newOptions);
1680
+ }
1681
+ }, [product, sku]);
1682
+ return [options, setOptions];
1683
+ }
1684
+ function decodeShopifyId2(gid) {
1685
+ try {
1686
+ const parts = gid.split("/");
1687
+ return parts[parts.length - 1] || gid;
1688
+ } catch {
1689
+ return gid;
1690
+ }
1691
+ }
1692
+ function useProductUrl(otherQuery) {
1693
+ const { routerAdapter } = useShopify();
1694
+ return react.useCallback(
1695
+ ({ product, variant }) => {
1696
+ if (!product) return "";
1697
+ const queryParams = new URLSearchParams();
1698
+ if (variant?.id) {
1699
+ const variantId = decodeShopifyId2(variant.id);
1700
+ if (variantId) {
1701
+ queryParams.set("variant", variantId);
1702
+ }
1703
+ }
1704
+ if (otherQuery) {
1705
+ Object.entries(otherQuery).forEach(([key, value]) => {
1706
+ queryParams.set(key, value);
1707
+ });
1708
+ }
1709
+ const queryString = queryParams.toString();
1710
+ const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
1711
+ if (routerAdapter?.getLocalizedPath) {
1712
+ return routerAdapter.getLocalizedPath(path);
1713
+ }
1714
+ return path;
1715
+ },
1716
+ [routerAdapter, otherQuery]
1717
+ );
1718
+ }
1719
+ function decodeShopifyId3(gid) {
1720
+ try {
1721
+ const parts = gid.split("/");
1722
+ return parts[parts.length - 1] || gid;
1723
+ } catch {
1724
+ return gid;
1725
+ }
1726
+ }
1727
+ function useUpdateVariantQuery(variant) {
1728
+ react.useEffect(() => {
1729
+ if (!variant || typeof window === "undefined") {
1730
+ return;
1731
+ }
1732
+ const searchParams = new URLSearchParams(window.location.search);
1733
+ const currentVariantId = searchParams.get("variant");
1734
+ const newVariantId = decodeShopifyId3(variant.id);
1735
+ if (newVariantId && currentVariantId !== newVariantId) {
1736
+ searchParams.set("variant", newVariantId);
1737
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
1738
+ window.history.replaceState({}, "", newUrl);
1739
+ }
1740
+ }, [variant]);
1741
+ }
1742
+ function getVariantMediaList({
1743
+ product,
1744
+ variant
1745
+ }) {
1746
+ if (variant.image?.url) {
1747
+ const variantMediaId = variant.image.url;
1748
+ const variantMedia = product.media.filter((media) => {
1749
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
1750
+ return media.previewImage?.url === variantMediaId;
1751
+ }
1752
+ return false;
1753
+ });
1754
+ if (variantMedia.length > 0) {
1755
+ const otherMedia = product.media.filter((media) => {
1756
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
1757
+ return media.previewImage.url !== variantMediaId;
1758
+ }
1759
+ return true;
1760
+ });
1761
+ return [...variantMedia, ...otherMedia];
1762
+ }
1763
+ }
1764
+ return product.media;
1765
+ }
1766
+ function useVariantMedia({
1767
+ product,
1768
+ variant
1769
+ }) {
1770
+ const [imageList, setImageList] = react.useState([]);
1771
+ const [sceneList, setSceneList] = react.useState([]);
1772
+ const [videoList, setVideoList] = react.useState([]);
1773
+ react.useEffect(() => {
1774
+ if (!product || !variant) {
1775
+ setImageList([]);
1776
+ setSceneList([]);
1777
+ setVideoList([]);
1778
+ return;
1779
+ }
1780
+ const mediaList = getVariantMediaList({ product, variant });
1781
+ const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
1782
+ const videos = mediaList.filter(
1783
+ (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
1784
+ );
1785
+ setImageList(images.length > 0 && images[0] ? [images[0]] : []);
1786
+ setSceneList(images.length > 1 ? images.slice(1) : []);
1787
+ setVideoList(videos);
1788
+ }, [product, variant]);
1789
+ return {
1790
+ productList: imageList,
1791
+ sceneList,
1792
+ videoList
1793
+ };
1794
+ }
1795
+ function useCollection(options = {}) {
1796
+ const { client, locale } = useShopify();
1797
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
1798
+ return useSWR__default.default(
1799
+ handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
1800
+ () => shopifySdk.getCollection(client, {
1801
+ handle,
1802
+ locale,
1803
+ metafieldIdentifiers
1804
+ }),
1805
+ swrOptions
1806
+ );
1807
+ }
1808
+ function useAllCollections(options = {}) {
1809
+ const { client, locale } = useShopify();
1810
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1811
+ return useSWR__default.default(
1812
+ ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
1813
+ () => shopifySdk.getAllCollections(client, {
1814
+ locale,
1815
+ first,
1816
+ query,
1817
+ sortKey,
1818
+ reverse,
1819
+ metafieldIdentifiers
1820
+ }),
1821
+ swrOptions
1822
+ );
1823
+ }
1824
+ function useCollections(options = {}) {
1825
+ const { client, locale } = useShopify();
1826
+ const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1827
+ return useSWR__default.default(
1828
+ ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
1829
+ () => shopifySdk.getCollections(client, {
1830
+ locale,
1831
+ first,
1832
+ after,
1833
+ query,
1834
+ sortKey,
1835
+ reverse,
1836
+ metafieldIdentifiers
1837
+ }),
1838
+ swrOptions
1839
+ );
1840
+ }
1841
+ function useBlog(options = {}) {
1842
+ const { client, locale } = useShopify();
1843
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
1844
+ return useSWR__default.default(
1845
+ handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
1846
+ () => shopifySdk.getBlog(client, { handle, locale, metafieldIdentifiers }),
1847
+ swrOptions
1848
+ );
1849
+ }
1850
+ function useAllBlogs(options = {}) {
1851
+ const { client, locale } = useShopify();
1852
+ const { first, query, metafieldIdentifiers, ...swrOptions } = options;
1853
+ return useSWR__default.default(
1854
+ ["all-blogs", locale, first, query, metafieldIdentifiers],
1855
+ () => shopifySdk.getAllBlogs(client, {
1856
+ locale,
1857
+ first,
1858
+ query,
1859
+ metafieldIdentifiers
1860
+ }),
1861
+ swrOptions
1862
+ );
1863
+ }
1864
+ function useArticle(options = {}) {
1865
+ const { client, locale } = useShopify();
1866
+ const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
1867
+ return useSWR__default.default(
1868
+ blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
1869
+ () => shopifySdk.getArticle(client, {
1870
+ blogHandle,
1871
+ articleHandle,
1872
+ locale,
1873
+ metafieldIdentifiers
1874
+ }),
1875
+ swrOptions
1876
+ );
1877
+ }
1878
+ function useArticles(options = {}) {
1879
+ const { client, locale } = useShopify();
1880
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1881
+ return useSWR__default.default(
1882
+ ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
1883
+ () => shopifySdk.getArticles(client, {
1884
+ locale,
1885
+ first,
1886
+ query,
1887
+ sortKey,
1888
+ reverse,
1889
+ metafieldIdentifiers
1890
+ }),
1891
+ swrOptions
1892
+ );
1893
+ }
1894
+ function useArticlesInBlog(options = {}) {
1895
+ const { client, locale } = useShopify();
1896
+ const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1897
+ return useSWR__default.default(
1898
+ blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
1899
+ () => shopifySdk.getArticlesInBlog(client, {
1900
+ blogHandle,
1901
+ locale,
1902
+ first,
1903
+ sortKey,
1904
+ reverse,
1905
+ metafieldIdentifiers
1906
+ }),
1907
+ swrOptions
1908
+ );
1909
+ }
1910
+ async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
1911
+ if (!searchQuery) {
1912
+ return void 0;
1913
+ }
1914
+ const query = (
1915
+ /* GraphQL */
1916
+ `
1917
+ query search($query: String!, $first: Int!, $types: [SearchType!])
1918
+ @inContext(language: $language) {
1919
+ search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
1920
+ totalCount
1921
+ edges {
1922
+ node {
1923
+ ... on Article {
1924
+ __typename
1925
+ id
1926
+ handle
1927
+ title
1928
+ excerpt
1929
+ image {
1930
+ url
1931
+ altText
1932
+ }
1933
+ }
1934
+ ... on Page {
1935
+ __typename
1936
+ id
1937
+ handle
1938
+ title
1939
+ }
1940
+ ... on Product {
1941
+ __typename
1942
+ id
1943
+ handle
1944
+ title
1945
+ description
1946
+ featuredImage {
1947
+ url
1948
+ altText
1949
+ }
1950
+ }
1951
+ }
1952
+ }
1953
+ pageInfo {
1954
+ hasNextPage
1955
+ endCursor
1956
+ }
1957
+ }
1958
+ }
1959
+ `
1960
+ );
1961
+ const data = await client.query(query, {
1962
+ query: searchQuery,
1963
+ first,
1964
+ types
1965
+ });
1966
+ if (!data || !data.search) {
1967
+ return void 0;
1968
+ }
1969
+ const items = data.search.edges?.map((edge) => {
1970
+ const node = edge.node;
1971
+ const item = {
1972
+ type: node.__typename.toUpperCase(),
1973
+ id: node.id,
1974
+ handle: node.handle,
1975
+ title: node.title
1976
+ };
1977
+ if (node.__typename === "Product") {
1978
+ item.description = node.description;
1979
+ item.image = node.featuredImage ? {
1980
+ url: node.featuredImage.url,
1981
+ altText: node.featuredImage.altText
1982
+ } : void 0;
1983
+ } else if (node.__typename === "Article") {
1984
+ item.description = node.excerpt;
1985
+ item.image = node.image ? {
1986
+ url: node.image.url,
1987
+ altText: node.image.altText
1988
+ } : void 0;
1989
+ }
1990
+ return item;
1991
+ }) || [];
1992
+ return {
1993
+ items,
1994
+ totalCount: data.search.totalCount || 0,
1995
+ pageInfo: data.search.pageInfo
1996
+ };
1997
+ }
1998
+ function useSearch(options = {}) {
1999
+ const { client, locale } = useShopify();
2000
+ const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2001
+ return useSWR__default.default(
2002
+ query ? ["search", locale, query, first, types] : null,
2003
+ () => performSearch(client, locale, query, first, types),
2004
+ swrOptions
2005
+ );
2006
+ }
2007
+ async function getSiteInfo(client, locale, metafieldIdentifiers) {
2008
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2009
+ const query = (
2010
+ /* GraphQL */
2011
+ `
2012
+ query getSiteInfo(
2013
+ ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2014
+ ) @inContext(language: $language) {
2015
+ shop {
2016
+ name
2017
+ description
2018
+ primaryDomain {
2019
+ url
2020
+ host
2021
+ }
2022
+ brand {
2023
+ logo {
2024
+ image {
2025
+ url
2026
+ }
2027
+ }
2028
+ colors {
2029
+ primary {
2030
+ background
2031
+ }
2032
+ secondary {
2033
+ background
2034
+ }
2035
+ }
2036
+ }
2037
+ ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2038
+ }
2039
+ }
2040
+ `
2041
+ );
2042
+ const variables = {};
2043
+ if (hasMetafields) {
2044
+ variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2045
+ }
2046
+ const data = await client.query(query, variables);
2047
+ if (!data || !data.shop) {
2048
+ return void 0;
2049
+ }
2050
+ const shop = data.shop;
2051
+ const metafields = shop.metafields?.reduce((acc, mf) => {
2052
+ if (mf && mf.key) {
2053
+ acc[mf.key] = mf.value;
2054
+ }
2055
+ return acc;
2056
+ }, {});
2057
+ return {
2058
+ name: shop.name,
2059
+ description: shop.description,
2060
+ primaryDomain: shop.primaryDomain,
2061
+ brand: shop.brand ? {
2062
+ logo: shop.brand.logo,
2063
+ colors: shop.brand.colors ? {
2064
+ primary: shop.brand.colors.primary?.background,
2065
+ secondary: shop.brand.colors.secondary?.background
2066
+ } : void 0
2067
+ } : void 0,
2068
+ metafields
2069
+ };
2070
+ }
2071
+ function useSite(options = {}) {
2072
+ const { client, locale } = useShopify();
2073
+ const { metafieldIdentifiers, ...swrOptions } = options;
2074
+ return useSWR__default.default(
2075
+ ["site", locale, metafieldIdentifiers],
2076
+ () => getSiteInfo(client, locale, metafieldIdentifiers),
2077
+ swrOptions
2078
+ );
2079
+ }
2080
+
2081
+ // src/hooks/member/plus/types.ts
2082
+ var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
2083
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
2084
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
2085
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
2086
+ return PLUS_MEMBER_TYPE2;
2087
+ })(PLUS_MEMBER_TYPE || {});
2088
+ var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
2089
+ PlusMemberMode2["MONTHLY"] = "monthly";
2090
+ PlusMemberMode2["ANNUAL"] = "annual";
2091
+ return PlusMemberMode2;
2092
+ })(PlusMemberMode || {});
2093
+ var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
2094
+ DeliveryPlusType2["FREE"] = "free";
2095
+ DeliveryPlusType2["MONTHLY"] = "monthly";
2096
+ DeliveryPlusType2["ANNUAL"] = "annual";
2097
+ return DeliveryPlusType2;
2098
+ })(DeliveryPlusType || {});
2099
+ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
2100
+ ShippingMethodMode2["FREE"] = "free";
2101
+ ShippingMethodMode2["TDD"] = "tdd";
2102
+ ShippingMethodMode2["NDD"] = "ndd";
2103
+ return ShippingMethodMode2;
2104
+ })(ShippingMethodMode || {});
2105
+ var createInitialValue = () => ({
2106
+ zipCode: "",
2107
+ plusMemberMetafields: {},
2108
+ setZipCode: () => {
2109
+ },
2110
+ allowNextDayDelivery: false,
2111
+ setAllowNextDayDelivery: () => {
2112
+ },
2113
+ allowThirdDayDelivery: false,
2114
+ setAllowThirdDayDelivery: () => {
2115
+ },
2116
+ selectedPlusMemberMode: "free",
2117
+ setSelectedPlusMemberMode: () => {
2118
+ },
2119
+ showAreaCheckModal: false,
2120
+ setShowAreaCheckModal: () => {
2121
+ },
2122
+ selectedShippingMethod: void 0,
2123
+ setSelectedShippingMethod: () => {
2124
+ },
2125
+ showTip: false,
2126
+ setShowTip: () => {
2127
+ },
2128
+ showMoreShippingMethod: false,
2129
+ setShowMoreShippingMethod: () => {
2130
+ },
2131
+ variant: {},
2132
+ product: {},
2133
+ shippingMethodsContext: {
2134
+ freeShippingMethods: [],
2135
+ paymentShippingMethods: [],
2136
+ nddOverweight: false,
2137
+ tddOverweight: false
2138
+ },
2139
+ selectedPlusMemberProduct: null,
2140
+ plusMemberProducts: [],
2141
+ showPlusMemberBenefit: false,
2142
+ setShowPlusMemberBenefit: () => {
2143
+ },
2144
+ deleteMarginBottom: false,
2145
+ setDeleteMarginBottom: () => {
2146
+ },
2147
+ profile: void 0,
2148
+ locale: void 0
2149
+ });
2150
+ var PlusMemberContext = react.createContext(createInitialValue());
2151
+ function usePlusMemberContext() {
2152
+ return react.useContext(PlusMemberContext);
2153
+ }
2154
+ function usePlusMonthlyProductVariant() {
2155
+ const { plusMemberProducts, plusMemberMetafields } = usePlusMemberContext();
2156
+ const plusMonthly = plusMemberMetafields?.plus_monthly_product;
2157
+ const plusMonthlyProductVariant = react.useMemo(() => {
2158
+ const product = plusMemberProducts?.find(
2159
+ (item) => item?.handle === plusMonthly?.handle
2160
+ );
2161
+ const productVariant = product?.variants?.find(
2162
+ (item) => item.sku === plusMonthly?.sku
2163
+ );
2164
+ return productVariant;
2165
+ }, [plusMemberProducts, plusMonthly]);
2166
+ return plusMonthlyProductVariant;
2167
+ }
2168
+ function usePlusAnnualProductVariant() {
2169
+ const { plusMemberProducts, plusMemberMetafields } = usePlusMemberContext();
2170
+ const plusAnnual = plusMemberMetafields?.plus_annual_product;
2171
+ const plusAnnualProductVariant = react.useMemo(() => {
2172
+ const product = plusMemberProducts?.find(
2173
+ (item) => item?.handle === plusAnnual?.handle
2174
+ );
2175
+ const productVariant = product?.variants?.find(
2176
+ (item) => item.sku === plusAnnual?.sku
2177
+ );
2178
+ return productVariant;
2179
+ }, [plusMemberProducts, plusAnnual]);
2180
+ return plusAnnualProductVariant;
2181
+ }
2182
+ function useShippingMethods(options) {
2183
+ const {
2184
+ variant,
2185
+ plusMemberMetafields,
2186
+ selectedPlusMemberMode,
2187
+ isPlus = false,
2188
+ nddCoupon,
2189
+ tddCoupon
2190
+ } = options;
2191
+ const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
2192
+ const nddOverweight = react.useMemo(() => {
2193
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
2194
+ }, [shippingMethod?.overWeight_ndd, variant?.weight]);
2195
+ const tddOverweight = react.useMemo(() => {
2196
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
2197
+ }, [shippingMethod?.overWeight_tdd, variant?.weight]);
2198
+ const paymentShippingMethods = react.useMemo(() => {
2199
+ const weight = variant?.weight || 0;
2200
+ const methods = plus_shipping?.shipping_methods?.filter(
2201
+ ({ weight_low, weight_high, __mode, __plus }) => {
2202
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2203
+ return __mode !== "free" /* FREE */ && !__plus && fitWeight;
2204
+ }
2205
+ ) || [];
2206
+ return methods.map((method) => {
2207
+ let disabled = false;
2208
+ const selectedFreeMember = selectedPlusMemberMode === "free";
2209
+ if (method.__mode === "ndd" /* NDD */) {
2210
+ disabled = selectedFreeMember || nddOverweight;
2211
+ } else if (method.__mode === "tdd" /* TDD */) {
2212
+ disabled = selectedFreeMember || tddOverweight;
2213
+ }
2214
+ return {
2215
+ ...method,
2216
+ id: method.__mode + method.__code,
2217
+ useCoupon: false,
2218
+ subtitle: plus_shipping?.directly || "",
2219
+ disabled
2220
+ };
2221
+ });
2222
+ }, [
2223
+ nddOverweight,
2224
+ plus_shipping?.directly,
2225
+ plus_shipping?.shipping_methods,
2226
+ selectedPlusMemberMode,
2227
+ tddOverweight,
2228
+ variant?.weight
2229
+ ]);
2230
+ const nddPrice = react.useMemo(() => {
2231
+ const weight = variant?.weight || 0;
2232
+ const nddMethod = paymentShippingMethods.find(
2233
+ ({ __mode, weight_high, weight_low }) => {
2234
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2235
+ return __mode === "ndd" && fitWeight;
2236
+ }
2237
+ );
2238
+ return nddMethod?.price || 0;
2239
+ }, [variant?.weight, paymentShippingMethods]);
2240
+ const tddPrice = react.useMemo(() => {
2241
+ const weight = variant?.weight || 0;
2242
+ const tddMethod = paymentShippingMethods.find(
2243
+ ({ __mode, weight_high, weight_low }) => {
2244
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2245
+ return __mode === "tdd" && fitWeight;
2246
+ }
2247
+ );
2248
+ return tddMethod?.price || 0;
2249
+ }, [variant?.weight, paymentShippingMethods]);
2250
+ const freeShippingMethods = react.useMemo(() => {
2251
+ const weight = variant?.weight || 0;
2252
+ let methods = plus_shipping?.shipping_methods?.filter(
2253
+ ({ __mode, __plus, weight_low, weight_high }) => {
2254
+ if (__mode === "free" /* FREE */) {
2255
+ return true;
2256
+ }
2257
+ if (isPlus) {
2258
+ const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
2259
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2260
+ return hasCoupon && fitWeight && !__plus;
2261
+ } else {
2262
+ return __plus;
2263
+ }
2264
+ }
2265
+ ) || [];
2266
+ if (isPlus) {
2267
+ methods = methods.sort((a, b) => {
2268
+ if (b.__mode === "free" /* FREE */) return -1;
2269
+ return 0;
2270
+ });
2271
+ }
2272
+ return methods.map((method) => {
2273
+ let price = 0;
2274
+ let coupon;
2275
+ let disabled;
2276
+ if (method.__mode !== "free" /* FREE */) {
2277
+ switch (method.__mode) {
2278
+ case "tdd":
2279
+ price = tddPrice;
2280
+ coupon = tddCoupon || nddCoupon;
2281
+ break;
2282
+ case "ndd":
2283
+ price = nddPrice;
2284
+ coupon = nddCoupon;
2285
+ break;
2286
+ }
2287
+ disabled = selectedPlusMemberMode === "free";
2288
+ if (method.__mode === "ndd" /* NDD */) {
2289
+ disabled = disabled || nddOverweight;
2290
+ } else if (method.__mode === "tdd" /* TDD */) {
2291
+ disabled = disabled || tddOverweight;
2292
+ }
2293
+ }
2294
+ return {
2295
+ ...method,
2296
+ id: method.__mode + method.__code,
2297
+ useCoupon: true,
2298
+ disabled,
2299
+ coupon,
2300
+ price
2301
+ };
2302
+ });
2303
+ }, [
2304
+ variant?.weight,
2305
+ plus_shipping?.shipping_methods,
2306
+ isPlus,
2307
+ nddCoupon,
2308
+ tddCoupon,
2309
+ selectedPlusMemberMode,
2310
+ tddPrice,
2311
+ nddPrice,
2312
+ nddOverweight,
2313
+ tddOverweight
2314
+ ]);
2315
+ return {
2316
+ freeShippingMethods,
2317
+ paymentShippingMethods,
2318
+ nddOverweight,
2319
+ tddOverweight
2320
+ };
2321
+ }
2322
+ function useShippingMethodAvailableCheck() {
2323
+ const {
2324
+ zipCode,
2325
+ allowNextDayDelivery,
2326
+ allowThirdDayDelivery,
2327
+ selectedShippingMethod,
2328
+ setSelectedShippingMethod,
2329
+ setShowTip,
2330
+ shippingMethodsContext
2331
+ } = usePlusMemberContext();
2332
+ react.useEffect(() => {
2333
+ const freeShippingMethod = shippingMethodsContext.freeShippingMethods[0];
2334
+ const standardShippingMethod = shippingMethodsContext.freeShippingMethods?.find(
2335
+ (item) => item.__mode === "free" /* FREE */
2336
+ );
2337
+ const freeTDD = shippingMethodsContext.freeShippingMethods.find(
2338
+ (item) => item.__mode === "tdd" /* TDD */
2339
+ );
2340
+ const paymentTDD = shippingMethodsContext.paymentShippingMethods.find(
2341
+ (item) => item.__mode === "tdd" /* TDD */
2342
+ );
2343
+ if (zipCode) {
2344
+ console.log(
2345
+ "allowNextDayDelivery, allowThirdDayDelivery:",
2346
+ allowNextDayDelivery,
2347
+ allowThirdDayDelivery
2348
+ );
2349
+ if (!allowNextDayDelivery && !allowThirdDayDelivery) {
2350
+ setShowTip(true);
2351
+ setSelectedShippingMethod(standardShippingMethod);
2352
+ } else {
2353
+ if (selectedShippingMethod?.__mode === "ndd" /* NDD */ && !allowNextDayDelivery) {
2354
+ setShowTip(true);
2355
+ if (allowThirdDayDelivery) {
2356
+ if (selectedShippingMethod.useCoupon) {
2357
+ const method = freeTDD || freeShippingMethod;
2358
+ if (method) setSelectedShippingMethod(method);
2359
+ } else {
2360
+ const method = paymentTDD || freeShippingMethod;
2361
+ if (method) setSelectedShippingMethod(method);
2362
+ }
2363
+ } else {
2364
+ if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
2365
+ }
2366
+ } else if (
2367
+ // TDD 无法使用
2368
+ selectedShippingMethod?.__mode === "tdd" /* TDD */ && !allowThirdDayDelivery
2369
+ ) {
2370
+ setShowTip(true);
2371
+ if (freeShippingMethod) setSelectedShippingMethod(freeShippingMethod);
2372
+ }
2373
+ }
2374
+ }
2375
+ }, [
2376
+ allowNextDayDelivery,
2377
+ allowThirdDayDelivery,
2378
+ zipCode,
2379
+ shippingMethodsContext,
2380
+ selectedShippingMethod,
2381
+ setSelectedShippingMethod,
2382
+ setShowTip
2383
+ ]);
2384
+ }
2385
+ var useReplaceCartPlusMember = () => {
2386
+ const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
2387
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
2388
+ const { cart } = useCartContext();
2389
+ const plusMonthly = plusMemberMetafields?.plus_monthly_product;
2390
+ const plusAnnual = plusMemberMetafields?.plus_annual_product;
2391
+ const handler = react.useCallback(async () => {
2392
+ const plusMonthlyInCart = cart?.lineItems.find(
2393
+ (item) => item.variant?.sku === plusMonthly?.sku
2394
+ );
2395
+ const plusAnnualInCart = cart?.lineItems.find(
2396
+ (item) => item.variant?.sku === plusAnnual?.sku
2397
+ );
2398
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
2399
+ await removeCartLines2({
2400
+ lineIds: [plusMonthlyInCart.id]
2401
+ });
2402
+ } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
2403
+ await removeCartLines2({
2404
+ lineIds: [plusAnnualInCart.id]
2405
+ });
2406
+ }
2407
+ }, [
2408
+ cart?.lineItems,
2409
+ selectedPlusMemberMode,
2410
+ plusMonthly?.sku,
2411
+ plusAnnual?.sku,
2412
+ removeCartLines2
2413
+ ]);
2414
+ return handler;
2415
+ };
2416
+ var usePlusMemberDeliveryCodes = ({
2417
+ deliveryData
2418
+ }) => {
2419
+ return react.useMemo(
2420
+ () => deliveryData?.deliveryCustomData?.discount_code,
2421
+ [deliveryData]
2422
+ );
2423
+ };
2424
+ var usePlusMemberItemCustomAttributes = ({
2425
+ deliveryData
2426
+ }) => {
2427
+ const { deliveryCustomData } = deliveryData || {};
2428
+ return react.useMemo(() => {
2429
+ const itemCustomAttributes = [];
2430
+ if (deliveryCustomData?.is_presale) {
2431
+ itemCustomAttributes.push({
2432
+ key: "_is_presale",
2433
+ value: "true"
2434
+ });
2435
+ }
2436
+ return itemCustomAttributes;
2437
+ }, [deliveryCustomData]);
2438
+ };
2439
+ var usePlusMemberCheckoutCustomAttributes = ({
2440
+ deliveryData,
2441
+ product,
2442
+ variant,
2443
+ customer,
2444
+ isShowShippingBenefits
2445
+ }) => {
2446
+ const { deliveryCustomData } = deliveryData || {};
2447
+ const { profile } = usePlusMemberContext();
2448
+ const userType = react.useMemo(() => {
2449
+ const customerInfo = customer;
2450
+ if (!customerInfo) {
2451
+ return "new_user_unlogin";
2452
+ }
2453
+ if (customer) {
2454
+ const { orders = {} } = customer;
2455
+ const edgesLength = orders?.edges?.length;
2456
+ if (edgesLength === 1) {
2457
+ return "old_user_orders_once";
2458
+ } else if (edgesLength && edgesLength > 1) {
2459
+ return "old_user_orders_twice";
2460
+ }
2461
+ }
2462
+ return "new_user_login";
2463
+ }, [customer]);
2464
+ return react.useMemo(() => {
2465
+ const checkoutCustomAttributes = [
2466
+ {
2467
+ key: "_token",
2468
+ value: profile?.token || ""
2469
+ },
2470
+ {
2471
+ key: "_last_url",
2472
+ value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2473
+ },
2474
+ {
2475
+ key: "_user_type",
2476
+ value: userType
2477
+ }
2478
+ ];
2479
+ if (profile) {
2480
+ checkoutCustomAttributes.push({
2481
+ key: "_login_user",
2482
+ value: "1"
2483
+ });
2484
+ }
2485
+ if (deliveryCustomData) {
2486
+ checkoutCustomAttributes.push({
2487
+ key: "_checkout_delivery_custom",
2488
+ value: JSON.stringify({
2489
+ ...deliveryCustomData,
2490
+ is_prime: profile?.isPlus
2491
+ })
2492
+ });
2493
+ }
2494
+ if (variant?.metafields?.presell) {
2495
+ checkoutCustomAttributes.push({
2496
+ key: "_presale",
2497
+ value: "true"
2498
+ });
2499
+ }
2500
+ if (isShowShippingBenefits && !isShowShippingBenefits({ variant, product, setting: {} })) {
2501
+ checkoutCustomAttributes.push({
2502
+ key: "_hide_shipping",
2503
+ value: "true"
2504
+ });
2505
+ }
2506
+ return checkoutCustomAttributes;
2507
+ }, [deliveryCustomData, product, profile, userType, variant, isShowShippingBenefits]);
2508
+ };
2509
+ function useAutoRemovePlusMemberInCart({
2510
+ metafields,
2511
+ isMonthlyPlus,
2512
+ isAnnualPlus
2513
+ }) {
2514
+ const { plus_monthly_product, plus_annual_product } = metafields || {};
2515
+ const { cart } = useCartContext();
2516
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
2517
+ react.useEffect(() => {
2518
+ if (!cart) return;
2519
+ const removePlusProduct = async (productType) => {
2520
+ if (!productType) return;
2521
+ const product = cart.lineItems?.find(
2522
+ (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
2523
+ );
2524
+ if (product) {
2525
+ await removeCartLines2({
2526
+ lineIds: [product.id]
2527
+ });
2528
+ }
2529
+ };
2530
+ if (isMonthlyPlus) {
2531
+ removePlusProduct(plus_monthly_product);
2532
+ }
2533
+ if (isAnnualPlus) {
2534
+ removePlusProduct(plus_annual_product);
2535
+ }
2536
+ }, [
2537
+ cart,
2538
+ plus_annual_product,
2539
+ plus_monthly_product,
2540
+ isAnnualPlus,
2541
+ isMonthlyPlus,
2542
+ removeCartLines2
2543
+ ]);
2544
+ }
2545
+ var PlusMemberProvider = ({
2546
+ variant,
2547
+ product,
2548
+ shopCommon,
2549
+ metafields,
2550
+ initialSelectedPlusMemberMode = "free",
2551
+ profile,
2552
+ locale,
2553
+ children
2554
+ }) => {
2555
+ const [zipCode, setZipCode] = react.useState("");
2556
+ const [showTip, setShowTip] = react.useState(false);
2557
+ const [selectedPlusMemberMode, setSelectedPlusMemberMode] = react.useState(
2558
+ initialSelectedPlusMemberMode
2559
+ );
2560
+ const [selectedShippingMethod, setSelectedShippingMethod] = react.useState();
2561
+ const [allowNextDayDelivery, setAllowNextDayDelivery] = react.useState(false);
2562
+ const [allowThirdDayDelivery, setAllowThirdDayDelivery] = react.useState(false);
2563
+ const [showAreaCheckModal, setShowAreaCheckModal] = react.useState(false);
2564
+ const [showMoreShippingMethod, setShowMoreShippingMethod] = react.useState(false);
2565
+ const [showPlusMemberBenefit, setShowPlusMemberBenefit] = react.useState(false);
2566
+ const [deleteMarginBottom, setDeleteMarginBottom] = react.useState(false);
2567
+ const shippingMethodsContext = useShippingMethods({
2568
+ variant,
2569
+ plusMemberMetafields: metafields,
2570
+ selectedPlusMemberMode});
2571
+ const plusMemberHandles = react.useMemo(() => {
2572
+ return [
2573
+ metafields?.plus_monthly_product?.handle,
2574
+ metafields?.plus_annual_product?.handle
2575
+ ].filter(Boolean);
2576
+ }, [metafields]);
2577
+ const { data: plusMemberProducts = [] } = useProductsByHandles({
2578
+ handles: plusMemberHandles
2579
+ });
2580
+ const selectedPlusMemberProduct = react.useMemo(() => {
2581
+ if (selectedPlusMemberMode === "free" /* FREE */) {
2582
+ return null;
2583
+ }
2584
+ const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? metafields?.plus_monthly_product?.handle : metafields?.plus_annual_product?.handle;
2585
+ const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? metafields?.plus_monthly_product?.sku : metafields?.plus_annual_product?.sku;
2586
+ const product2 = plusMemberProducts?.find((p) => p.handle === handle);
2587
+ const variant2 = product2?.variants?.find((v) => v.sku === sku);
2588
+ return product2 && variant2 ? { product: product2, variant: variant2 } : null;
2589
+ }, [plusMemberProducts, metafields, selectedPlusMemberMode]);
2590
+ return /* @__PURE__ */ jsxRuntime.jsx(
2591
+ PlusMemberContext.Provider,
2592
+ {
2593
+ value: {
2594
+ variant,
2595
+ shopCommon,
2596
+ zipCode,
2597
+ setZipCode,
2598
+ allowNextDayDelivery,
2599
+ setAllowNextDayDelivery,
2600
+ allowThirdDayDelivery,
2601
+ setAllowThirdDayDelivery,
2602
+ plusMemberMetafields: metafields,
2603
+ selectedPlusMemberMode,
2604
+ setSelectedPlusMemberMode,
2605
+ showAreaCheckModal,
2606
+ setShowAreaCheckModal,
2607
+ selectedShippingMethod,
2608
+ setSelectedShippingMethod,
2609
+ shippingMethodsContext,
2610
+ showTip,
2611
+ setShowTip,
2612
+ showMoreShippingMethod,
2613
+ setShowMoreShippingMethod,
2614
+ selectedPlusMemberProduct,
2615
+ plusMemberProducts,
2616
+ product,
2617
+ showPlusMemberBenefit,
2618
+ setShowPlusMemberBenefit,
2619
+ deleteMarginBottom,
2620
+ setDeleteMarginBottom,
2621
+ profile,
2622
+ locale
2623
+ },
2624
+ children
2625
+ }
2626
+ );
2627
+ };
2628
+ function useIntersection(targetRef, options) {
2629
+ const {
2630
+ callback,
2631
+ once = false,
2632
+ root = null,
2633
+ rootMargin = "0px",
2634
+ threshold = 0.8
2635
+ } = options;
2636
+ react.useEffect(() => {
2637
+ if (!targetRef?.current) {
2638
+ return;
2639
+ }
2640
+ if (typeof IntersectionObserver === "undefined") {
2641
+ console.warn("[useIntersection] IntersectionObserver is not supported");
2642
+ return;
2643
+ }
2644
+ const current = targetRef.current;
2645
+ const observerOptions = {
2646
+ root,
2647
+ rootMargin,
2648
+ threshold
2649
+ };
2650
+ const observer = new IntersectionObserver((entries) => {
2651
+ entries.forEach((entry) => {
2652
+ if (entry.isIntersecting) {
2653
+ callback();
2654
+ if (once) {
2655
+ observer.disconnect();
2656
+ }
2657
+ }
2658
+ });
2659
+ }, observerOptions);
2660
+ observer.observe(current);
2661
+ return () => {
2662
+ observer.disconnect();
2663
+ };
2664
+ }, [targetRef, callback, once, root, rootMargin, threshold]);
2665
+ }
2666
+ function useExposure(targetRef, options) {
2667
+ const { threshold = 0.5, duration = 2e3, once = true, onExposure } = options;
2668
+ const [isVisible, setIsVisible] = react.useState(false);
2669
+ const timeoutRef = react.useRef(void 0);
2670
+ const hasTriggeredRef = react.useRef(false);
2671
+ react.useEffect(() => {
2672
+ if (!targetRef?.current || typeof IntersectionObserver === "undefined") {
2673
+ return;
2674
+ }
2675
+ if (once && hasTriggeredRef.current) {
2676
+ return;
2677
+ }
2678
+ const current = targetRef.current;
2679
+ const clearTimer = () => {
2680
+ if (timeoutRef.current) {
2681
+ clearTimeout(timeoutRef.current);
2682
+ timeoutRef.current = void 0;
2683
+ }
2684
+ };
2685
+ const observer = new IntersectionObserver(
2686
+ (entries) => {
2687
+ entries.forEach((entry) => {
2688
+ setIsVisible(entry.isIntersecting);
2689
+ if (entry.isIntersecting) {
2690
+ timeoutRef.current = setTimeout(() => {
2691
+ if (once && hasTriggeredRef.current) {
2692
+ return;
2693
+ }
2694
+ onExposure();
2695
+ hasTriggeredRef.current = true;
2696
+ if (once) {
2697
+ observer.disconnect();
2698
+ }
2699
+ }, duration);
2700
+ } else {
2701
+ clearTimer();
2702
+ }
2703
+ });
2704
+ },
2705
+ {
2706
+ root: null,
2707
+ rootMargin: "0px",
2708
+ threshold
2709
+ }
2710
+ );
2711
+ observer.observe(current);
2712
+ return () => {
2713
+ clearTimer();
2714
+ observer.disconnect();
2715
+ };
2716
+ }, [targetRef, threshold, duration, once, onExposure]);
2717
+ return isVisible;
2718
+ }
2719
+ function determineSuggestedLocale(countryCode, mapping) {
2720
+ if (!countryCode) {
2721
+ return "us";
2722
+ }
2723
+ const upperCode = countryCode.toUpperCase();
2724
+ if (mapping?.customMapping?.[upperCode]) {
2725
+ return mapping.customMapping[upperCode];
2726
+ }
2727
+ if (mapping?.euCountries?.includes(upperCode)) {
2728
+ if (upperCode === "PL") {
2729
+ return "pl";
2730
+ }
2731
+ return "eu";
2732
+ }
2733
+ if (mapping?.auCountries?.includes(upperCode)) {
2734
+ return "au";
2735
+ }
2736
+ if (mapping?.deCountries?.includes(upperCode)) {
2737
+ return "de";
2738
+ }
2739
+ if (mapping?.aeEnCountries?.includes(upperCode)) {
2740
+ return "ae-en";
2741
+ }
2742
+ if (upperCode === "GB") {
2743
+ return "uk";
2744
+ }
2745
+ return countryCode.toLowerCase();
2746
+ }
2747
+ function useGeoLocation(options = {}) {
2748
+ const {
2749
+ endpoint = "/geolocation",
2750
+ cacheKey = "geoLocation",
2751
+ cacheDuration = 1e3 * 60 * 60 * 24,
2752
+ // 24 hours
2753
+ localeMapping,
2754
+ enableCache = true,
2755
+ ...swrOptions
2756
+ } = options;
2757
+ const fetcher = async () => {
2758
+ if (enableCache) {
2759
+ const cached = shopifySdk.getLocalStorage(cacheKey);
2760
+ if (cached) {
2761
+ return cached;
2762
+ }
2763
+ }
2764
+ try {
2765
+ const response = await fetch(endpoint);
2766
+ if (!response.ok) {
2767
+ throw new Error(`Failed to fetch geo location: ${response.status}`);
2768
+ }
2769
+ const result = await response.json();
2770
+ const countryCode = result?.geo?.country?.code;
2771
+ if (!countryCode) {
2772
+ console.warn("[useGeoLocation] No country code in response");
2773
+ return void 0;
2774
+ }
2775
+ const suggestLocale = determineSuggestedLocale(
2776
+ countryCode,
2777
+ localeMapping
2778
+ );
2779
+ const geoData = {
2780
+ geo: result.geo,
2781
+ suggestLocale
2782
+ };
2783
+ if (enableCache) {
2784
+ const expires = new Date(Date.now() + cacheDuration);
2785
+ shopifySdk.setLocalStorage(cacheKey, geoData, { expires });
2786
+ }
2787
+ return geoData;
2788
+ } catch (error) {
2789
+ console.error("[useGeoLocation] Error fetching geo data:", error);
2790
+ return void 0;
2791
+ }
2792
+ };
2793
+ return useSWR__default.default(
2794
+ cacheKey,
2795
+ fetcher,
2796
+ swrOptions
2797
+ );
2798
+ }
2799
+ function getCachedGeoLocation(cacheKey = "geoLocation") {
2800
+ return shopifySdk.getLocalStorage(cacheKey) ?? void 0;
2801
+ }
2802
+ function clearGeoLocationCache(cacheKey = "geoLocation") {
2803
+ if (typeof localStorage !== "undefined") {
2804
+ localStorage.removeItem(cacheKey);
2805
+ }
2806
+ }
2807
+
2808
+ exports.BuyRuleType = BuyRuleType;
2809
+ exports.CODE_AMOUNT_KEY = CODE_AMOUNT_KEY;
2810
+ exports.CUSTOMER_ATTRIBUTE_KEY = CUSTOMER_ATTRIBUTE_KEY;
2811
+ exports.CUSTOMER_SCRIPT_GIFT_KEY = CUSTOMER_SCRIPT_GIFT_KEY;
2812
+ exports.DeliveryPlusType = DeliveryPlusType;
2813
+ exports.MAIN_PRODUCT_CODE = MAIN_PRODUCT_CODE;
2814
+ exports.OrderBasePriceType = OrderBasePriceType;
2815
+ exports.OrderDiscountType = OrderDiscountType;
2816
+ exports.PLUS_MEMBER_TYPE = PLUS_MEMBER_TYPE;
2817
+ exports.PlusMemberContext = PlusMemberContext;
2818
+ exports.PlusMemberMode = PlusMemberMode;
2819
+ exports.PlusMemberProvider = PlusMemberProvider;
2820
+ exports.PriceBasePriceType = PriceBasePriceType;
2821
+ exports.PriceDiscountType = PriceDiscountType;
2822
+ exports.RuleType = RuleType;
2823
+ exports.SCRIPT_CODE_AMOUNT_KEY = SCRIPT_CODE_AMOUNT_KEY;
2824
+ exports.ShippingMethodMode = ShippingMethodMode;
2825
+ exports.SpendMoneyType = SpendMoneyType;
2826
+ exports.atobID = atobID;
2827
+ exports.btoaID = btoaID;
2828
+ exports.clearGeoLocationCache = clearGeoLocationCache;
2829
+ exports.currencyCodeMapping = currencyCodeMapping;
2830
+ exports.defaultSWRMutationConfiguration = defaultSWRMutationConfiguration;
2831
+ exports.formatFunctionAutoFreeGift = formatFunctionAutoFreeGift;
2832
+ exports.formatScriptAutoFreeGift = formatScriptAutoFreeGift;
2833
+ exports.getCachedGeoLocation = getCachedGeoLocation;
2834
+ exports.getDiscountEnvAttributeValue = getDiscountEnvAttributeValue;
2835
+ exports.getMatchedMainProductSubTotal = getMatchedMainProductSubTotal;
2836
+ exports.getQuery = getQuery;
2837
+ exports.getReferralAttributes = getReferralAttributes;
2838
+ exports.isAttributesEqual = isAttributesEqual;
2839
+ exports.preCheck = preCheck;
2840
+ exports.safeParseJson = safeParseJson;
2841
+ exports.useAddCartLines = useAddCartLines;
2842
+ exports.useAddToCart = useAddToCart;
2843
+ exports.useAllBlogs = useAllBlogs;
2844
+ exports.useAllCollections = useAllCollections;
2845
+ exports.useAllProducts = useAllProducts;
2846
+ exports.useApplyCartCodes = useApplyCartCodes;
2847
+ exports.useArticle = useArticle;
2848
+ exports.useArticles = useArticles;
2849
+ exports.useArticlesInBlog = useArticlesInBlog;
2850
+ exports.useAutoRemovePlusMemberInCart = useAutoRemovePlusMemberInCart;
2851
+ exports.useBlog = useBlog;
2852
+ exports.useBuyNow = useBuyNow;
2853
+ exports.useCalcAutoFreeGift = useCalcAutoFreeGift;
2854
+ exports.useCalcOrderDiscount = useCalcOrderDiscount;
2855
+ exports.useCartAttributes = useCartAttributes;
2856
+ exports.useCartItemQuantityLimit = useCartItemQuantityLimit;
2857
+ exports.useCollection = useCollection;
2858
+ exports.useCollections = useCollections;
2859
+ exports.useCreateCart = useCreateCart;
2860
+ exports.useExposure = useExposure;
2861
+ exports.useGeoLocation = useGeoLocation;
2862
+ exports.useHasPlusMemberInCart = useHasPlusMemberInCart;
2863
+ exports.useIntersection = useIntersection;
2864
+ exports.usePlusAnnualProductVariant = usePlusAnnualProductVariant;
2865
+ exports.usePlusMemberCheckoutCustomAttributes = usePlusMemberCheckoutCustomAttributes;
2866
+ exports.usePlusMemberContext = usePlusMemberContext;
2867
+ exports.usePlusMemberDeliveryCodes = usePlusMemberDeliveryCodes;
2868
+ exports.usePlusMemberItemCustomAttributes = usePlusMemberItemCustomAttributes;
2869
+ exports.usePlusMonthlyProductVariant = usePlusMonthlyProductVariant;
2870
+ exports.usePrice = usePrice;
2871
+ exports.useProduct = useProduct;
2872
+ exports.useProductUrl = useProductUrl;
2873
+ exports.useProductsByHandles = useProductsByHandles;
2874
+ exports.useRemoveCartCodes = useRemoveCartCodes;
2875
+ exports.useRemoveCartLines = useRemoveCartLines;
2876
+ exports.useReplaceCartPlusMember = useReplaceCartPlusMember;
2877
+ exports.useScriptAutoFreeGift = useScriptAutoFreeGift;
2878
+ exports.useSearch = useSearch;
2879
+ exports.useSelectedOptions = useSelectedOptions;
2880
+ exports.useShippingMethodAvailableCheck = useShippingMethodAvailableCheck;
2881
+ exports.useShippingMethods = useShippingMethods;
2882
+ exports.useSite = useSite;
2883
+ exports.useUpdateCartAttributes = useUpdateCartAttributes;
2884
+ exports.useUpdateCartLines = useUpdateCartLines;
2885
+ exports.useUpdateLineCodeAmountAttributes = useUpdateLineCodeAmountAttributes;
2886
+ exports.useUpdateVariantQuery = useUpdateVariantQuery;
2887
+ exports.useVariant = useVariant;
2888
+ exports.useVariantMedia = useVariantMedia;
2889
+ //# sourceMappingURL=index.js.map
2890
+ //# sourceMappingURL=index.js.map