@anker-in/shopify-react 0.1.1-beta.1 → 0.1.1-beta.2
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 +89 -40
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +87 -39
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-CCMIeIUh.d.ts → index-BZ6WbAdZ.d.ts} +53 -14
- package/dist/{index-RevQokdZ.d.mts → index-Bea95u2X.d.mts} +53 -14
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +110 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -49
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +44 -27
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +44 -27
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -181,25 +181,25 @@ var getMatchedMainProductSubTotal = (cartData, variant_list, main_product) => {
|
|
|
181
181
|
return acc + (main_product?.spend_money_type === 1 /* ORIGIN_PRICE */ ? Number(line.subtotalAmount) || 0 : Number(line.totalAmount) || 0);
|
|
182
182
|
}, 0) || 0;
|
|
183
183
|
};
|
|
184
|
-
var
|
|
185
|
-
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
186
|
-
return safeParseJson(attr?.value ?? "") ?? {};
|
|
187
|
-
};
|
|
188
|
-
var isAttributesEqual = (attrs1 = [], attrs2 = []) => {
|
|
189
|
-
if (attrs1.length !== attrs2.length) return false;
|
|
190
|
-
const sorted1 = [...attrs1].sort((a, b) => a.key.localeCompare(b.key));
|
|
191
|
-
const sorted2 = [...attrs2].sort((a, b) => a.key.localeCompare(b.key));
|
|
192
|
-
return sorted1.every(
|
|
193
|
-
(attr, i) => attr.key === sorted2[i]?.key && attr.value === sorted2[i]?.value
|
|
194
|
-
);
|
|
195
|
-
};
|
|
196
|
-
var safeParseJson = (str) => {
|
|
184
|
+
var safeParse = (str) => {
|
|
197
185
|
try {
|
|
198
186
|
return JSON.parse(str);
|
|
199
187
|
} catch (err) {
|
|
200
188
|
return {};
|
|
201
189
|
}
|
|
202
190
|
};
|
|
191
|
+
var getDiscountEnvAttributeValue = (attributes = []) => {
|
|
192
|
+
const attr = attributes.find((attr2) => attr2.key === CUSTOMER_ATTRIBUTE_KEY);
|
|
193
|
+
return safeParse(attr?.value ?? "") ?? {};
|
|
194
|
+
};
|
|
195
|
+
var checkAttributesUpdateNeeded = (oldAttributes, newAttributes, customAttributesNeedRemove) => {
|
|
196
|
+
return oldAttributes.some((attr) => {
|
|
197
|
+
const newAttr = newAttributes.find((newAttr2) => newAttr2.key === attr.key);
|
|
198
|
+
return newAttr ? newAttr.value !== attr.value : true;
|
|
199
|
+
}) || newAttributes.some((attr) => !oldAttributes.some((oldAttr) => oldAttr.key === attr.key)) || customAttributesNeedRemove.some(
|
|
200
|
+
(removeAttr) => oldAttributes.some((oldAttr) => oldAttr.key === removeAttr.key)
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
203
|
var containsAll = (source, requiredItems = []) => {
|
|
204
204
|
if (!requiredItems?.length) return true;
|
|
205
205
|
const sourceSet = new Set(source);
|
|
@@ -488,6 +488,14 @@ var useScriptAutoFreeGift = ({
|
|
|
488
488
|
set_points_subscribe(!!isPointsSubscribe);
|
|
489
489
|
}
|
|
490
490
|
}, [locale]);
|
|
491
|
+
const isActivityAvailable = react.useMemo(() => {
|
|
492
|
+
if (!campaign) return false;
|
|
493
|
+
const query = getQuery();
|
|
494
|
+
const utmCampaign = Cookies5__default.default.get("utm_campaign") || query?.utm_campaign;
|
|
495
|
+
if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
|
|
496
|
+
return false;
|
|
497
|
+
return true;
|
|
498
|
+
}, [campaign]);
|
|
491
499
|
const [upgrade_multiple, upgrade_value] = react.useMemo(() => {
|
|
492
500
|
let upgrade_multiple2 = 1;
|
|
493
501
|
let upgrade_value2 = 0;
|
|
@@ -504,8 +512,8 @@ var useScriptAutoFreeGift = ({
|
|
|
504
512
|
return [upgrade_multiple2, upgrade_value2];
|
|
505
513
|
}, [cart?.lineItems, points_subscribe]);
|
|
506
514
|
const breakpoints = react.useMemo(() => {
|
|
507
|
-
if (!
|
|
508
|
-
return (campaign
|
|
515
|
+
if (!isActivityAvailable) return [];
|
|
516
|
+
return (campaign?.breakpoints || []).map((item) => ({
|
|
509
517
|
breakpoint: new Decimal2__default.default(item.breakpoint).minus(new Decimal2__default.default(upgrade_value)).dividedBy(new Decimal2__default.default(upgrade_multiple)).toFixed(2, Decimal2__default.default.ROUND_DOWN),
|
|
510
518
|
giveawayProducts: item.giveawayProducts || []
|
|
511
519
|
}));
|
|
@@ -529,25 +537,26 @@ var useScriptAutoFreeGift = ({
|
|
|
529
537
|
return true;
|
|
530
538
|
}, [giftHandles]);
|
|
531
539
|
const involvedLines = react.useMemo(() => {
|
|
532
|
-
if (!
|
|
540
|
+
if (!isActivityAvailable) return [];
|
|
533
541
|
return (cart?.lineItems || []).filter((line) => {
|
|
534
542
|
const isNotGift = line?.totalAmount && Number(line.totalAmount) > 0 && line.customAttributes?.every(
|
|
535
543
|
(item) => item.key !== _giveaway
|
|
536
544
|
);
|
|
537
545
|
const hasCampaignTag = line.product?.tags?.some(
|
|
538
|
-
(tag) => campaign
|
|
546
|
+
(tag) => campaign?.includeTags?.includes(tag.trim()) && line.variant?.availableForSale
|
|
539
547
|
);
|
|
540
548
|
return isNotGift && hasCampaignTag;
|
|
541
549
|
});
|
|
542
|
-
}, [cart?.lineItems,
|
|
550
|
+
}, [cart?.lineItems, isActivityAvailable, _giveaway]);
|
|
543
551
|
const involvedSubTotal = react.useMemo(() => {
|
|
544
|
-
if (!
|
|
552
|
+
if (!isActivityAvailable) return new Decimal2__default.default(0);
|
|
545
553
|
return involvedLines.reduce((prev, item) => {
|
|
546
|
-
const amount = campaign
|
|
554
|
+
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
547
555
|
return new Decimal2__default.default(prev).plus(new Decimal2__default.default(amount || 0));
|
|
548
556
|
}, new Decimal2__default.default(0));
|
|
549
|
-
}, [involvedLines,
|
|
557
|
+
}, [involvedLines, isActivityAvailable]);
|
|
550
558
|
const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
|
|
559
|
+
if (!isActivityAvailable) return [null, null];
|
|
551
560
|
const sortedLevels = [...breakpoints].sort(
|
|
552
561
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
553
562
|
);
|
|
@@ -691,8 +700,12 @@ var trackAddToCartGA = ({
|
|
|
691
700
|
}
|
|
692
701
|
const { variant } = lineItems[0];
|
|
693
702
|
const currencyCode = variant.product?.price?.currencyCode;
|
|
694
|
-
const
|
|
695
|
-
|
|
703
|
+
const totalPrice = lineItems?.reduce(
|
|
704
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
705
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? variant2?.price?.amount ?? 0
|
|
706
|
+
),
|
|
707
|
+
new Decimal2__default.default(0)
|
|
708
|
+
).toNumber();
|
|
696
709
|
gaTrack({
|
|
697
710
|
event: "ga4Event",
|
|
698
711
|
event_name: "add_to_cart",
|
|
@@ -707,7 +720,7 @@ var trackAddToCartGA = ({
|
|
|
707
720
|
item_brand: gtmParams?.brand || "",
|
|
708
721
|
item_category: variant2?.product?.productType || "",
|
|
709
722
|
item_variant: variant2?.title || variant2?.title,
|
|
710
|
-
price,
|
|
723
|
+
price: variant2?.compareAtPrice?.amount ?? variant2?.price?.amount,
|
|
711
724
|
quantity: quantity || 1
|
|
712
725
|
})),
|
|
713
726
|
...gtmParams?.ga4Params
|
|
@@ -722,9 +735,12 @@ var trackBeginCheckoutGA = ({
|
|
|
722
735
|
if (!lineItems.length) {
|
|
723
736
|
return;
|
|
724
737
|
}
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
738
|
+
const totalPrice = lineItems?.reduce(
|
|
739
|
+
(prev, { variant }) => prev.plus(
|
|
740
|
+
variant?.finalPrice?.amount ?? variant?.compareAtPrice?.amount ?? variant?.price?.amount ?? 0
|
|
741
|
+
),
|
|
742
|
+
new Decimal2__default.default(0)
|
|
743
|
+
).toNumber();
|
|
728
744
|
gaTrack({
|
|
729
745
|
event: "ga4Event",
|
|
730
746
|
event_name: "begin_checkout",
|
|
@@ -739,7 +755,7 @@ var trackBeginCheckoutGA = ({
|
|
|
739
755
|
item_brand: gtmParams?.brand || "",
|
|
740
756
|
item_category: item.variant?.product?.productType,
|
|
741
757
|
item_variant: item.variant?.title,
|
|
742
|
-
price,
|
|
758
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
743
759
|
quantity: item.quantity || 1
|
|
744
760
|
})),
|
|
745
761
|
...gtmParams?.ga4Params
|
|
@@ -755,8 +771,12 @@ var trackBuyNowGA = ({
|
|
|
755
771
|
}
|
|
756
772
|
const { variant } = lineItems[0];
|
|
757
773
|
const currencyCode = variant.price?.currencyCode;
|
|
758
|
-
const
|
|
759
|
-
|
|
774
|
+
const totalPrice = lineItems?.reduce(
|
|
775
|
+
(prev, { variant: variant2 }) => prev.plus(
|
|
776
|
+
variant2?.finalPrice?.amount ?? variant2?.compareAtPrice?.amount ?? (variant2?.price?.amount || 0)
|
|
777
|
+
),
|
|
778
|
+
new Decimal2__default.default(0)
|
|
779
|
+
).toNumber();
|
|
760
780
|
gaTrack({
|
|
761
781
|
event: "ga4Event",
|
|
762
782
|
event_name: "begin_checkout",
|
|
@@ -771,7 +791,7 @@ var trackBuyNowGA = ({
|
|
|
771
791
|
item_brand: gtmParams?.brand || "",
|
|
772
792
|
item_category: item.variant?.product?.productType || "",
|
|
773
793
|
item_variant: item.variant?.title,
|
|
774
|
-
price,
|
|
794
|
+
price: item.variant?.compareAtPrice?.amount ?? item.variant?.price?.amount,
|
|
775
795
|
quantity: item.quantity || 1
|
|
776
796
|
})),
|
|
777
797
|
...gtmParams?.ga4Params
|
|
@@ -2592,11 +2612,43 @@ function useAutoRemovePlusMemberInCart({
|
|
|
2592
2612
|
removeCartLines2
|
|
2593
2613
|
]);
|
|
2594
2614
|
}
|
|
2615
|
+
function useAddPlusMemberProductsToCart({
|
|
2616
|
+
cart,
|
|
2617
|
+
memberSetting,
|
|
2618
|
+
selectedPlusMemberMode,
|
|
2619
|
+
selectedPlusMemberProduct
|
|
2620
|
+
}) {
|
|
2621
|
+
const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
|
|
2622
|
+
cart,
|
|
2623
|
+
memberSetting
|
|
2624
|
+
});
|
|
2625
|
+
const plusMemberProduct = react.useMemo(() => {
|
|
2626
|
+
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2627
|
+
return void 0;
|
|
2628
|
+
}
|
|
2629
|
+
if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
|
|
2630
|
+
return void 0;
|
|
2631
|
+
}
|
|
2632
|
+
if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
|
|
2633
|
+
return void 0;
|
|
2634
|
+
}
|
|
2635
|
+
if (!selectedPlusMemberProduct) {
|
|
2636
|
+
return void 0;
|
|
2637
|
+
}
|
|
2638
|
+
return selectedPlusMemberProduct;
|
|
2639
|
+
}, [
|
|
2640
|
+
selectedPlusMemberMode,
|
|
2641
|
+
selectedPlusMemberProduct?.variant,
|
|
2642
|
+
selectedPlusMemberProduct?.product,
|
|
2643
|
+
hasMonthlyPlus,
|
|
2644
|
+
hasAnnualPlus
|
|
2645
|
+
]);
|
|
2646
|
+
return plusMemberProduct;
|
|
2647
|
+
}
|
|
2595
2648
|
var PlusMemberProvider = ({
|
|
2596
2649
|
variant,
|
|
2597
2650
|
product,
|
|
2598
|
-
|
|
2599
|
-
metafields,
|
|
2651
|
+
memberSetting,
|
|
2600
2652
|
initialSelectedPlusMemberMode = "free",
|
|
2601
2653
|
profile,
|
|
2602
2654
|
locale,
|
|
@@ -2616,14 +2668,14 @@ var PlusMemberProvider = ({
|
|
|
2616
2668
|
const [deleteMarginBottom, setDeleteMarginBottom] = react.useState(false);
|
|
2617
2669
|
const shippingMethodsContext = useShippingMethods({
|
|
2618
2670
|
variant,
|
|
2619
|
-
plusMemberMetafields:
|
|
2671
|
+
plusMemberMetafields: memberSetting,
|
|
2620
2672
|
selectedPlusMemberMode});
|
|
2621
2673
|
const plusMemberHandles = react.useMemo(() => {
|
|
2622
2674
|
return [
|
|
2623
|
-
|
|
2624
|
-
|
|
2675
|
+
memberSetting?.plus_monthly_product?.handle,
|
|
2676
|
+
memberSetting?.plus_annual_product?.handle
|
|
2625
2677
|
].filter(Boolean);
|
|
2626
|
-
}, [
|
|
2678
|
+
}, [memberSetting]);
|
|
2627
2679
|
const { data: plusMemberProducts = [] } = useProductsByHandles({
|
|
2628
2680
|
handles: plusMemberHandles
|
|
2629
2681
|
});
|
|
@@ -2631,25 +2683,24 @@ var PlusMemberProvider = ({
|
|
|
2631
2683
|
if (selectedPlusMemberMode === "free" /* FREE */) {
|
|
2632
2684
|
return null;
|
|
2633
2685
|
}
|
|
2634
|
-
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2635
|
-
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ?
|
|
2686
|
+
const handle = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.handle : memberSetting?.plus_annual_product?.handle;
|
|
2687
|
+
const sku = selectedPlusMemberMode === "monthly" /* MONTHLY */ ? memberSetting?.plus_monthly_product?.sku : memberSetting?.plus_annual_product?.sku;
|
|
2636
2688
|
const product2 = plusMemberProducts?.find((p) => p.handle === handle);
|
|
2637
2689
|
const variant2 = product2?.variants?.find((v) => v.sku === sku);
|
|
2638
2690
|
return product2 && variant2 ? { product: product2, variant: variant2 } : null;
|
|
2639
|
-
}, [plusMemberProducts,
|
|
2691
|
+
}, [plusMemberProducts, memberSetting, selectedPlusMemberMode]);
|
|
2640
2692
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2641
2693
|
PlusMemberContext.Provider,
|
|
2642
2694
|
{
|
|
2643
2695
|
value: {
|
|
2644
2696
|
variant,
|
|
2645
|
-
shopCommon,
|
|
2646
2697
|
zipCode,
|
|
2647
2698
|
setZipCode,
|
|
2648
2699
|
allowNextDayDelivery,
|
|
2649
2700
|
setAllowNextDayDelivery,
|
|
2650
2701
|
allowThirdDayDelivery,
|
|
2651
2702
|
setAllowThirdDayDelivery,
|
|
2652
|
-
plusMemberMetafields:
|
|
2703
|
+
plusMemberMetafields: memberSetting,
|
|
2653
2704
|
selectedPlusMemberMode,
|
|
2654
2705
|
setSelectedPlusMemberMode,
|
|
2655
2706
|
showAreaCheckModal,
|
|
@@ -2868,6 +2919,9 @@ function CartProvider({
|
|
|
2868
2919
|
}) {
|
|
2869
2920
|
const { client, cartCookieAdapter } = useShopify();
|
|
2870
2921
|
const [customAttributes, setCustomAttributes] = react.useState([]);
|
|
2922
|
+
const [customAttributesNeedDelete, setCustomAttributesNeedDelete] = react.useState(
|
|
2923
|
+
[]
|
|
2924
|
+
);
|
|
2871
2925
|
const [isCodeChanging, setIsCodeChanging] = react.useState(false);
|
|
2872
2926
|
const [loadingState, setLoadingState] = react.useState({
|
|
2873
2927
|
editLineQuantityLoading: false,
|
|
@@ -2898,7 +2952,11 @@ function CartProvider({
|
|
|
2898
2952
|
ahooks.useRequest(
|
|
2899
2953
|
() => {
|
|
2900
2954
|
const newAttributes = [...attributes, ...customAttributes];
|
|
2901
|
-
const needUpdate = cart && !
|
|
2955
|
+
const needUpdate = cart && !checkAttributesUpdateNeeded(
|
|
2956
|
+
cart.customAttributes,
|
|
2957
|
+
newAttributes,
|
|
2958
|
+
customAttributesNeedDelete
|
|
2959
|
+
);
|
|
2902
2960
|
if (needUpdate) {
|
|
2903
2961
|
return updateAttributes({ attributes: newAttributes });
|
|
2904
2962
|
} else {
|
|
@@ -2919,11 +2977,12 @@ function CartProvider({
|
|
|
2919
2977
|
isCartLoading: isCartLoading || isCodeChanging,
|
|
2920
2978
|
setLoadingState
|
|
2921
2979
|
});
|
|
2922
|
-
const removeCustomAttributes = react.useCallback(
|
|
2923
|
-
|
|
2924
|
-
(
|
|
2925
|
-
|
|
2926
|
-
|
|
2980
|
+
const removeCustomAttributes = react.useCallback(
|
|
2981
|
+
(attributes2) => {
|
|
2982
|
+
setCustomAttributesNeedDelete(attributes2);
|
|
2983
|
+
},
|
|
2984
|
+
[setCustomAttributesNeedDelete]
|
|
2985
|
+
);
|
|
2927
2986
|
const addCustomAttributes = react.useCallback(
|
|
2928
2987
|
(attributes2) => {
|
|
2929
2988
|
const sameAttributes = attributes2.filter(
|
|
@@ -3105,6 +3164,7 @@ exports.atobID = atobID;
|
|
|
3105
3164
|
exports.browserCartCookieAdapter = browserCartCookieAdapter;
|
|
3106
3165
|
exports.browserCookieAdapter = browserCookieAdapter;
|
|
3107
3166
|
exports.btoaID = btoaID;
|
|
3167
|
+
exports.checkAttributesUpdateNeeded = checkAttributesUpdateNeeded;
|
|
3108
3168
|
exports.clearGeoLocationCache = clearGeoLocationCache;
|
|
3109
3169
|
exports.currencyCodeMapping = currencyCodeMapping;
|
|
3110
3170
|
exports.defaultSWRMutationConfiguration = defaultSWRMutationConfiguration;
|
|
@@ -3116,15 +3176,15 @@ exports.getDiscountEnvAttributeValue = getDiscountEnvAttributeValue;
|
|
|
3116
3176
|
exports.getMatchedMainProductSubTotal = getMatchedMainProductSubTotal;
|
|
3117
3177
|
exports.getQuery = getQuery;
|
|
3118
3178
|
exports.getReferralAttributes = getReferralAttributes;
|
|
3119
|
-
exports.isAttributesEqual = isAttributesEqual;
|
|
3120
3179
|
exports.preCheck = preCheck;
|
|
3121
|
-
exports.
|
|
3180
|
+
exports.safeParse = safeParse;
|
|
3122
3181
|
exports.trackAddToCartFBQ = trackAddToCartFBQ;
|
|
3123
3182
|
exports.trackAddToCartGA = trackAddToCartGA;
|
|
3124
3183
|
exports.trackBeginCheckoutGA = trackBeginCheckoutGA;
|
|
3125
3184
|
exports.trackBuyNowFBQ = trackBuyNowFBQ;
|
|
3126
3185
|
exports.trackBuyNowGA = trackBuyNowGA;
|
|
3127
3186
|
exports.useAddCartLines = useAddCartLines;
|
|
3187
|
+
exports.useAddPlusMemberProductsToCart = useAddPlusMemberProductsToCart;
|
|
3128
3188
|
exports.useAddToCart = useAddToCart;
|
|
3129
3189
|
exports.useAllBlogs = useAllBlogs;
|
|
3130
3190
|
exports.useAllCollections = useAllCollections;
|