@anker-in/shopify-react 0.1.1-beta.1 → 0.1.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +242 -47
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +237 -46
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-RevQokdZ.d.mts → index-Utuz9i5x.d.mts} +165 -49
- package/dist/{index-CCMIeIUh.d.ts → index-aSsTcW2O.d.ts} +165 -49
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +265 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -56
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +138 -34
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +138 -34
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/hooks/index.mjs
CHANGED
|
@@ -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,7 +394,7 @@ 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 };
|
|
@@ -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
|
);
|
|
@@ -621,8 +718,12 @@ var trackAddToCartGA = ({
|
|
|
621
718
|
}
|
|
622
719
|
const { variant } = lineItems[0];
|
|
623
720
|
const currencyCode = variant.product?.price?.currencyCode;
|
|
624
|
-
const
|
|
625
|
-
|
|
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();
|
|
626
727
|
gaTrack({
|
|
627
728
|
event: "ga4Event",
|
|
628
729
|
event_name: "add_to_cart",
|
|
@@ -637,7 +738,7 @@ var trackAddToCartGA = ({
|
|
|
637
738
|
item_brand: gtmParams?.brand || "",
|
|
638
739
|
item_category: variant2?.product?.productType || "",
|
|
639
740
|
item_variant: variant2?.title || variant2?.title,
|
|
640
|
-
price,
|
|
741
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
641
742
|
quantity: quantity || 1
|
|
642
743
|
})),
|
|
643
744
|
...gtmParams?.ga4Params
|
|
@@ -653,8 +754,12 @@ var trackBuyNowGA = ({
|
|
|
653
754
|
}
|
|
654
755
|
const { variant } = lineItems[0];
|
|
655
756
|
const currencyCode = variant.price?.currencyCode;
|
|
656
|
-
const
|
|
657
|
-
|
|
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();
|
|
658
763
|
gaTrack({
|
|
659
764
|
event: "ga4Event",
|
|
660
765
|
event_name: "begin_checkout",
|
|
@@ -669,7 +774,7 @@ var trackBuyNowGA = ({
|
|
|
669
774
|
item_brand: gtmParams?.brand || "",
|
|
670
775
|
item_category: item.variant?.product?.productType || "",
|
|
671
776
|
item_variant: item.variant?.title,
|
|
672
|
-
price,
|
|
777
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
673
778
|
quantity: item.quantity || 1
|
|
674
779
|
})),
|
|
675
780
|
...gtmParams?.ga4Params
|
|
@@ -812,6 +917,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
812
917
|
if (!resultCart) {
|
|
813
918
|
return void 0;
|
|
814
919
|
}
|
|
920
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
815
921
|
if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
816
922
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
817
923
|
if (unapplicableCodes.length > 0) {
|
|
@@ -985,6 +1091,60 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
|
985
1091
|
);
|
|
986
1092
|
return useSWRMutation("buy-now", buyNow, swrOptions);
|
|
987
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
|
+
}
|
|
988
1148
|
|
|
989
1149
|
// src/hooks/cart/types/order-discount.ts
|
|
990
1150
|
var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
|
|
@@ -2490,11 +2650,43 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2490
2650
|
removeCartLines2
|
|
2491
2651
|
]);
|
|
2492
2652
|
}
|
|
2653
|
+
function useAddPlusMemberProductsToCart({
|
|
2654
|
+
cart,
|
|
2655
|
+
memberSetting,
|
|
2656
|
+
selectedPlusMemberMode,
|
|
2657
|
+
selectedPlusMemberProduct
|
|
2658
|
+
}) {
|
|
2659
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2660
|
+
cart,
|
|
2661
|
+
memberSetting
|
|
2662
|
+
});
|
|
2663
|
+
const plusMemberProduct = useMemo(() => {
|
|
2664
|
+
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2665
|
+
return void 0;
|
|
2666
|
+
}
|
|
2667
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2668
|
+
return void 0;
|
|
2669
|
+
}
|
|
2670
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2671
|
+
return void 0;
|
|
2672
|
+
}
|
|
2673
|
+
if (!selectedPlusMemberProduct) {
|
|
2674
|
+
return void 0;
|
|
2675
|
+
}
|
|
2676
|
+
return selectedPlusMemberProduct;
|
|
2677
|
+
}, [
|
|
2678
|
+
selectedPlusMemberMode,
|
|
2679
|
+
selectedPlusMemberProduct?.variant,
|
|
2680
|
+
selectedPlusMemberProduct?.product,
|
|
2681
|
+
hasMonthlyPlus,
|
|
2682
|
+
hasAnnualPlus
|
|
2683
|
+
]);
|
|
2684
|
+
return plusMemberProduct;
|
|
2685
|
+
}
|
|
2493
2686
|
var PlusMemberProvider = ({
|
|
2494
2687
|
variant,
|
|
2495
2688
|
product,
|
|
2496
|
-
|
|
2497
|
-
metafields,
|
|
2689
|
+
memberSetting,
|
|
2498
2690
|
initialSelectedPlusMemberMode = "free",
|
|
2499
2691
|
profile,
|
|
2500
2692
|
locale,
|
|
@@ -2514,14 +2706,14 @@ var PlusMemberProvider = ({
|
|
|
2514
2706
|
const [deleteMarginBottom, setDeleteMarginBottom] = useState(false);
|
|
2515
2707
|
const shippingMethodsContext = useShippingMethods({
|
|
2516
2708
|
variant,
|
|
2517
|
-
plusMemberMetafields:
|
|
2709
|
+
plusMemberMetafields: memberSetting,
|
|
2518
2710
|
selectedPlusMemberMode});
|
|
2519
2711
|
const plusMemberHandles = useMemo(() => {
|
|
2520
2712
|
return [
|
|
2521
|
-
|
|
2522
|
-
|
|
2713
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2714
|
+
memberSetting?.plus_annual_product?.handle
|
|
2523
2715
|
].filter(Boolean);
|
|
2524
|
-
}, [
|
|
2716
|
+
}, [memberSetting]);
|
|
2525
2717
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2526
2718
|
handles: plusMemberHandles
|
|
2527
2719
|
});
|
|
@@ -2529,25 +2721,24 @@ var PlusMemberProvider = ({
|
|
|
2529
2721
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2530
2722
|
return null;
|
|
2531
2723
|
}
|
|
2532
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2533
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2724
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2725
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2534
2726
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2535
2727
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2536
2728
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2537
|
-
}, [plusMemberProducts,
|
|
2729
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2538
2730
|
return /* @__PURE__ */ jsx(
|
|
2539
2731
|
PlusMemberContext.Provider,
|
|
2540
2732
|
{
|
|
2541
2733
|
value: {
|
|
2542
2734
|
variant,
|
|
2543
|
-
shopCommon,
|
|
2544
2735
|
zipCode,
|
|
2545
2736
|
setZipCode,
|
|
2546
2737
|
allowNextDayDelivery,
|
|
2547
2738
|
setAllowNextDayDelivery,
|
|
2548
2739
|
allowThirdDayDelivery,
|
|
2549
2740
|
setAllowThirdDayDelivery,
|
|
2550
|
-
plusMemberMetafields:
|
|
2741
|
+
plusMemberMetafields: memberSetting,
|
|
2551
2742
|
selectedPlusMemberMode,
|
|
2552
2743
|
setSelectedPlusMemberMode,
|
|
2553
2744
|
showAreaCheckModal,
|
|
@@ -2753,6 +2944,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
2753
2944
|
}
|
|
2754
2945
|
}
|
|
2755
2946
|
|
|
2756
|
-
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,
|
|
2947
|
+
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, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
2757
2948
|
//# sourceMappingURL=index.mjs.map
|
|
2758
2949
|
//# sourceMappingURL=index.mjs.map
|