@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/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useMemo, useContext, useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getLocalStorage, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
2
|
+
import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getLocalStorage, getCart, setLocalStorage, updateCartDeliveryOptions } from '@anker-in/shopify-sdk';
|
|
3
3
|
export { ShopifyConfig, clearLocalStorage, createShopifyClient, getLocalStorage, removeLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
4
4
|
import Cookies5 from 'js-cookie';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -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,13 +466,13 @@ 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 };
|
|
392
473
|
}
|
|
393
474
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
394
|
-
const qualifyingTier = [...giftTiers].
|
|
475
|
+
const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
|
|
395
476
|
const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
|
|
396
477
|
if (!qualifyingTier) {
|
|
397
478
|
return { qualifyingGift: null, nextTierGoal: nextGoal || 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
|
);
|
|
@@ -659,8 +756,6 @@ function useAddCartLines(options) {
|
|
|
659
756
|
);
|
|
660
757
|
return useSWRMutation("add-cart-lines", addLines, options);
|
|
661
758
|
}
|
|
662
|
-
|
|
663
|
-
// src/tracking/ga.ts
|
|
664
759
|
var gaTrack = (data) => {
|
|
665
760
|
if (typeof window === "undefined") {
|
|
666
761
|
return;
|
|
@@ -678,18 +773,19 @@ var gaTrack = (data) => {
|
|
|
678
773
|
};
|
|
679
774
|
var trackAddToCartGA = ({
|
|
680
775
|
lineItems = [],
|
|
681
|
-
gtmParams = {}
|
|
682
|
-
brand
|
|
776
|
+
gtmParams = {}
|
|
683
777
|
}) => {
|
|
684
778
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
685
779
|
return;
|
|
686
780
|
}
|
|
687
781
|
const { variant } = lineItems[0];
|
|
688
|
-
const currencyCode = variant?.price?.currencyCode;
|
|
689
|
-
const totalPrice = lineItems
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
782
|
+
const currencyCode = variant.product?.price?.currencyCode;
|
|
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();
|
|
693
789
|
gaTrack({
|
|
694
790
|
event: "ga4Event",
|
|
695
791
|
event_name: "add_to_cart",
|
|
@@ -700,11 +796,11 @@ var trackAddToCartGA = ({
|
|
|
700
796
|
position: gtmParams?.position || "",
|
|
701
797
|
items: lineItems.map(({ variant: variant2, quantity }) => ({
|
|
702
798
|
item_id: variant2?.sku,
|
|
703
|
-
item_name: variant2?.product?.title || variant2?.product?.
|
|
704
|
-
item_brand:
|
|
799
|
+
item_name: variant2?.product?.title || variant2?.product?.title,
|
|
800
|
+
item_brand: gtmParams?.brand || "",
|
|
705
801
|
item_category: variant2?.product?.productType || "",
|
|
706
|
-
item_variant: variant2?.title || variant2?.
|
|
707
|
-
price: variant2?.
|
|
802
|
+
item_variant: variant2?.title || variant2?.title,
|
|
803
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
708
804
|
quantity: quantity || 1
|
|
709
805
|
})),
|
|
710
806
|
...gtmParams?.ga4Params
|
|
@@ -714,13 +810,17 @@ var trackAddToCartGA = ({
|
|
|
714
810
|
var trackBeginCheckoutGA = ({
|
|
715
811
|
lineItems = [],
|
|
716
812
|
currencyCode,
|
|
717
|
-
|
|
718
|
-
gtmParams = {},
|
|
719
|
-
brand
|
|
813
|
+
gtmParams = {}
|
|
720
814
|
}) => {
|
|
721
815
|
if (!lineItems.length) {
|
|
722
816
|
return;
|
|
723
817
|
}
|
|
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();
|
|
724
824
|
gaTrack({
|
|
725
825
|
event: "ga4Event",
|
|
726
826
|
event_name: "begin_checkout",
|
|
@@ -732,10 +832,10 @@ var trackBeginCheckoutGA = ({
|
|
|
732
832
|
items: lineItems.map((item) => ({
|
|
733
833
|
item_id: item.variant?.sku,
|
|
734
834
|
item_name: item.variant?.product?.title,
|
|
735
|
-
item_brand:
|
|
835
|
+
item_brand: gtmParams?.brand || "",
|
|
736
836
|
item_category: item.variant?.product?.productType,
|
|
737
837
|
item_variant: item.variant?.title,
|
|
738
|
-
price: item.
|
|
838
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
739
839
|
quantity: item.quantity || 1
|
|
740
840
|
})),
|
|
741
841
|
...gtmParams?.ga4Params
|
|
@@ -744,19 +844,19 @@ var trackBeginCheckoutGA = ({
|
|
|
744
844
|
};
|
|
745
845
|
var trackBuyNowGA = ({
|
|
746
846
|
lineItems = [],
|
|
747
|
-
gtmParams = {}
|
|
748
|
-
brand
|
|
847
|
+
gtmParams = {}
|
|
749
848
|
}) => {
|
|
750
849
|
if (!lineItems.length || !lineItems[0]?.variant) {
|
|
751
850
|
return;
|
|
752
851
|
}
|
|
753
852
|
const { variant } = lineItems[0];
|
|
754
853
|
const currencyCode = variant.price?.currencyCode;
|
|
755
|
-
const totalPrice = lineItems
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
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();
|
|
760
860
|
gaTrack({
|
|
761
861
|
event: "ga4Event",
|
|
762
862
|
event_name: "begin_checkout",
|
|
@@ -768,10 +868,10 @@ var trackBuyNowGA = ({
|
|
|
768
868
|
items: lineItems.map((item) => ({
|
|
769
869
|
item_id: item.variant?.sku,
|
|
770
870
|
item_name: item.variant?.product?.title || item.variant?.title,
|
|
771
|
-
item_brand:
|
|
871
|
+
item_brand: gtmParams?.brand || "",
|
|
772
872
|
item_category: item.variant?.product?.productType || "",
|
|
773
873
|
item_variant: item.variant?.title,
|
|
774
|
-
price: item.
|
|
874
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
775
875
|
quantity: item.quantity || 1
|
|
776
876
|
})),
|
|
777
877
|
...gtmParams?.ga4Params
|
|
@@ -785,10 +885,10 @@ var trackAddToCartFBQ = ({ lineItems = [] }) => {
|
|
|
785
885
|
return;
|
|
786
886
|
}
|
|
787
887
|
if (lineItems.length && lineItems[0]?.variant) {
|
|
788
|
-
const { variant, quantity
|
|
888
|
+
const { variant, quantity } = lineItems[0];
|
|
789
889
|
try {
|
|
790
890
|
window.fbq("track", "AddToCart", {
|
|
791
|
-
value:
|
|
891
|
+
value: variant?.compareAtPrice?.amount ?? (variant?.price?.amount || variant?.price || 0),
|
|
792
892
|
num_items: quantity,
|
|
793
893
|
currency: variant?.price?.currencyCode,
|
|
794
894
|
content_name: variant?.product?.title,
|
|
@@ -875,9 +975,9 @@ function useRemoveCartCodes(options) {
|
|
|
875
975
|
}
|
|
876
976
|
|
|
877
977
|
// src/hooks/cart/use-add-to-cart.ts
|
|
878
|
-
function useAddToCart({ withTrack = true
|
|
879
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
880
|
-
const {
|
|
978
|
+
function useAddToCart({ withTrack = true } = {}, swrOptions) {
|
|
979
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
980
|
+
const { cart } = useCartContext();
|
|
881
981
|
const { trigger: applyCartCodes } = useApplyCartCodes();
|
|
882
982
|
const { trigger: removeInvalidCodes } = useRemoveCartCodes();
|
|
883
983
|
const { trigger: addCartLines2 } = useAddCartLines();
|
|
@@ -899,7 +999,8 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
899
999
|
const lines = lineItems.map((item) => ({
|
|
900
1000
|
merchandiseId: item.variant?.id || "",
|
|
901
1001
|
quantity: item.quantity || 1,
|
|
902
|
-
attributes: item.attributes
|
|
1002
|
+
attributes: item.attributes,
|
|
1003
|
+
sellingPlanId: item.sellingPlanId
|
|
903
1004
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
904
1005
|
if (lines.length === 0) {
|
|
905
1006
|
return;
|
|
@@ -913,6 +1014,7 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
913
1014
|
if (!resultCart) {
|
|
914
1015
|
return void 0;
|
|
915
1016
|
}
|
|
1017
|
+
console.log("npm addCartLines resultCart", resultCart);
|
|
916
1018
|
if (resultCart.discountCodes && resultCart.discountCodes.length > 0) {
|
|
917
1019
|
const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
|
|
918
1020
|
if (unapplicableCodes.length > 0) {
|
|
@@ -934,34 +1036,16 @@ function useAddToCart({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
934
1036
|
discountCodes
|
|
935
1037
|
});
|
|
936
1038
|
}
|
|
937
|
-
if (withTrack
|
|
938
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
939
|
-
variant: {
|
|
940
|
-
id: line.variant.id,
|
|
941
|
-
sku: line.variant.sku || "",
|
|
942
|
-
title: line.variant.name,
|
|
943
|
-
price: {
|
|
944
|
-
amount: String(line.variant.price),
|
|
945
|
-
currencyCode: resultCart.currency.code
|
|
946
|
-
},
|
|
947
|
-
product: line.product ? {
|
|
948
|
-
title: line.product.title || line.name,
|
|
949
|
-
productType: line.product.productType,
|
|
950
|
-
vendor: line.product.vendor
|
|
951
|
-
} : void 0
|
|
952
|
-
},
|
|
953
|
-
quantity: line.quantity
|
|
954
|
-
}));
|
|
1039
|
+
if (withTrack) {
|
|
955
1040
|
trackAddToCartGA({
|
|
956
|
-
lineItems
|
|
957
|
-
gtmParams: { ...gtmParams, brand }
|
|
958
|
-
brand
|
|
1041
|
+
lineItems,
|
|
1042
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
959
1043
|
});
|
|
960
|
-
trackAddToCartFBQ({ lineItems
|
|
1044
|
+
trackAddToCartFBQ({ lineItems });
|
|
961
1045
|
}
|
|
962
1046
|
return resultCart;
|
|
963
1047
|
},
|
|
964
|
-
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack
|
|
1048
|
+
[client, locale, cartCookieAdapter, userAdapter, cart, withTrack]
|
|
965
1049
|
);
|
|
966
1050
|
return useSWRMutation("add-to-cart", addToCart, swrOptions);
|
|
967
1051
|
}
|
|
@@ -1042,8 +1126,8 @@ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
|
|
|
1042
1126
|
);
|
|
1043
1127
|
return useSWRMutation("update-cart-attributes", updateAttributes, options);
|
|
1044
1128
|
}
|
|
1045
|
-
function useBuyNow({ withTrack = true
|
|
1046
|
-
const { client, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
1129
|
+
function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
1130
|
+
const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
|
|
1047
1131
|
const isLoggedIn = userAdapter?.isLoggedIn || false;
|
|
1048
1132
|
const buyNow = useCallback(
|
|
1049
1133
|
async (_key, { arg }) => {
|
|
@@ -1061,9 +1145,10 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1061
1145
|
return;
|
|
1062
1146
|
}
|
|
1063
1147
|
const lines = lineItems.map((item) => ({
|
|
1064
|
-
merchandiseId: item.variant?.id ||
|
|
1148
|
+
merchandiseId: item.variant?.id || "",
|
|
1065
1149
|
quantity: item.quantity || 1,
|
|
1066
|
-
attributes: item.attributes
|
|
1150
|
+
attributes: item.attributes,
|
|
1151
|
+
sellingPlanId: item.sellingPlanId
|
|
1067
1152
|
})).filter((item) => item.merchandiseId && item.quantity);
|
|
1068
1153
|
if (lines.length === 0) {
|
|
1069
1154
|
return;
|
|
@@ -1080,27 +1165,9 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1080
1165
|
throw new Error("Failed to create cart for buy now");
|
|
1081
1166
|
}
|
|
1082
1167
|
if (withTrack && resultCart.lineItems) {
|
|
1083
|
-
const trackingLineItems = resultCart.lineItems.map((line) => ({
|
|
1084
|
-
variant: {
|
|
1085
|
-
id: line.variantId,
|
|
1086
|
-
sku: line.variant.sku || "",
|
|
1087
|
-
title: line.variant.name,
|
|
1088
|
-
price: {
|
|
1089
|
-
amount: String(line.variant.price),
|
|
1090
|
-
currencyCode: resultCart.currency.code
|
|
1091
|
-
},
|
|
1092
|
-
product: line.product ? {
|
|
1093
|
-
title: line.product.title || line.name,
|
|
1094
|
-
productType: line.product.productType,
|
|
1095
|
-
vendor: line.product.vendor
|
|
1096
|
-
} : void 0
|
|
1097
|
-
},
|
|
1098
|
-
quantity: line.quantity
|
|
1099
|
-
}));
|
|
1100
1168
|
trackBuyNowGA({
|
|
1101
|
-
lineItems
|
|
1102
|
-
gtmParams: { ...gtmParams, brand }
|
|
1103
|
-
brand
|
|
1169
|
+
lineItems,
|
|
1170
|
+
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
1104
1171
|
});
|
|
1105
1172
|
if (fbqTrackConfig) {
|
|
1106
1173
|
trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
|
|
@@ -1117,10 +1184,64 @@ function useBuyNow({ withTrack = true, brand } = {}, swrOptions) {
|
|
|
1117
1184
|
}
|
|
1118
1185
|
return resultCart;
|
|
1119
1186
|
},
|
|
1120
|
-
[client, locale, isLoggedIn, cartCookieAdapter, withTrack
|
|
1187
|
+
[client, locale, isLoggedIn, cartCookieAdapter, withTrack]
|
|
1121
1188
|
);
|
|
1122
1189
|
return useSWRMutation("buy-now", buyNow, swrOptions);
|
|
1123
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
|
+
}
|
|
1124
1245
|
|
|
1125
1246
|
// src/hooks/cart/types/order-discount.ts
|
|
1126
1247
|
var OrderDiscountType = /* @__PURE__ */ ((OrderDiscountType2) => {
|
|
@@ -1270,8 +1391,6 @@ var useCartAttributes = ({
|
|
|
1270
1391
|
memberSetting,
|
|
1271
1392
|
cart
|
|
1272
1393
|
});
|
|
1273
|
-
console.log("memberSetting", memberSetting);
|
|
1274
|
-
console.log("hasPlusMember", hasPlusMember);
|
|
1275
1394
|
useEffect(() => {
|
|
1276
1395
|
setCurrentUrl(window.location.href);
|
|
1277
1396
|
}, []);
|
|
@@ -1320,15 +1439,19 @@ var useCartAttributes = ({
|
|
|
1320
1439
|
];
|
|
1321
1440
|
}, [profile?.memberType, profile?.token, userType, hasPlusMember]);
|
|
1322
1441
|
const functionAttributes = useMemo(() => {
|
|
1323
|
-
|
|
1324
|
-
|
|
1442
|
+
const hasFunctionEnvAttribute = cart?.lineItems.some(
|
|
1443
|
+
(item) => item.customAttributes?.some((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY)
|
|
1444
|
+
);
|
|
1445
|
+
const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
|
|
1446
|
+
return hasFunctionEnvAttribute ? [
|
|
1447
|
+
{
|
|
1325
1448
|
key: "_discounts_function_env",
|
|
1326
1449
|
value: JSON.stringify({
|
|
1327
|
-
discount_code:
|
|
1450
|
+
discount_code: discountCodes,
|
|
1328
1451
|
user_tags: customer?.tags || []
|
|
1329
1452
|
})
|
|
1330
1453
|
}
|
|
1331
|
-
];
|
|
1454
|
+
] : [];
|
|
1332
1455
|
}, [cart]);
|
|
1333
1456
|
const presellAttributes = useMemo(() => {
|
|
1334
1457
|
return [
|
|
@@ -2505,6 +2628,69 @@ var usePlusMemberDeliveryCodes = ({
|
|
|
2505
2628
|
[deliveryData]
|
|
2506
2629
|
);
|
|
2507
2630
|
};
|
|
2631
|
+
function useUpdateCartDeliveryOptions(mutate, metafieldIdentifiers, options) {
|
|
2632
|
+
const { client, locale, cartCookieAdapter } = useShopify();
|
|
2633
|
+
const updateDeliveryOptions = useCallback(
|
|
2634
|
+
async (_key, { arg }) => {
|
|
2635
|
+
const updatedCart = await updateCartDeliveryOptions(client, {
|
|
2636
|
+
...arg,
|
|
2637
|
+
metafieldIdentifiers,
|
|
2638
|
+
cookieAdapter: cartCookieAdapter
|
|
2639
|
+
});
|
|
2640
|
+
console.log("useUpdateCartDeliveryOptions updatedCart", updatedCart);
|
|
2641
|
+
if (updatedCart) {
|
|
2642
|
+
mutate(updatedCart);
|
|
2643
|
+
}
|
|
2644
|
+
return updatedCart;
|
|
2645
|
+
},
|
|
2646
|
+
[client, locale, cartCookieAdapter, mutate]
|
|
2647
|
+
);
|
|
2648
|
+
return useSWRMutation("update-cart-delivery-options", updateDeliveryOptions, options);
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
// src/hooks/member/plus/use-update-plus-member-delivery-options.ts
|
|
2652
|
+
var useUpdatePlusMemberDeliveryOptions = ({
|
|
2653
|
+
options
|
|
2654
|
+
}) => {
|
|
2655
|
+
const { cart, mutateCart: mutate, metafieldIdentifiers } = useCartContext();
|
|
2656
|
+
const { trigger: updateCartDeliveryOptions2, isMutating } = useUpdateCartDeliveryOptions(
|
|
2657
|
+
mutate,
|
|
2658
|
+
metafieldIdentifiers
|
|
2659
|
+
);
|
|
2660
|
+
const handler = useCallback(
|
|
2661
|
+
async (_, { arg }) => {
|
|
2662
|
+
const { deliveryData } = arg;
|
|
2663
|
+
const firstDeliveryGroup = cart?.deliveryGroups?.[0];
|
|
2664
|
+
const deliveryGroupId = firstDeliveryGroup?.id;
|
|
2665
|
+
const selectedOptionCode = deliveryData?.deliveryCustomData?.selected_delivery_option?.code;
|
|
2666
|
+
if (!deliveryGroupId || !selectedOptionCode || selectedOptionCode === firstDeliveryGroup?.selectedDeliveryOption?.code) {
|
|
2667
|
+
return null;
|
|
2668
|
+
}
|
|
2669
|
+
const deliveryGroup = cart?.deliveryGroups?.find((group) => group?.id === deliveryGroupId);
|
|
2670
|
+
const matchedOption = deliveryGroup?.deliveryOptions?.find(
|
|
2671
|
+
(option) => option?.code === selectedOptionCode
|
|
2672
|
+
);
|
|
2673
|
+
if (!matchedOption?.handle) {
|
|
2674
|
+
return null;
|
|
2675
|
+
}
|
|
2676
|
+
const deliveryOptions = [
|
|
2677
|
+
{
|
|
2678
|
+
deliveryGroupId,
|
|
2679
|
+
deliveryOptionHandle: matchedOption.handle
|
|
2680
|
+
}
|
|
2681
|
+
];
|
|
2682
|
+
const updatedCart = await updateCartDeliveryOptions2({
|
|
2683
|
+
selectedDeliveryOptions: deliveryOptions
|
|
2684
|
+
});
|
|
2685
|
+
if (updatedCart && mutate) {
|
|
2686
|
+
mutate(updatedCart);
|
|
2687
|
+
}
|
|
2688
|
+
return updatedCart;
|
|
2689
|
+
},
|
|
2690
|
+
[cart, updateCartDeliveryOptions2, mutate]
|
|
2691
|
+
);
|
|
2692
|
+
return useSWRMutation("update-cart-delivery-options", handler, options);
|
|
2693
|
+
};
|
|
2508
2694
|
var usePlusMemberItemCustomAttributes = ({
|
|
2509
2695
|
deliveryData
|
|
2510
2696
|
}) => {
|
|
@@ -2591,15 +2777,14 @@ var usePlusMemberCheckoutCustomAttributes = ({
|
|
|
2591
2777
|
}, [deliveryCustomData, product, profile, userType, variant, isShowShippingBenefits]);
|
|
2592
2778
|
};
|
|
2593
2779
|
function useAutoRemovePlusMemberInCart({
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2780
|
+
cart,
|
|
2781
|
+
profile,
|
|
2782
|
+
memberSetting
|
|
2597
2783
|
}) {
|
|
2598
|
-
const { plus_monthly_product, plus_annual_product } =
|
|
2599
|
-
const { cart } = useCartContext();
|
|
2784
|
+
const { plus_monthly_product, plus_annual_product } = memberSetting || {};
|
|
2600
2785
|
const { trigger: removeCartLines2 } = useRemoveCartLines();
|
|
2601
2786
|
useEffect(() => {
|
|
2602
|
-
if (!cart) return;
|
|
2787
|
+
if (!cart || !plus_monthly_product || !plus_annual_product) return;
|
|
2603
2788
|
const removePlusProduct = async (productType) => {
|
|
2604
2789
|
if (!productType) return;
|
|
2605
2790
|
const product = cart.lineItems?.find(
|
|
@@ -2611,26 +2796,53 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2611
2796
|
});
|
|
2612
2797
|
}
|
|
2613
2798
|
};
|
|
2614
|
-
if (isMonthlyPlus) {
|
|
2799
|
+
if (profile?.isMonthlyPlus) {
|
|
2615
2800
|
removePlusProduct(plus_monthly_product);
|
|
2616
2801
|
}
|
|
2617
|
-
if (isAnnualPlus) {
|
|
2802
|
+
if (profile?.isAnnualPlus) {
|
|
2618
2803
|
removePlusProduct(plus_annual_product);
|
|
2619
2804
|
}
|
|
2805
|
+
}, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
|
|
2806
|
+
}
|
|
2807
|
+
function useAddPlusMemberProductsToCart({
|
|
2808
|
+
cart,
|
|
2809
|
+
profile
|
|
2810
|
+
}) {
|
|
2811
|
+
const { selectedPlusMemberMode, selectedPlusMemberProduct, plusMemberMetafields } = usePlusMemberContext();
|
|
2812
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2813
|
+
memberSetting: plusMemberMetafields,
|
|
2814
|
+
cart
|
|
2815
|
+
});
|
|
2816
|
+
const plusMemberProduct = useMemo(() => {
|
|
2817
|
+
if (!selectedPlusMemberProduct || selectedPlusMemberMode === "free" /* FREE */) {
|
|
2818
|
+
return void 0;
|
|
2819
|
+
}
|
|
2820
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2821
|
+
return void 0;
|
|
2822
|
+
}
|
|
2823
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2824
|
+
return void 0;
|
|
2825
|
+
}
|
|
2826
|
+
if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
|
|
2827
|
+
return void 0;
|
|
2828
|
+
}
|
|
2829
|
+
if (!profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
|
|
2830
|
+
return void 0;
|
|
2831
|
+
}
|
|
2832
|
+
return selectedPlusMemberProduct;
|
|
2620
2833
|
}, [
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
removeCartLines2
|
|
2834
|
+
selectedPlusMemberMode,
|
|
2835
|
+
selectedPlusMemberProduct?.variant,
|
|
2836
|
+
selectedPlusMemberProduct?.product,
|
|
2837
|
+
hasMonthlyPlus,
|
|
2838
|
+
hasAnnualPlus
|
|
2627
2839
|
]);
|
|
2840
|
+
return plusMemberProduct;
|
|
2628
2841
|
}
|
|
2629
2842
|
var PlusMemberProvider = ({
|
|
2630
2843
|
variant,
|
|
2631
2844
|
product,
|
|
2632
|
-
|
|
2633
|
-
metafields,
|
|
2845
|
+
memberSetting,
|
|
2634
2846
|
initialSelectedPlusMemberMode = "free",
|
|
2635
2847
|
profile,
|
|
2636
2848
|
locale,
|
|
@@ -2650,14 +2862,14 @@ var PlusMemberProvider = ({
|
|
|
2650
2862
|
const [deleteMarginBottom, setDeleteMarginBottom] = useState(false);
|
|
2651
2863
|
const shippingMethodsContext = useShippingMethods({
|
|
2652
2864
|
variant,
|
|
2653
|
-
plusMemberMetafields:
|
|
2865
|
+
plusMemberMetafields: memberSetting,
|
|
2654
2866
|
selectedPlusMemberMode});
|
|
2655
2867
|
const plusMemberHandles = useMemo(() => {
|
|
2656
2868
|
return [
|
|
2657
|
-
|
|
2658
|
-
|
|
2869
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2870
|
+
memberSetting?.plus_annual_product?.handle
|
|
2659
2871
|
].filter(Boolean);
|
|
2660
|
-
}, [
|
|
2872
|
+
}, [memberSetting]);
|
|
2661
2873
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2662
2874
|
handles: plusMemberHandles
|
|
2663
2875
|
});
|
|
@@ -2665,25 +2877,24 @@ var PlusMemberProvider = ({
|
|
|
2665
2877
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2666
2878
|
return null;
|
|
2667
2879
|
}
|
|
2668
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2669
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2880
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2881
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2670
2882
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2671
2883
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2672
2884
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2673
|
-
}, [plusMemberProducts,
|
|
2885
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2674
2886
|
return /* @__PURE__ */ jsx(
|
|
2675
2887
|
PlusMemberContext.Provider,
|
|
2676
2888
|
{
|
|
2677
2889
|
value: {
|
|
2678
2890
|
variant,
|
|
2679
|
-
shopCommon,
|
|
2680
2891
|
zipCode,
|
|
2681
2892
|
setZipCode,
|
|
2682
2893
|
allowNextDayDelivery,
|
|
2683
2894
|
setAllowNextDayDelivery,
|
|
2684
2895
|
allowThirdDayDelivery,
|
|
2685
2896
|
setAllowThirdDayDelivery,
|
|
2686
|
-
plusMemberMetafields:
|
|
2897
|
+
plusMemberMetafields: memberSetting,
|
|
2687
2898
|
selectedPlusMemberMode,
|
|
2688
2899
|
setSelectedPlusMemberMode,
|
|
2689
2900
|
showAreaCheckModal,
|
|
@@ -2902,6 +3113,9 @@ function CartProvider({
|
|
|
2902
3113
|
}) {
|
|
2903
3114
|
const { client, cartCookieAdapter } = useShopify();
|
|
2904
3115
|
const [customAttributes, setCustomAttributes] = useState([]);
|
|
3116
|
+
const [customAttributesNeedDelete, setCustomAttributesNeedDelete] = useState(
|
|
3117
|
+
[]
|
|
3118
|
+
);
|
|
2905
3119
|
const [isCodeChanging, setIsCodeChanging] = useState(false);
|
|
2906
3120
|
const [loadingState, setLoadingState] = useState({
|
|
2907
3121
|
editLineQuantityLoading: false,
|
|
@@ -2932,7 +3146,11 @@ function CartProvider({
|
|
|
2932
3146
|
useRequest(
|
|
2933
3147
|
() => {
|
|
2934
3148
|
const newAttributes = [...attributes, ...customAttributes];
|
|
2935
|
-
const needUpdate = cart && !
|
|
3149
|
+
const needUpdate = cart && !checkAttributesUpdateNeeded(
|
|
3150
|
+
cart.customAttributes,
|
|
3151
|
+
newAttributes,
|
|
3152
|
+
customAttributesNeedDelete
|
|
3153
|
+
);
|
|
2936
3154
|
if (needUpdate) {
|
|
2937
3155
|
return updateAttributes({ attributes: newAttributes });
|
|
2938
3156
|
} else {
|
|
@@ -2953,11 +3171,12 @@ function CartProvider({
|
|
|
2953
3171
|
isCartLoading: isCartLoading || isCodeChanging,
|
|
2954
3172
|
setLoadingState
|
|
2955
3173
|
});
|
|
2956
|
-
const removeCustomAttributes = useCallback(
|
|
2957
|
-
|
|
2958
|
-
(
|
|
2959
|
-
|
|
2960
|
-
|
|
3174
|
+
const removeCustomAttributes = useCallback(
|
|
3175
|
+
(attributes2) => {
|
|
3176
|
+
setCustomAttributesNeedDelete(attributes2);
|
|
3177
|
+
},
|
|
3178
|
+
[setCustomAttributesNeedDelete]
|
|
3179
|
+
);
|
|
2961
3180
|
const addCustomAttributes = useCallback(
|
|
2962
3181
|
(attributes2) => {
|
|
2963
3182
|
const sameAttributes = attributes2.filter(
|
|
@@ -3044,6 +3263,7 @@ function CartProvider({
|
|
|
3044
3263
|
isCodeChanging,
|
|
3045
3264
|
setIsCodeChanging,
|
|
3046
3265
|
autoFreeGiftConfig,
|
|
3266
|
+
gradientGiftsConfig,
|
|
3047
3267
|
setLoadingState,
|
|
3048
3268
|
loadingState,
|
|
3049
3269
|
// function满赠
|
|
@@ -3067,6 +3287,7 @@ function CartProvider({
|
|
|
3067
3287
|
locale,
|
|
3068
3288
|
isCodeChanging,
|
|
3069
3289
|
autoFreeGiftConfig,
|
|
3290
|
+
gradientGiftsConfig,
|
|
3070
3291
|
loadingState,
|
|
3071
3292
|
// function满赠
|
|
3072
3293
|
functionAutoFreeGift,
|
|
@@ -3090,6 +3311,6 @@ function useCartContext() {
|
|
|
3090
3311
|
return context;
|
|
3091
3312
|
}
|
|
3092
3313
|
|
|
3093
|
-
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,
|
|
3314
|
+
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, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3094
3315
|
//# sourceMappingURL=index.mjs.map
|
|
3095
3316
|
//# sourceMappingURL=index.mjs.map
|