@anker-in/shopify-react 0.1.1-beta.1 → 0.1.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +242 -47
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +237 -46
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-RevQokdZ.d.mts → index-Utuz9i5x.d.mts} +165 -49
- package/dist/{index-CCMIeIUh.d.ts → index-aSsTcW2O.d.ts} +165 -49
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +265 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -56
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +138 -34
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +138 -34
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,81 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
134
134
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
135
135
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
136
136
|
|
|
137
|
+
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
138
|
+
function normalizeAddToCartLines(lines) {
|
|
139
|
+
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
140
|
+
const variant = line.variant;
|
|
141
|
+
const product = variant.product;
|
|
142
|
+
const quantity = line.quantity || 1;
|
|
143
|
+
const price = variant.finalPrice?.amount ? Number(variant.finalPrice.amount) : variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
144
|
+
const subtotalAmount = price * quantity;
|
|
145
|
+
const totalAmount = subtotalAmount;
|
|
146
|
+
return {
|
|
147
|
+
id: `temp-line-${index}-${variant.id}`,
|
|
148
|
+
// Temporary ID for pre-cart lines
|
|
149
|
+
name: product?.title || variant.title || "",
|
|
150
|
+
quantity,
|
|
151
|
+
variantId: variant.id,
|
|
152
|
+
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
153
|
+
totalAmount,
|
|
154
|
+
subtotalAmount,
|
|
155
|
+
discountAllocations: [],
|
|
156
|
+
customAttributes: line.attributes || [],
|
|
157
|
+
variant: {
|
|
158
|
+
id: variant.id,
|
|
159
|
+
price,
|
|
160
|
+
listPrice: variant.compareAtPrice?.amount ? Number(variant.compareAtPrice.amount) : 0,
|
|
161
|
+
sku: variant.sku || "",
|
|
162
|
+
name: variant.title || "",
|
|
163
|
+
image: variant.image ? {
|
|
164
|
+
url: variant.image.url,
|
|
165
|
+
altText: variant.image.altText || void 0
|
|
166
|
+
} : void 0,
|
|
167
|
+
requiresShipping: false,
|
|
168
|
+
// Default value, not available in NormalizedProductVariant
|
|
169
|
+
availableForSale: variant.availableForSale ?? true,
|
|
170
|
+
quantityAvailable: variant.quantityAvailable ?? 0,
|
|
171
|
+
currentlyNotInStock: false,
|
|
172
|
+
// Default value, will be updated when added to cart
|
|
173
|
+
weight: variant.weight,
|
|
174
|
+
metafields: variant.metafields
|
|
175
|
+
},
|
|
176
|
+
product,
|
|
177
|
+
path: product?.handle ? `/products/${product.handle}` : "",
|
|
178
|
+
discounts: [],
|
|
179
|
+
options: variant.selectedOptions?.map((opt) => ({
|
|
180
|
+
name: opt.name,
|
|
181
|
+
value: opt.value
|
|
182
|
+
}))
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function createMockCartFromLines(lines, existingCart) {
|
|
187
|
+
const normalizedLines = normalizeAddToCartLines(lines);
|
|
188
|
+
const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
|
|
189
|
+
const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
|
|
190
|
+
return {
|
|
191
|
+
id: existingCart?.id || "temp-cart-id",
|
|
192
|
+
customerId: existingCart?.customerId,
|
|
193
|
+
email: existingCart?.email,
|
|
194
|
+
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
195
|
+
currency: existingCart?.currency || { code: "USD" },
|
|
196
|
+
taxesIncluded: existingCart?.taxesIncluded,
|
|
197
|
+
lineItems: normalizedLines,
|
|
198
|
+
totallineItemsDiscount: 0,
|
|
199
|
+
orderDiscounts: 0,
|
|
200
|
+
lineItemsSubtotalPrice: subtotalPrice,
|
|
201
|
+
subtotalPrice,
|
|
202
|
+
totalPrice,
|
|
203
|
+
totalTaxAmount: 0,
|
|
204
|
+
discountCodes: existingCart?.discountCodes || [],
|
|
205
|
+
discountAllocations: [],
|
|
206
|
+
url: existingCart?.url || "",
|
|
207
|
+
ready: true,
|
|
208
|
+
customAttributes: existingCart?.customAttributes
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
137
212
|
// src/hooks/cart/utils/index.ts
|
|
138
213
|
var getQuery = () => {
|
|
139
214
|
const url = typeof window !== "undefined" ? window.location.search : "";
|
|
@@ -173,25 +248,25 @@ var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
|
|
|
173
248
|
return acc + (main_product?.spend_money_type === 1 /* ORIGIN_PRICE */ ? Number(line.subtotalAmount) || 0 : Number(line.totalAmount) || 0);
|
|
174
249
|
}, 0) || 0;
|
|
175
250
|
};
|
|
176
|
-
var
|
|
177
|
-
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
178
|
-
return safeParseJson(attr?.value ?? "") ?? {};
|
|
179
|
-
};
|
|
180
|
-
var isAttributesEqual = (attrs1 = [], attrs2 = []) => {
|
|
181
|
-
if (attrs1.length !== attrs2.length) return false;
|
|
182
|
-
const sorted1 = [...attrs1].sort((a, b) => a.key.localeCompare(b.key));
|
|
183
|
-
const sorted2 = [...attrs2].sort((a, b) => a.key.localeCompare(b.key));
|
|
184
|
-
return sorted1.every(
|
|
185
|
-
(attr, i) => attr.key === sorted2[i]?.key && attr.value === sorted2[i]?.value
|
|
186
|
-
);
|
|
187
|
-
};
|
|
188
|
-
var safeParseJson = (str) => {
|
|
251
|
+
var safeParse = (str) => {
|
|
189
252
|
try {
|
|
190
253
|
return JSON.parse(str);
|
|
191
254
|
} catch (err) {
|
|
192
255
|
return {};
|
|
193
256
|
}
|
|
194
257
|
};
|
|
258
|
+
var getDiscountEnvAttributeValue = (attributes = []) => {
|
|
259
|
+
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
260
|
+
return safeParse(attr?.value ?? "") ?? {};
|
|
261
|
+
};
|
|
262
|
+
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
263
|
+
return oldAttributes.some((attr) => {
|
|
264
|
+
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
265
|
+
return newAttr ? newAttr.value !== attr.value : true;
|
|
266
|
+
}) || newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || customAttributesNeedRemove.some(
|
|
267
|
+
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
268
|
+
);
|
|
269
|
+
};
|
|
195
270
|
var containsAll = (source, requiredItems = []) => {
|
|
196
271
|
if (!requiredItems?.length) return true;
|
|
197
272
|
const sourceSet = new Set(source);
|
|
@@ -358,12 +433,18 @@ var formatFunctionAutoFreeGift = ({
|
|
|
358
433
|
};
|
|
359
434
|
return result;
|
|
360
435
|
};
|
|
361
|
-
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
436
|
+
var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
362
437
|
const tags = useMemo(() => customer?.tags || [], [customer?.tags]);
|
|
363
438
|
const isCustomerLoading = useMemo(() => !customer ? true : false, [customer]);
|
|
364
439
|
const dealsType = "";
|
|
365
440
|
const { client, locale } = useShopify();
|
|
366
441
|
const giftProductsCache = useRef(null);
|
|
442
|
+
const effectiveCart = useMemo(() => {
|
|
443
|
+
if (lines && lines.length > 0) {
|
|
444
|
+
return createMockCartFromLines(lines, cart);
|
|
445
|
+
}
|
|
446
|
+
return cart;
|
|
447
|
+
}, [lines, cart]);
|
|
367
448
|
const { activeCampaign, subtotal } = useMemo(() => {
|
|
368
449
|
for (const campaign of autoFreeGiftConfig) {
|
|
369
450
|
const { rule_conditions = [], rule_result } = campaign;
|
|
@@ -371,7 +452,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
371
452
|
const isPreCheckPassed = preCheck(rule_conditions, tags, []);
|
|
372
453
|
if (isPreCheckPassed && spend_get_reward) {
|
|
373
454
|
const matchedSubtotal = getMatchedMainProductSubTotal(
|
|
374
|
-
|
|
455
|
+
effectiveCart,
|
|
375
456
|
spend_get_reward.main_product?.variant_list?.map((v) => v.variant_id) || [],
|
|
376
457
|
{
|
|
377
458
|
spend_money_type: spend_get_reward.main_product?.spend_money_type || 1,
|
|
@@ -385,7 +466,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer) => {
|
|
|
385
466
|
}
|
|
386
467
|
}
|
|
387
468
|
return { activeCampaign: null, subtotal: 0 };
|
|
388
|
-
}, [autoFreeGiftConfig,
|
|
469
|
+
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
389
470
|
const { qualifyingGift, nextTierGoal } = useMemo(() => {
|
|
390
471
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
391
472
|
return { qualifyingGift: null, nextTierGoal: null };
|
|
@@ -468,18 +549,33 @@ var useScriptAutoFreeGift = ({
|
|
|
468
549
|
campaign,
|
|
469
550
|
_giveaway,
|
|
470
551
|
cart,
|
|
471
|
-
locale: providedLocale
|
|
552
|
+
locale: providedLocale,
|
|
553
|
+
lines
|
|
472
554
|
}) => {
|
|
473
555
|
const { client, locale: contextLocale } = useShopify();
|
|
474
556
|
const locale = providedLocale || contextLocale;
|
|
475
557
|
const [points_subscribe, set_points_subscribe] = useState(false);
|
|
476
558
|
const giftProductsCache = useRef(null);
|
|
559
|
+
const effectiveCart = useMemo(() => {
|
|
560
|
+
if (lines && lines.length > 0) {
|
|
561
|
+
return createMockCartFromLines(lines, cart);
|
|
562
|
+
}
|
|
563
|
+
return cart;
|
|
564
|
+
}, [lines, cart]);
|
|
477
565
|
useEffect(() => {
|
|
478
566
|
if (locale === "au") {
|
|
479
567
|
const isPointsSubscribe = Cookies5.get("points_subscribe");
|
|
480
568
|
set_points_subscribe(!!isPointsSubscribe);
|
|
481
569
|
}
|
|
482
570
|
}, [locale]);
|
|
571
|
+
const isActivityAvailable = useMemo(() => {
|
|
572
|
+
if (!campaign) return false;
|
|
573
|
+
const query = getQuery();
|
|
574
|
+
const utmCampaign = Cookies5.get("utm_campaign") || query?.utm_campaign;
|
|
575
|
+
if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
|
|
576
|
+
return false;
|
|
577
|
+
return true;
|
|
578
|
+
}, [campaign]);
|
|
483
579
|
const [upgrade_multiple, upgrade_value] = useMemo(() => {
|
|
484
580
|
let upgrade_multiple2 = 1;
|
|
485
581
|
let upgrade_value2 = 0;
|
|
@@ -487,17 +583,17 @@ var useScriptAutoFreeGift = ({
|
|
|
487
583
|
upgrade_multiple2 = 1.2;
|
|
488
584
|
upgrade_value2 = 40;
|
|
489
585
|
}
|
|
490
|
-
|
|
586
|
+
effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
|
|
491
587
|
customAttributes?.forEach(({ key, value }) => {
|
|
492
588
|
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
493
589
|
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
494
590
|
});
|
|
495
591
|
});
|
|
496
592
|
return [upgrade_multiple2, upgrade_value2];
|
|
497
|
-
}, [
|
|
593
|
+
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
498
594
|
const breakpoints = useMemo(() => {
|
|
499
|
-
if (!
|
|
500
|
-
return (campaign
|
|
595
|
+
if (!isActivityAvailable) return [];
|
|
596
|
+
return (campaign?.breakpoints || []).map((item) => ({
|
|
501
597
|
breakpoint: new Decimal2(item.breakpoint).minus(new Decimal2(upgrade_value)).dividedBy(new Decimal2(upgrade_multiple)).toFixed(2, Decimal2.ROUND_DOWN),
|
|
502
598
|
giveawayProducts: item.giveawayProducts || []
|
|
503
599
|
}));
|
|
@@ -521,25 +617,26 @@ var useScriptAutoFreeGift = ({
|
|
|
521
617
|
return true;
|
|
522
618
|
}, [giftHandles]);
|
|
523
619
|
const involvedLines = useMemo(() => {
|
|
524
|
-
if (!
|
|
525
|
-
return (
|
|
620
|
+
if (!isActivityAvailable) return [];
|
|
621
|
+
return (effectiveCart?.lineItems || []).filter((line) => {
|
|
526
622
|
const isNotGift = line?.totalAmount && Number(line.totalAmount) > 0 && line.customAttributes?.every(
|
|
527
623
|
(item) => item.key !== _giveaway
|
|
528
624
|
);
|
|
529
625
|
const hasCampaignTag = line.product?.tags?.some(
|
|
530
|
-
(tag) => campaign
|
|
626
|
+
(tag) => campaign?.includeTags?.includes(tag.trim()) && line.variant?.availableForSale
|
|
531
627
|
);
|
|
532
628
|
return isNotGift && hasCampaignTag;
|
|
533
629
|
});
|
|
534
|
-
}, [
|
|
630
|
+
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
535
631
|
const involvedSubTotal = useMemo(() => {
|
|
536
|
-
if (!
|
|
632
|
+
if (!isActivityAvailable) return new Decimal2(0);
|
|
537
633
|
return involvedLines.reduce((prev, item) => {
|
|
538
|
-
const amount = campaign
|
|
634
|
+
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
539
635
|
return new Decimal2(prev).plus(new Decimal2(amount || 0));
|
|
540
636
|
}, new Decimal2(0));
|
|
541
|
-
}, [involvedLines,
|
|
637
|
+
}, [involvedLines, isActivityAvailable]);
|
|
542
638
|
const [freeGiftLevel, nextFreeGiftLevel] = useMemo(() => {
|
|
639
|
+
if (!isActivityAvailable) return [null, null];
|
|
543
640
|
const sortedLevels = [...breakpoints].sort(
|
|
544
641
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
545
642
|
);
|
|
@@ -683,8 +780,12 @@ var trackAddToCartGA = ({
|
|
|
683
780
|
}
|
|
684
781
|
const { variant } = lineItems[0];
|
|
685
782
|
const currencyCode = variant.product?.price?.currencyCode;
|
|
686
|
-
const
|
|
687
|
-
|
|
783
|
+
const totalPrice = lineItems?.reduce(
|
|
784
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
785
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? variant2?.price?.amount ?? 0
|
|
786
|
+
),
|
|
787
|
+
new Decimal2(0)
|
|
788
|
+
).toNumber();
|
|
688
789
|
gaTrack({
|
|
689
790
|
event: "ga4Event",
|
|
690
791
|
event_name: "add_to_cart",
|
|
@@ -699,7 +800,7 @@ var trackAddToCartGA = ({
|
|
|
699
800
|
item_brand: gtmParams?.brand || "",
|
|
700
801
|
item_category: variant2?.product?.productType || "",
|
|
701
802
|
item_variant: variant2?.title || variant2?.title,
|
|
702
|
-
price,
|
|
803
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
703
804
|
quantity: quantity || 1
|
|
704
805
|
})),
|
|
705
806
|
...gtmParams?.ga4Params
|
|
@@ -714,9 +815,12 @@ var trackBeginCheckoutGA = ({
|
|
|
714
815
|
if (!lineItems.length) {
|
|
715
816
|
return;
|
|
716
817
|
}
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
818
|
+
const totalPrice = lineItems?.reduce(
|
|
819
|
+
(prev, { variant }) => prev.plus(
|
|
820
|
+
variant?.finalPrice?.amount ?? variant?.compareAtPrice?.amount ?? variant?.price?.amount ?? 0
|
|
821
|
+
),
|
|
822
|
+
new Decimal2(0)
|
|
823
|
+
).toNumber();
|
|
720
824
|
gaTrack({
|
|
721
825
|
event: "ga4Event",
|
|
722
826
|
event_name: "begin_checkout",
|
|
@@ -731,7 +835,7 @@ var trackBeginCheckoutGA = ({
|
|
|
731
835
|
item_brand: gtmParams?.brand || "",
|
|
732
836
|
item_category: item.variant?.product?.productType,
|
|
733
837
|
item_variant: item.variant?.title,
|
|
734
|
-
price,
|
|
838
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
735
839
|
quantity: item.quantity || 1
|
|
736
840
|
})),
|
|
737
841
|
...gtmParams?.ga4Params
|
|
@@ -747,8 +851,12 @@ var trackBuyNowGA = ({
|
|
|
747
851
|
}
|
|
748
852
|
const { variant } = lineItems[0];
|
|
749
853
|
const currencyCode = variant.price?.currencyCode;
|
|
750
|
-
const
|
|
751
|
-
|
|
854
|
+
const totalPrice = lineItems?.reduce(
|
|
855
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
856
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? (variant2?.price?.amount || 0)
|
|
857
|
+
),
|
|
858
|
+
new Decimal2(0)
|
|
859
|
+
).toNumber();
|
|
752
860
|
gaTrack({
|
|
753
861
|
event: "ga4Event",
|
|
754
862
|
event_name: "begin_checkout",
|
|
@@ -763,7 +871,7 @@ var trackBuyNowGA = ({
|
|
|
763
871
|
item_brand: gtmParams?.brand || "",
|
|
764
872
|
item_category: item.variant?.product?.productType || "",
|
|
765
873
|
item_variant: item.variant?.title,
|
|
766
|
-
price,
|
|
874
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
767
875
|
quantity: item.quantity || 1
|
|
768
876
|
})),
|
|
769
877
|
...gtmParams?.ga4Params
|
|
@@ -906,6 +1014,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
|
906
1014
|
if (!resultCart) {
|
|
907
1015
|
return void 0;
|
|
908
1016
|
}
|
|
1017
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
909
1018
|
if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
910
1019
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
911
1020
|
if (unapplicableCodes.length > 0) {
|
|
@@ -1079,6 +1188,60 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
|
1079
1188
|
);
|
|
1080
1189
|
return useSWRMutation("buy-now", buyNow, swrOptions);
|
|
1081
1190
|
}
|
|
1191
|
+
function useCalcGiftsFromLines({
|
|
1192
|
+
lines,
|
|
1193
|
+
customer,
|
|
1194
|
+
scriptGiveawayKey = CUSTOMER_SCRIPT_GIFT_KEY
|
|
1195
|
+
}) {
|
|
1196
|
+
const { locale } = useShopify();
|
|
1197
|
+
const { cart, autoFreeGiftConfig, gradientGiftsConfig } = useCartContext();
|
|
1198
|
+
const functionGift = useCalcAutoFreeGift(cart, autoFreeGiftConfig || [], customer, lines);
|
|
1199
|
+
const scriptGift = useScriptAutoFreeGift({
|
|
1200
|
+
campaign: gradientGiftsConfig || null,
|
|
1201
|
+
_giveaway: scriptGiveawayKey,
|
|
1202
|
+
cart,
|
|
1203
|
+
locale,
|
|
1204
|
+
lines
|
|
1205
|
+
});
|
|
1206
|
+
const allGiftLines = useMemo(() => {
|
|
1207
|
+
const functionGiftLines = functionGift.qualifyingGift?.itemsToAdd || [];
|
|
1208
|
+
const scriptGiftLines = scriptGift.freeGiftLevel ? scriptGift.freeGiftLevel.giveawayProducts.map((product) => {
|
|
1209
|
+
const giftProduct = scriptGift.giftProductsResult?.find(
|
|
1210
|
+
(p) => p.handle === product.handle
|
|
1211
|
+
);
|
|
1212
|
+
const variant = giftProduct?.variants?.[0];
|
|
1213
|
+
return {
|
|
1214
|
+
variant: {
|
|
1215
|
+
id: variant?.id || "",
|
|
1216
|
+
handle: product.handle,
|
|
1217
|
+
sku: product.sku
|
|
1218
|
+
},
|
|
1219
|
+
quantity: 1,
|
|
1220
|
+
attributes: [
|
|
1221
|
+
{
|
|
1222
|
+
key: scriptGiveawayKey,
|
|
1223
|
+
value: "true"
|
|
1224
|
+
}
|
|
1225
|
+
]
|
|
1226
|
+
};
|
|
1227
|
+
}).filter((item) => item.variant.id) : [];
|
|
1228
|
+
return [...functionGiftLines, ...scriptGiftLines];
|
|
1229
|
+
}, [
|
|
1230
|
+
functionGift.qualifyingGift,
|
|
1231
|
+
scriptGift.freeGiftLevel,
|
|
1232
|
+
scriptGift.giftProductsResult,
|
|
1233
|
+
scriptGiveawayKey
|
|
1234
|
+
]);
|
|
1235
|
+
const hasGifts = useMemo(() => {
|
|
1236
|
+
return allGiftLines.length > 0;
|
|
1237
|
+
}, [allGiftLines]);
|
|
1238
|
+
return {
|
|
1239
|
+
functionGift,
|
|
1240
|
+
scriptGift,
|
|
1241
|
+
allGiftLines,
|
|
1242
|
+
hasGifts
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1082
1245
|
|
|
1083
1246
|
// src/hooks/cart/types/order-discount.ts
|
|
1084
1247
|
var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
|
|
@@ -2584,11 +2747,43 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2584
2747
|
removeCartLines2
|
|
2585
2748
|
]);
|
|
2586
2749
|
}
|
|
2750
|
+
function useAddPlusMemberProductsToCart({
|
|
2751
|
+
cart,
|
|
2752
|
+
memberSetting,
|
|
2753
|
+
selectedPlusMemberMode,
|
|
2754
|
+
selectedPlusMemberProduct
|
|
2755
|
+
}) {
|
|
2756
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2757
|
+
cart,
|
|
2758
|
+
memberSetting
|
|
2759
|
+
});
|
|
2760
|
+
const plusMemberProduct = useMemo(() => {
|
|
2761
|
+
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2762
|
+
return void 0;
|
|
2763
|
+
}
|
|
2764
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2765
|
+
return void 0;
|
|
2766
|
+
}
|
|
2767
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2768
|
+
return void 0;
|
|
2769
|
+
}
|
|
2770
|
+
if (!selectedPlusMemberProduct) {
|
|
2771
|
+
return void 0;
|
|
2772
|
+
}
|
|
2773
|
+
return selectedPlusMemberProduct;
|
|
2774
|
+
}, [
|
|
2775
|
+
selectedPlusMemberMode,
|
|
2776
|
+
selectedPlusMemberProduct?.variant,
|
|
2777
|
+
selectedPlusMemberProduct?.product,
|
|
2778
|
+
hasMonthlyPlus,
|
|
2779
|
+
hasAnnualPlus
|
|
2780
|
+
]);
|
|
2781
|
+
return plusMemberProduct;
|
|
2782
|
+
}
|
|
2587
2783
|
var PlusMemberProvider = ({
|
|
2588
2784
|
variant,
|
|
2589
2785
|
product,
|
|
2590
|
-
|
|
2591
|
-
metafields,
|
|
2786
|
+
memberSetting,
|
|
2592
2787
|
initialSelectedPlusMemberMode = "free",
|
|
2593
2788
|
profile,
|
|
2594
2789
|
locale,
|
|
@@ -2608,14 +2803,14 @@ var PlusMemberProvider = ({
|
|
|
2608
2803
|
const [deleteMarginBottom, setDeleteMarginBottom] = useState(false);
|
|
2609
2804
|
const shippingMethodsContext = useShippingMethods({
|
|
2610
2805
|
variant,
|
|
2611
|
-
plusMemberMetafields:
|
|
2806
|
+
plusMemberMetafields: memberSetting,
|
|
2612
2807
|
selectedPlusMemberMode});
|
|
2613
2808
|
const plusMemberHandles = useMemo(() => {
|
|
2614
2809
|
return [
|
|
2615
|
-
|
|
2616
|
-
|
|
2810
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2811
|
+
memberSetting?.plus_annual_product?.handle
|
|
2617
2812
|
].filter(Boolean);
|
|
2618
|
-
}, [
|
|
2813
|
+
}, [memberSetting]);
|
|
2619
2814
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2620
2815
|
handles: plusMemberHandles
|
|
2621
2816
|
});
|
|
@@ -2623,25 +2818,24 @@ var PlusMemberProvider = ({
|
|
|
2623
2818
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2624
2819
|
return null;
|
|
2625
2820
|
}
|
|
2626
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2627
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2821
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2822
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2628
2823
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2629
2824
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2630
2825
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2631
|
-
}, [plusMemberProducts,
|
|
2826
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2632
2827
|
return /* @__PURE__ */ jsx(
|
|
2633
2828
|
PlusMemberContext.Provider,
|
|
2634
2829
|
{
|
|
2635
2830
|
value: {
|
|
2636
2831
|
variant,
|
|
2637
|
-
shopCommon,
|
|
2638
2832
|
zipCode,
|
|
2639
2833
|
setZipCode,
|
|
2640
2834
|
allowNextDayDelivery,
|
|
2641
2835
|
setAllowNextDayDelivery,
|
|
2642
2836
|
allowThirdDayDelivery,
|
|
2643
2837
|
setAllowThirdDayDelivery,
|
|
2644
|
-
plusMemberMetafields:
|
|
2838
|
+
plusMemberMetafields: memberSetting,
|
|
2645
2839
|
selectedPlusMemberMode,
|
|
2646
2840
|
setSelectedPlusMemberMode,
|
|
2647
2841
|
showAreaCheckModal,
|
|
@@ -2860,6 +3054,9 @@ function CartProvider({
|
|
|
2860
3054
|
}) {
|
|
2861
3055
|
const { client, cartCookieAdapter } = useShopify();
|
|
2862
3056
|
const [customAttributes, setCustomAttributes] = useState([]);
|
|
3057
|
+
const [customAttributesNeedDelete, setCustomAttributesNeedDelete] = useState(
|
|
3058
|
+
[]
|
|
3059
|
+
);
|
|
2863
3060
|
const [isCodeChanging, setIsCodeChanging] = useState(false);
|
|
2864
3061
|
const [loadingState, setLoadingState] = useState({
|
|
2865
3062
|
editLineQuantityLoading: false,
|
|
@@ -2890,7 +3087,11 @@ function CartProvider({
|
|
|
2890
3087
|
useRequest(
|
|
2891
3088
|
() => {
|
|
2892
3089
|
const newAttributes = [...attributes, ...customAttributes];
|
|
2893
|
-
const needUpdate = cart && !
|
|
3090
|
+
const needUpdate = cart && !checkAttributesUpdateNeeded(
|
|
3091
|
+
cart.customAttributes,
|
|
3092
|
+
newAttributes,
|
|
3093
|
+
customAttributesNeedDelete
|
|
3094
|
+
);
|
|
2894
3095
|
if (needUpdate) {
|
|
2895
3096
|
return updateAttributes({ attributes: newAttributes });
|
|
2896
3097
|
} else {
|
|
@@ -2911,11 +3112,12 @@ function CartProvider({
|
|
|
2911
3112
|
isCartLoading: isCartLoading || isCodeChanging,
|
|
2912
3113
|
setLoadingState
|
|
2913
3114
|
});
|
|
2914
|
-
const removeCustomAttributes = useCallback(
|
|
2915
|
-
|
|
2916
|
-
(
|
|
2917
|
-
|
|
2918
|
-
|
|
3115
|
+
const removeCustomAttributes = useCallback(
|
|
3116
|
+
(attributes2) => {
|
|
3117
|
+
setCustomAttributesNeedDelete(attributes2);
|
|
3118
|
+
},
|
|
3119
|
+
[setCustomAttributesNeedDelete]
|
|
3120
|
+
);
|
|
2919
3121
|
const addCustomAttributes = useCallback(
|
|
2920
3122
|
(attributes2) => {
|
|
2921
3123
|
const sameAttributes = attributes2.filter(
|
|
@@ -3002,6 +3204,7 @@ function CartProvider({
|
|
|
3002
3204
|
isCodeChanging,
|
|
3003
3205
|
setIsCodeChanging,
|
|
3004
3206
|
autoFreeGiftConfig,
|
|
3207
|
+
gradientGiftsConfig,
|
|
3005
3208
|
setLoadingState,
|
|
3006
3209
|
loadingState,
|
|
3007
3210
|
// function满赠
|
|
@@ -3025,6 +3228,7 @@ function CartProvider({
|
|
|
3025
3228
|
locale,
|
|
3026
3229
|
isCodeChanging,
|
|
3027
3230
|
autoFreeGiftConfig,
|
|
3231
|
+
gradientGiftsConfig,
|
|
3028
3232
|
loadingState,
|
|
3029
3233
|
// function满赠
|
|
3030
3234
|
functionAutoFreeGift,
|
|
@@ -3048,6 +3252,6 @@ function useCartContext() {
|
|
|
3048
3252
|
return context;
|
|
3049
3253
|
}
|
|
3050
3254
|
|
|
3051
|
-
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, atobID, browserCartCookieAdapter, browserCookieAdapter, btoaID, clearGeoLocationCache, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes,
|
|
3255
|
+
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, atobID, browserCartCookieAdapter, browserCookieAdapter, btoaID, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddPlusMemberProductsToCart, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, 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, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3052
3256
|
//# sourceMappingURL=index.mjs.map
|
|
3053
3257
|
//# sourceMappingURL=index.mjs.map
|