@anker-in/shopify-react 0.1.1-beta.0 → 0.1.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +350 -138
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +345 -138
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-DenyuVGJ.d.mts → index-CwP6qHUo.d.mts} +197 -151
- package/dist/{index-BUWkkUdh.d.ts → index-Dwc-_zEo.d.ts} +197 -151
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +375 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +370 -149
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +4 -1
- package/dist/provider/index.d.ts +4 -1
- package/dist/provider/index.js +147 -41
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +147 -41
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-CMA6_FML.d.mts → types-CUv-lzQk.d.mts} +89 -78
- package/dist/{types-CMA6_FML.d.ts → types-CUv-lzQk.d.ts} +89 -78
- package/package.json +2 -2
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useMemo, useRef, useState, useEffect, useCallback, useContext } from 'react';
|
|
2
2
|
import useSWRMutation from 'swr/mutation';
|
|
3
|
-
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
3
|
+
import { getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getLocalStorage, setLocalStorage, updateCartDeliveryOptions } from '@anker-in/shopify-sdk';
|
|
4
4
|
import Cookies5 from 'js-cookie';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
import Decimal2 from 'decimal.js';
|
|
@@ -62,6 +62,81 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
62
62
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
63
63
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
64
64
|
|
|
65
|
+
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
66
|
+
function normalizeAddToCartLines(lines) {
|
|
67
|
+
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
68
|
+
const variant = line.variant;
|
|
69
|
+
const product = variant.product;
|
|
70
|
+
const quantity = line.quantity || 1;
|
|
71
|
+
const price = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
72
|
+
const subtotalAmount = price * quantity;
|
|
73
|
+
const totalAmount = subtotalAmount;
|
|
74
|
+
return {
|
|
75
|
+
id: `temp-line-${index}-${variant.id}`,
|
|
76
|
+
// Temporary ID for pre-cart lines
|
|
77
|
+
name: product?.title || variant.title || "",
|
|
78
|
+
quantity,
|
|
79
|
+
variantId: variant.id,
|
|
80
|
+
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
81
|
+
totalAmount,
|
|
82
|
+
subtotalAmount,
|
|
83
|
+
discountAllocations: [],
|
|
84
|
+
customAttributes: line.attributes || [],
|
|
85
|
+
variant: {
|
|
86
|
+
id: variant.id,
|
|
87
|
+
price,
|
|
88
|
+
listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
|
|
89
|
+
sku: variant.sku || "",
|
|
90
|
+
name: variant.title || "",
|
|
91
|
+
image: variant.image ? {
|
|
92
|
+
url: variant.image.url,
|
|
93
|
+
altText: variant.image.altText || void 0
|
|
94
|
+
} : void 0,
|
|
95
|
+
requiresShipping: false,
|
|
96
|
+
// Default value, not available in NormalizedProductVariant
|
|
97
|
+
availableForSale: variant.availableForSale ?? true,
|
|
98
|
+
quantityAvailable: variant.quantityAvailable ?? 0,
|
|
99
|
+
currentlyNotInStock: false,
|
|
100
|
+
// Default value, will be updated when added to cart
|
|
101
|
+
weight: variant.weight,
|
|
102
|
+
metafields: variant.metafields
|
|
103
|
+
},
|
|
104
|
+
product,
|
|
105
|
+
path: product?.handle ? `/products/${product.handle}` : "",
|
|
106
|
+
discounts: [],
|
|
107
|
+
options: variant.selectedOptions?.map((opt) => ({
|
|
108
|
+
name: opt.name,
|
|
109
|
+
value: opt.value
|
|
110
|
+
}))
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function createMockCartFromLines(lines, existingCart) {
|
|
115
|
+
const normalizedLines = normalizeAddToCartLines(lines);
|
|
116
|
+
const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
|
|
117
|
+
const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
|
|
118
|
+
return {
|
|
119
|
+
id: existingCart?.id || "temp-cart-id",
|
|
120
|
+
customerId: existingCart?.customerId,
|
|
121
|
+
email: existingCart?.email,
|
|
122
|
+
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
123
|
+
currency: existingCart?.currency || { code: "USD" },
|
|
124
|
+
taxesIncluded: existingCart?.taxesIncluded,
|
|
125
|
+
lineItems: normalizedLines,
|
|
126
|
+
totalLineItemsDiscount: 0,
|
|
127
|
+
orderDiscounts: 0,
|
|
128
|
+
lineItemsSubtotalPrice: subtotalPrice,
|
|
129
|
+
subtotalPrice,
|
|
130
|
+
totalPrice,
|
|
131
|
+
totalTaxAmount: 0,
|
|
132
|
+
discountCodes: existingCart?.discountCodes || [],
|
|
133
|
+
discountAllocations: [],
|
|
134
|
+
url: existingCart?.url || "",
|
|
135
|
+
ready: true,
|
|
136
|
+
customAttributes: existingCart?.customAttributes
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
65
140
|
// src/hooks/cart/utils/index.ts
|
|
66
141
|
var getQuery = () => {
|
|
67
142
|
const url = typeof window !== "undefined" ? window.location.search : "";
|
|
@@ -101,25 +176,25 @@ var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
|
|
|
101
176
|
return acc + (main_product?.spend_money_type === 1 /* ORIGIN_PRICE */ ? Number(line.subtotalAmount) || 0 : Number(line.totalAmount) || 0);
|
|
102
177
|
}, 0) || 0;
|
|
103
178
|
};
|
|
104
|
-
var
|
|
105
|
-
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
106
|
-
return safeParseJson(attr?.value ?? "") ?? {};
|
|
107
|
-
};
|
|
108
|
-
var isAttributesEqual = (attrs1 = [], attrs2 = []) => {
|
|
109
|
-
if (attrs1.length !== attrs2.length) return false;
|
|
110
|
-
const sorted1 = [...attrs1].sort((a, b) => a.key.localeCompare(b.key));
|
|
111
|
-
const sorted2 = [...attrs2].sort((a, b) => a.key.localeCompare(b.key));
|
|
112
|
-
return sorted1.every(
|
|
113
|
-
(attr, i) => attr.key === sorted2[i]?.key && attr.value === sorted2[i]?.value
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
var safeParseJson = (str) => {
|
|
179
|
+
var safeParse = (str) => {
|
|
117
180
|
try {
|
|
118
181
|
return JSON.parse(str);
|
|
119
182
|
} catch (err) {
|
|
120
183
|
return {};
|
|
121
184
|
}
|
|
122
185
|
};
|
|
186
|
+
var getDiscountEnvAttributeValue = (attributes = []) => {
|
|
187
|
+
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
188
|
+
return safeParse(attr?.value ?? "") ?? {};
|
|
189
|
+
};
|
|
190
|
+
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
191
|
+
return oldAttributes.some((attr) => {
|
|
192
|
+
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
193
|
+
return newAttr ? newAttr.value !== attr.value : true;
|
|
194
|
+
}) || newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || customAttributesNeedRemove.some(
|
|
195
|
+
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
196
|
+
);
|
|
197
|
+
};
|
|
123
198
|
var containsAll = (source, requiredItems = []) => {
|
|
124
199
|
if (!requiredItems?.length) return true;
|
|
125
200
|
const sourceSet = new Set(source);
|
|
@@ -286,12 +361,18 @@ var formatFunctionAutoFreeGift = ({
|
|
|
286
361
|
};
|
|
287
362
|
return result;
|
|
288
363
|
};
|
|
289
|
-
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
364
|
+
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
290
365
|
const tags = useMemo(() => customer?.tags || [], [customer?.tags]);
|
|
291
366
|
const isCustomerLoading = useMemo(() => !customer ? true : false, [customer]);
|
|
292
367
|
const dealsType = "";
|
|
293
368
|
const { client, locale } = useShopify();
|
|
294
369
|
const giftProductsCache = useRef(null);
|
|
370
|
+
const effectiveCart = useMemo(() => {
|
|
371
|
+
if (lines && lines.length > 0) {
|
|
372
|
+
return createMockCartFromLines(lines, cart);
|
|
373
|
+
}
|
|
374
|
+
return cart;
|
|
375
|
+
}, [lines, cart]);
|
|
295
376
|
const { activeCampaign, subtotal } = useMemo(() => {
|
|
296
377
|
for (const campaign of autoFreeGiftConfig) {
|
|
297
378
|
const { rule_conditions = [], rule_result } = campaign;
|
|
@@ -299,7 +380,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
299
380
|
const isPreCheckPassed = preCheck(rule_conditions, tags, []);
|
|
300
381
|
if (isPreCheckPassed && spend_get_reward) {
|
|
301
382
|
const matchedSubtotal = getMatchedMainProductSubTotal(
|
|
302
|
-
|
|
383
|
+
effectiveCart,
|
|
303
384
|
spend_get_reward.main_product?.variant_list?.map((v) => v.variant_id) || [],
|
|
304
385
|
{
|
|
305
386
|
spend_money_type: spend_get_reward.main_product?.spend_money_type || 1,
|
|
@@ -313,13 +394,13 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
313
394
|
}
|
|
314
395
|
}
|
|
315
396
|
return { activeCampaign: null, subtotal: 0 };
|
|
316
|
-
}, [autoFreeGiftConfig,
|
|
397
|
+
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
317
398
|
const { qualifyingGift, nextTierGoal } = useMemo(() => {
|
|
318
399
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
319
400
|
return { qualifyingGift: null, nextTierGoal: null };
|
|
320
401
|
}
|
|
321
402
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
322
|
-
const qualifyingTier = [...giftTiers].
|
|
403
|
+
const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
|
|
323
404
|
const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
|
|
324
405
|
if (!qualifyingTier) {
|
|
325
406
|
return { qualifyingGift: null, nextTierGoal: nextGoal || null };
|
|
@@ -396,18 +477,33 @@ var useScriptAutoFreeGift = ({
|
|
|
396
477
|
campaign,
|
|
397
478
|
_giveaway,
|
|
398
479
|
cart,
|
|
399
|
-
locale: providedLocale
|
|
480
|
+
locale: providedLocale,
|
|
481
|
+
lines
|
|
400
482
|
}) => {
|
|
401
483
|
const { client, locale: contextLocale } = useShopify();
|
|
402
484
|
const locale = providedLocale || contextLocale;
|
|
403
485
|
const [points_subscribe, set_points_subscribe] = useState(false);
|
|
404
486
|
const giftProductsCache = useRef(null);
|
|
487
|
+
const effectiveCart = useMemo(() => {
|
|
488
|
+
if (lines && lines.length > 0) {
|
|
489
|
+
return createMockCartFromLines(lines, cart);
|
|
490
|
+
}
|
|
491
|
+
return cart;
|
|
492
|
+
}, [lines, cart]);
|
|
405
493
|
useEffect(() => {
|
|
406
494
|
if (locale === "au") {
|
|
407
495
|
const isPointsSubscribe = Cookies5.get("points_subscribe");
|
|
408
496
|
set_points_subscribe(!!isPointsSubscribe);
|
|
409
497
|
}
|
|
410
498
|
}, [locale]);
|
|
499
|
+
const isActivityAvailable = useMemo(() => {
|
|
500
|
+
if (!campaign) return false;
|
|
501
|
+
const query = getQuery();
|
|
502
|
+
const utmCampaign = Cookies5.get("utm_campaign") || query?.utm_campaign;
|
|
503
|
+
if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
|
|
504
|
+
return false;
|
|
505
|
+
return true;
|
|
506
|
+
}, [campaign]);
|
|
411
507
|
const [upgrade_multiple, upgrade_value] = useMemo(() => {
|
|
412
508
|
let upgrade_multiple2 = 1;
|
|
413
509
|
let upgrade_value2 = 0;
|
|
@@ -415,17 +511,17 @@ var useScriptAutoFreeGift = ({
|
|
|
415
511
|
upgrade_multiple2 = 1.2;
|
|
416
512
|
upgrade_value2 = 40;
|
|
417
513
|
}
|
|
418
|
-
|
|
514
|
+
effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
|
|
419
515
|
customAttributes?.forEach(({ key, value }) => {
|
|
420
516
|
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
421
517
|
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
422
518
|
});
|
|
423
519
|
});
|
|
424
520
|
return [upgrade_multiple2, upgrade_value2];
|
|
425
|
-
}, [
|
|
521
|
+
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
426
522
|
const breakpoints = useMemo(() => {
|
|
427
|
-
if (!
|
|
428
|
-
return (campaign
|
|
523
|
+
if (!isActivityAvailable) return [];
|
|
524
|
+
return (campaign?.breakpoints || []).map((item) => ({
|
|
429
525
|
breakpoint: new Decimal2(item.breakpoint).minus(new Decimal2(upgrade_value)).dividedBy(new Decimal2(upgrade_multiple)).toFixed(2, Decimal2.ROUND_DOWN),
|
|
430
526
|
giveawayProducts: item.giveawayProducts || []
|
|
431
527
|
}));
|
|
@@ -449,25 +545,26 @@ var useScriptAutoFreeGift = ({
|
|
|
449
545
|
return true;
|
|
450
546
|
}, [giftHandles]);
|
|
451
547
|
const involvedLines = useMemo(() => {
|
|
452
|
-
if (!
|
|
453
|
-
return (
|
|
548
|
+
if (!isActivityAvailable) return [];
|
|
549
|
+
return (effectiveCart?.lineItems || []).filter((line) => {
|
|
454
550
|
const isNotGift = line?.totalAmount && Number(line.totalAmount) > 0 && line.customAttributes?.every(
|
|
455
551
|
(item) => item.key !== _giveaway
|
|
456
552
|
);
|
|
457
553
|
const hasCampaignTag = line.product?.tags?.some(
|
|
458
|
-
(tag) => campaign
|
|
554
|
+
(tag) => campaign?.includeTags?.includes(tag.trim()) && line.variant?.availableForSale
|
|
459
555
|
);
|
|
460
556
|
return isNotGift && hasCampaignTag;
|
|
461
557
|
});
|
|
462
|
-
}, [
|
|
558
|
+
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
463
559
|
const involvedSubTotal = useMemo(() => {
|
|
464
|
-
if (!
|
|
560
|
+
if (!isActivityAvailable) return new Decimal2(0);
|
|
465
561
|
return involvedLines.reduce((prev, item) => {
|
|
466
|
-
const amount = campaign
|
|
562
|
+
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
467
563
|
return new Decimal2(prev).plus(new Decimal2(amount || 0));
|
|
468
564
|
}, new Decimal2(0));
|
|
469
|
-
}, [involvedLines,
|
|
565
|
+
}, [involvedLines, isActivityAvailable]);
|
|
470
566
|
const [freeGiftLevel, nextFreeGiftLevel] = useMemo(() => {
|
|
567
|
+
if (!isActivityAvailable) return [null, null];
|
|
471
568
|
const sortedLevels = [...breakpoints].sort(
|
|
472
569
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
473
570
|
);
|
|
@@ -597,8 +694,6 @@ function useAddCartLines(options) {
|
|
|
597
694
|
);
|
|
598
695
|
return useSWRMutation("add-cart-lines", addLines, options);
|
|
599
696
|
}
|
|
600
|
-
|
|
601
|
-
// src/tracking/ga.ts
|
|
602
697
|
var gaTrack = (data) => {
|
|
603
698
|
if (typeof window === "undefined") {
|
|
604
699
|
return;
|
|
@@ -616,18 +711,19 @@ var gaTrack = (data) => {
|
|
|
616
711
|
};
|
|
617
712
|
var trackAddToCartGA = ({
|
|
618
713
|
lineItems = [],
|
|
619
|
-
gtmParams = {}
|
|
620
|
-
brand
|
|
714
|
+
gtmParams = {}
|
|
621
715
|
}) => {
|
|
622
716
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
623
717
|
return;
|
|
624
718
|
}
|
|
625
719
|
const { variant } = lineItems[0];
|
|
626
|
-
const currencyCode = variant?.price?.currencyCode;
|
|
627
|
-
const totalPrice = lineItems
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
720
|
+
const currencyCode = variant.product?.price?.currencyCode;
|
|
721
|
+
const totalPrice = lineItems?.reduce(
|
|
722
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
723
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? variant2?.price?.amount ?? 0
|
|
724
|
+
),
|
|
725
|
+
new Decimal2(0)
|
|
726
|
+
).toNumber();
|
|
631
727
|
gaTrack({
|
|
632
728
|
event: "ga4Event",
|
|
633
729
|
event_name: "add_to_cart",
|
|
@@ -638,11 +734,11 @@ var trackAddToCartGA = ({
|
|
|
638
734
|
position: gtmParams?.position || "",
|
|
639
735
|
items: lineItems.map(({ variant: variant2, quantity }) => ({
|
|
640
736
|
item_id: variant2?.sku,
|
|
641
|
-
item_name: variant2?.product?.title || variant2?.product?.
|
|
642
|
-
item_brand:
|
|
737
|
+
item_name: variant2?.product?.title || variant2?.product?.title,
|
|
738
|
+
item_brand: gtmParams?.brand || "",
|
|
643
739
|
item_category: variant2?.product?.productType || "",
|
|
644
|
-
item_variant: variant2?.title || variant2?.
|
|
645
|
-
price: variant2?.
|
|
740
|
+
item_variant: variant2?.title || variant2?.title,
|
|
741
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
646
742
|
quantity: quantity || 1
|
|
647
743
|
})),
|
|
648
744
|
...gtmParams?.ga4Params
|
|
@@ -651,19 +747,19 @@ var trackAddToCartGA = ({
|
|
|
651
747
|
};
|
|
652
748
|
var trackBuyNowGA = ({
|
|
653
749
|
lineItems = [],
|
|
654
|
-
gtmParams = {}
|
|
655
|
-
brand
|
|
750
|
+
gtmParams = {}
|
|
656
751
|
}) => {
|
|
657
752
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
658
753
|
return;
|
|
659
754
|
}
|
|
660
755
|
const { variant } = lineItems[0];
|
|
661
756
|
const currencyCode = variant.price?.currencyCode;
|
|
662
|
-
const totalPrice = lineItems
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
757
|
+
const totalPrice = lineItems?.reduce(
|
|
758
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
759
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? (variant2?.price?.amount || 0)
|
|
760
|
+
),
|
|
761
|
+
new Decimal2(0)
|
|
762
|
+
).toNumber();
|
|
667
763
|
gaTrack({
|
|
668
764
|
event: "ga4Event",
|
|
669
765
|
event_name: "begin_checkout",
|
|
@@ -675,10 +771,10 @@ var trackBuyNowGA = ({
|
|
|
675
771
|
items: lineItems.map((item) => ({
|
|
676
772
|
item_id: item.variant?.sku,
|
|
677
773
|
item_name: item.variant?.product?.title || item.variant?.title,
|
|
678
|
-
item_brand:
|
|
774
|
+
item_brand: gtmParams?.brand || "",
|
|
679
775
|
item_category: item.variant?.product?.productType || "",
|
|
680
776
|
item_variant: item.variant?.title,
|
|
681
|
-
price: item.
|
|
777
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
682
778
|
quantity: item.quantity || 1
|
|
683
779
|
})),
|
|
684
780
|
...gtmParams?.ga4Params
|
|
@@ -692,10 +788,10 @@ var trackAddToCartFBQ = ({ lineItems = [] }) => {
|
|
|
692
788
|
return;
|
|
693
789
|
}
|
|
694
790
|
if (lineItems.length && lineItems[0]?.variant) {
|
|
695
|
-
const { variant, quantity
|
|
791
|
+
const { variant, quantity } = lineItems[0];
|
|
696
792
|
try {
|
|
697
793
|
window.fbq("track", "AddToCart", {
|
|
698
|
-
value:
|
|
794
|
+
value: variant?.compareAtPrice?.amount ?? (variant?.price?.amount || variant?.price || 0),
|
|
699
795
|
num_items: quantity,
|
|
700
796
|
currency: variant?.price?.currencyCode,
|
|
701
797
|
content_name: variant?.product?.title,
|
|
@@ -782,9 +878,9 @@ function useRemoveCartCodes(options) {
|
|
|
782
878
|
}
|
|
783
879
|
|
|
784
880
|
// src/hooks/cart/use-add-to-cart.ts
|
|
785
|
-
function useAddToCart({ withTrack = true
|
|
786
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
787
|
-
const {
|
|
881
|
+
function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
882
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
883
|
+
const { cart } = useCartContext();
|
|
788
884
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
789
885
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
790
886
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
@@ -806,7 +902,8 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
806
902
|
const lines = lineItems.map((item) => ({
|
|
807
903
|
merchandiseId: item.variant?.id || "",
|
|
808
904
|
quantity: item.quantity || 1,
|
|
809
|
-
attributes: item.attributes
|
|
905
|
+
attributes: item.attributes,
|
|
906
|
+
sellingPlanId: item.sellingPlanId
|
|
810
907
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
811
908
|
if (lines.length === 0) {
|
|
812
909
|
return;
|
|
@@ -820,6 +917,7 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
820
917
|
if (!resultCart) {
|
|
821
918
|
return void 0;
|
|
822
919
|
}
|
|
920
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
823
921
|
if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
824
922
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
825
923
|
if (unapplicableCodes.length > 0) {
|
|
@@ -841,34 +939,16 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
841
939
|
discountCodes
|
|
842
940
|
});
|
|
843
941
|
}
|
|
844
|
-
if (withTrack
|
|
845
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
846
|
-
variant: {
|
|
847
|
-
id: line.variant.id,
|
|
848
|
-
sku: line.variant.sku || "",
|
|
849
|
-
title: line.variant.name,
|
|
850
|
-
price: {
|
|
851
|
-
amount: String(line.variant.price),
|
|
852
|
-
currencyCode: resultCart.currency.code
|
|
853
|
-
},
|
|
854
|
-
product: line.product ? {
|
|
855
|
-
title: line.product.title || line.name,
|
|
856
|
-
productType: line.product.productType,
|
|
857
|
-
vendor: line.product.vendor
|
|
858
|
-
} : void 0
|
|
859
|
-
},
|
|
860
|
-
quantity: line.quantity
|
|
861
|
-
}));
|
|
942
|
+
if (withTrack) {
|
|
862
943
|
trackAddToCartGA({
|
|
863
|
-
lineItems
|
|
864
|
-
gtmParams: { ...gtmParams, brand }
|
|
865
|
-
brand
|
|
944
|
+
lineItems,
|
|
945
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
866
946
|
});
|
|
867
|
-
trackAddToCartFBQ({ lineItems
|
|
947
|
+
trackAddToCartFBQ({ lineItems });
|
|
868
948
|
}
|
|
869
949
|
return resultCart;
|
|
870
950
|
},
|
|
871
|
-
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack
|
|
951
|
+
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack]
|
|
872
952
|
);
|
|
873
953
|
return useSWRMutation("add-to-cart", addToCart, swrOptions);
|
|
874
954
|
}
|
|
@@ -949,8 +1029,8 @@ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
|
|
|
949
1029
|
);
|
|
950
1030
|
return useSWRMutation("update-cart-attributes", updateAttributes, options);
|
|
951
1031
|
}
|
|
952
|
-
function useBuyNow({ withTrack = true
|
|
953
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
1032
|
+
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
1033
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
954
1034
|
const isLoggedIn = userAdapter?.isLoggedIn || false;
|
|
955
1035
|
const buyNow = useCallback(
|
|
956
1036
|
async (_key, { arg }) => {
|
|
@@ -968,9 +1048,10 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
968
1048
|
return;
|
|
969
1049
|
}
|
|
970
1050
|
const lines = lineItems.map((item) => ({
|
|
971
|
-
merchandiseId: item.variant?.id ||
|
|
1051
|
+
merchandiseId: item.variant?.id || "",
|
|
972
1052
|
quantity: item.quantity || 1,
|
|
973
|
-
attributes: item.attributes
|
|
1053
|
+
attributes: item.attributes,
|
|
1054
|
+
sellingPlanId: item.sellingPlanId
|
|
974
1055
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
975
1056
|
if (lines.length === 0) {
|
|
976
1057
|
return;
|
|
@@ -987,27 +1068,9 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
987
1068
|
throw new Error("Failed to create cart for buy now");
|
|
988
1069
|
}
|
|
989
1070
|
if (withTrack && resultCart.lineItems) {
|
|
990
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
991
|
-
variant: {
|
|
992
|
-
id: line.variantId,
|
|
993
|
-
sku: line.variant.sku || "",
|
|
994
|
-
title: line.variant.name,
|
|
995
|
-
price: {
|
|
996
|
-
amount: String(line.variant.price),
|
|
997
|
-
currencyCode: resultCart.currency.code
|
|
998
|
-
},
|
|
999
|
-
product: line.product ? {
|
|
1000
|
-
title: line.product.title || line.name,
|
|
1001
|
-
productType: line.product.productType,
|
|
1002
|
-
vendor: line.product.vendor
|
|
1003
|
-
} : void 0
|
|
1004
|
-
},
|
|
1005
|
-
quantity: line.quantity
|
|
1006
|
-
}));
|
|
1007
1071
|
trackBuyNowGA({
|
|
1008
|
-
lineItems
|
|
1009
|
-
gtmParams: { ...gtmParams, brand }
|
|
1010
|
-
brand
|
|
1072
|
+
lineItems,
|
|
1073
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
1011
1074
|
});
|
|
1012
1075
|
if (fbqTrackConfig) {
|
|
1013
1076
|
trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
|
|
@@ -1024,10 +1087,64 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1024
1087
|
}
|
|
1025
1088
|
return resultCart;
|
|
1026
1089
|
},
|
|
1027
|
-
[client, locale, isLoggedIn, cartCookieAdapter, withTrack
|
|
1090
|
+
[client, locale, isLoggedIn, cartCookieAdapter, withTrack]
|
|
1028
1091
|
);
|
|
1029
1092
|
return useSWRMutation("buy-now", buyNow, swrOptions);
|
|
1030
1093
|
}
|
|
1094
|
+
function useCalcGiftsFromLines({
|
|
1095
|
+
lines,
|
|
1096
|
+
customer,
|
|
1097
|
+
scriptGiveawayKey = CUSTOMER_SCRIPT_GIFT_KEY
|
|
1098
|
+
}) {
|
|
1099
|
+
const { locale } = useShopify();
|
|
1100
|
+
const { cart, autoFreeGiftConfig, gradientGiftsConfig } = useCartContext();
|
|
1101
|
+
const functionGift = useCalcAutoFreeGift(cart, autoFreeGiftConfig || [], customer, lines);
|
|
1102
|
+
const scriptGift = useScriptAutoFreeGift({
|
|
1103
|
+
campaign: gradientGiftsConfig || null,
|
|
1104
|
+
_giveaway: scriptGiveawayKey,
|
|
1105
|
+
cart,
|
|
1106
|
+
locale,
|
|
1107
|
+
lines
|
|
1108
|
+
});
|
|
1109
|
+
const allGiftLines = useMemo(() => {
|
|
1110
|
+
const functionGiftLines = functionGift.qualifyingGift?.itemsToAdd || [];
|
|
1111
|
+
const scriptGiftLines = scriptGift.freeGiftLevel ? scriptGift.freeGiftLevel.giveawayProducts.map((product) => {
|
|
1112
|
+
const giftProduct = scriptGift.giftProductsResult?.find(
|
|
1113
|
+
(p) => p.handle === product.handle
|
|
1114
|
+
);
|
|
1115
|
+
const variant = giftProduct?.variants?.[0];
|
|
1116
|
+
return {
|
|
1117
|
+
variant: {
|
|
1118
|
+
id: variant?.id || "",
|
|
1119
|
+
handle: product.handle,
|
|
1120
|
+
sku: product.sku
|
|
1121
|
+
},
|
|
1122
|
+
quantity: 1,
|
|
1123
|
+
attributes: [
|
|
1124
|
+
{
|
|
1125
|
+
key: scriptGiveawayKey,
|
|
1126
|
+
value: "true"
|
|
1127
|
+
}
|
|
1128
|
+
]
|
|
1129
|
+
};
|
|
1130
|
+
}).filter((item) => item.variant.id) : [];
|
|
1131
|
+
return [...functionGiftLines, ...scriptGiftLines];
|
|
1132
|
+
}, [
|
|
1133
|
+
functionGift.qualifyingGift,
|
|
1134
|
+
scriptGift.freeGiftLevel,
|
|
1135
|
+
scriptGift.giftProductsResult,
|
|
1136
|
+
scriptGiveawayKey
|
|
1137
|
+
]);
|
|
1138
|
+
const hasGifts = useMemo(() => {
|
|
1139
|
+
return allGiftLines.length > 0;
|
|
1140
|
+
}, [allGiftLines]);
|
|
1141
|
+
return {
|
|
1142
|
+
functionGift,
|
|
1143
|
+
scriptGift,
|
|
1144
|
+
allGiftLines,
|
|
1145
|
+
hasGifts
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1031
1148
|
|
|
1032
1149
|
// src/hooks/cart/types/order-discount.ts
|
|
1033
1150
|
var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
|
|
@@ -1177,8 +1294,6 @@ var useCartAttributes = ({
|
|
|
1177
1294
|
memberSetting,
|
|
1178
1295
|
cart
|
|
1179
1296
|
});
|
|
1180
|
-
console.log("memberSetting", memberSetting);
|
|
1181
|
-
console.log("hasPlusMember", hasPlusMember);
|
|
1182
1297
|
useEffect(() => {
|
|
1183
1298
|
setCurrentUrl(window.location.href);
|
|
1184
1299
|
}, []);
|
|
@@ -1227,15 +1342,19 @@ var useCartAttributes = ({
|
|
|
1227
1342
|
];
|
|
1228
1343
|
}, [profile?.memberType, profile?.token, userType, hasPlusMember]);
|
|
1229
1344
|
const functionAttributes = useMemo(() => {
|
|
1230
|
-
|
|
1231
|
-
|
|
1345
|
+
const hasFunctionEnvAttribute = cart?.lineItems.some(
|
|
1346
|
+
(item) => item.customAttributes?.some((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY)
|
|
1347
|
+
);
|
|
1348
|
+
const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
|
|
1349
|
+
return hasFunctionEnvAttribute ? [
|
|
1350
|
+
{
|
|
1232
1351
|
key: "_discounts_function_env",
|
|
1233
1352
|
value: JSON.stringify({
|
|
1234
|
-
discount_code:
|
|
1353
|
+
discount_code: discountCodes,
|
|
1235
1354
|
user_tags: customer?.tags || []
|
|
1236
1355
|
})
|
|
1237
1356
|
}
|
|
1238
|
-
];
|
|
1357
|
+
] : [];
|
|
1239
1358
|
}, [cart]);
|
|
1240
1359
|
const presellAttributes = useMemo(() => {
|
|
1241
1360
|
return [
|
|
@@ -2412,6 +2531,69 @@ var usePlusMemberDeliveryCodes = ({
|
|
|
2412
2531
|
[deliveryData]
|
|
2413
2532
|
);
|
|
2414
2533
|
};
|
|
2534
|
+
function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
|
|
2535
|
+
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2536
|
+
const updateDeliveryOptions = useCallback(
|
|
2537
|
+
async (_key, { arg }) => {
|
|
2538
|
+
const updatedCart = await updateCartDeliveryOptions(client, {
|
|
2539
|
+
...arg,
|
|
2540
|
+
metafieldIdentifiers,
|
|
2541
|
+
cookieAdapter: cartCookieAdapter
|
|
2542
|
+
});
|
|
2543
|
+
console.log("useUpdateCartDeliveryOptions updatedCart", updatedCart);
|
|
2544
|
+
if (updatedCart) {
|
|
2545
|
+
mutate(updatedCart);
|
|
2546
|
+
}
|
|
2547
|
+
return updatedCart;
|
|
2548
|
+
},
|
|
2549
|
+
[client, locale, cartCookieAdapter, mutate]
|
|
2550
|
+
);
|
|
2551
|
+
return useSWRMutation("update-cart-delivery-options", updateDeliveryOptions, options);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
// src/hooks/member/plus/use-update-plus-member-delivery-options.ts
|
|
2555
|
+
var useUpdatePlusMemberDeliveryOptions = ({
|
|
2556
|
+
options
|
|
2557
|
+
}) => {
|
|
2558
|
+
const { cart, mutateCart: mutate, metafieldIdentifiers } = useCartContext();
|
|
2559
|
+
const { trigger: updateCartDeliveryOptions2, isMutating } = useUpdateCartDeliveryOptions(
|
|
2560
|
+
mutate,
|
|
2561
|
+
metafieldIdentifiers
|
|
2562
|
+
);
|
|
2563
|
+
const handler = useCallback(
|
|
2564
|
+
async (_, { arg }) => {
|
|
2565
|
+
const { deliveryData } = arg;
|
|
2566
|
+
const firstDeliveryGroup = cart?.deliveryGroups?.[0];
|
|
2567
|
+
const deliveryGroupId = firstDeliveryGroup?.id;
|
|
2568
|
+
const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
|
|
2569
|
+
if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
|
|
2570
|
+
return null;
|
|
2571
|
+
}
|
|
2572
|
+
const deliveryGroup = cart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
|
|
2573
|
+
const matchedOption = deliveryGroup?.deliveryOptions?.find(
|
|
2574
|
+
(option) => option?.code === selectedOptionCode
|
|
2575
|
+
);
|
|
2576
|
+
if (!matchedOption?.handle) {
|
|
2577
|
+
return null;
|
|
2578
|
+
}
|
|
2579
|
+
const deliveryOptions = [
|
|
2580
|
+
{
|
|
2581
|
+
deliveryGroupId,
|
|
2582
|
+
deliveryOptionHandle: matchedOption.handle
|
|
2583
|
+
}
|
|
2584
|
+
];
|
|
2585
|
+
const updatedCart = await updateCartDeliveryOptions2({
|
|
2586
|
+
selectedDeliveryOptions: deliveryOptions
|
|
2587
|
+
});
|
|
2588
|
+
if (updatedCart && mutate) {
|
|
2589
|
+
mutate(updatedCart);
|
|
2590
|
+
}
|
|
2591
|
+
return updatedCart;
|
|
2592
|
+
},
|
|
2593
|
+
[cart, updateCartDeliveryOptions2, mutate]
|
|
2594
|
+
);
|
|
2595
|
+
return useSWRMutation("update-cart-delivery-options", handler, options);
|
|
2596
|
+
};
|
|
2415
2597
|
var usePlusMemberItemCustomAttributes = ({
|
|
2416
2598
|
deliveryData
|
|
2417
2599
|
}) => {
|
|
@@ -2498,15 +2680,14 @@ var usePlusMemberCheckoutCustomAttributes = ({
|
|
|
2498
2680
|
}, [deliveryCustomData, product, profile, userType, variant, isShowShippingBenefits]);
|
|
2499
2681
|
};
|
|
2500
2682
|
function useAutoRemovePlusMemberInCart({
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2683
|
+
cart,
|
|
2684
|
+
profile,
|
|
2685
|
+
memberSetting
|
|
2504
2686
|
}) {
|
|
2505
|
-
const { plus_monthly_product, plus_annual_product } =
|
|
2506
|
-
const { cart } = useCartContext();
|
|
2687
|
+
const { plus_monthly_product, plus_annual_product } = memberSetting || {};
|
|
2507
2688
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
2508
2689
|
useEffect(() => {
|
|
2509
|
-
if (!cart) return;
|
|
2690
|
+
if (!cart || !plus_monthly_product || !plus_annual_product) return;
|
|
2510
2691
|
const removePlusProduct = async (productType) => {
|
|
2511
2692
|
if (!productType) return;
|
|
2512
2693
|
const product = cart.lineItems?.find(
|
|
@@ -2518,26 +2699,53 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2518
2699
|
});
|
|
2519
2700
|
}
|
|
2520
2701
|
};
|
|
2521
|
-
if (isMonthlyPlus) {
|
|
2702
|
+
if (profile?.isMonthlyPlus) {
|
|
2522
2703
|
removePlusProduct(plus_monthly_product);
|
|
2523
2704
|
}
|
|
2524
|
-
if (isAnnualPlus) {
|
|
2705
|
+
if (profile?.isAnnualPlus) {
|
|
2525
2706
|
removePlusProduct(plus_annual_product);
|
|
2526
2707
|
}
|
|
2708
|
+
}, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
|
|
2709
|
+
}
|
|
2710
|
+
function useAddPlusMemberProductsToCart({
|
|
2711
|
+
cart,
|
|
2712
|
+
profile
|
|
2713
|
+
}) {
|
|
2714
|
+
const { selectedPlusMemberMode, selectedPlusMemberProduct, plusMemberMetafields } = usePlusMemberContext();
|
|
2715
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2716
|
+
memberSetting: plusMemberMetafields,
|
|
2717
|
+
cart
|
|
2718
|
+
});
|
|
2719
|
+
const plusMemberProduct = useMemo(() => {
|
|
2720
|
+
if (!selectedPlusMemberProduct || selectedPlusMemberMode === "free" /* FREE */) {
|
|
2721
|
+
return void 0;
|
|
2722
|
+
}
|
|
2723
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2724
|
+
return void 0;
|
|
2725
|
+
}
|
|
2726
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2727
|
+
return void 0;
|
|
2728
|
+
}
|
|
2729
|
+
if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
|
|
2730
|
+
return void 0;
|
|
2731
|
+
}
|
|
2732
|
+
if (!profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
|
|
2733
|
+
return void 0;
|
|
2734
|
+
}
|
|
2735
|
+
return selectedPlusMemberProduct;
|
|
2527
2736
|
}, [
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
removeCartLines2
|
|
2737
|
+
selectedPlusMemberMode,
|
|
2738
|
+
selectedPlusMemberProduct?.variant,
|
|
2739
|
+
selectedPlusMemberProduct?.product,
|
|
2740
|
+
hasMonthlyPlus,
|
|
2741
|
+
hasAnnualPlus
|
|
2534
2742
|
]);
|
|
2743
|
+
return plusMemberProduct;
|
|
2535
2744
|
}
|
|
2536
2745
|
var PlusMemberProvider = ({
|
|
2537
2746
|
variant,
|
|
2538
2747
|
product,
|
|
2539
|
-
|
|
2540
|
-
metafields,
|
|
2748
|
+
memberSetting,
|
|
2541
2749
|
initialSelectedPlusMemberMode = "free",
|
|
2542
2750
|
profile,
|
|
2543
2751
|
locale,
|
|
@@ -2557,14 +2765,14 @@ var PlusMemberProvider = ({
|
|
|
2557
2765
|
const [deleteMarginBottom, setDeleteMarginBottom] = useState(false);
|
|
2558
2766
|
const shippingMethodsContext = useShippingMethods({
|
|
2559
2767
|
variant,
|
|
2560
|
-
plusMemberMetafields:
|
|
2768
|
+
plusMemberMetafields: memberSetting,
|
|
2561
2769
|
selectedPlusMemberMode});
|
|
2562
2770
|
const plusMemberHandles = useMemo(() => {
|
|
2563
2771
|
return [
|
|
2564
|
-
|
|
2565
|
-
|
|
2772
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2773
|
+
memberSetting?.plus_annual_product?.handle
|
|
2566
2774
|
].filter(Boolean);
|
|
2567
|
-
}, [
|
|
2775
|
+
}, [memberSetting]);
|
|
2568
2776
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2569
2777
|
handles: plusMemberHandles
|
|
2570
2778
|
});
|
|
@@ -2572,25 +2780,24 @@ var PlusMemberProvider = ({
|
|
|
2572
2780
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2573
2781
|
return null;
|
|
2574
2782
|
}
|
|
2575
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2576
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2783
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2784
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2577
2785
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2578
2786
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2579
2787
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2580
|
-
}, [plusMemberProducts,
|
|
2788
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2581
2789
|
return /* @__PURE__ */ jsx(
|
|
2582
2790
|
PlusMemberContext.Provider,
|
|
2583
2791
|
{
|
|
2584
2792
|
value: {
|
|
2585
2793
|
variant,
|
|
2586
|
-
shopCommon,
|
|
2587
2794
|
zipCode,
|
|
2588
2795
|
setZipCode,
|
|
2589
2796
|
allowNextDayDelivery,
|
|
2590
2797
|
setAllowNextDayDelivery,
|
|
2591
2798
|
allowThirdDayDelivery,
|
|
2592
2799
|
setAllowThirdDayDelivery,
|
|
2593
|
-
plusMemberMetafields:
|
|
2800
|
+
plusMemberMetafields: memberSetting,
|
|
2594
2801
|
selectedPlusMemberMode,
|
|
2595
2802
|
setSelectedPlusMemberMode,
|
|
2596
2803
|
showAreaCheckModal,
|
|
@@ -2796,6 +3003,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
2796
3003
|
}
|
|
2797
3004
|
}
|
|
2798
3005
|
|
|
2799
|
-
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, atobID, btoaID, clearGeoLocationCache, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes,
|
|
3006
|
+
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, atobID, btoaID, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddPlusMemberProductsToCart, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
2800
3007
|
//# sourceMappingURL=index.mjs.map
|
|
2801
3008
|
//# sourceMappingURL=index.mjs.map
|