@anker-in/shopify-react 0.1.1-beta.17 → 0.1.1-beta.19
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.js +71 -35
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +71 -35
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +77 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -36
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +72 -32
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +72 -32
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/provider/index.js
CHANGED
|
@@ -486,18 +486,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
486
486
|
}
|
|
487
487
|
return true;
|
|
488
488
|
}, [giftHandles]);
|
|
489
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
489
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
490
|
+
shouldFetch ? giftHandles : null,
|
|
491
|
+
async () => {
|
|
492
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
493
|
+
handles: giftHandles,
|
|
494
|
+
locale
|
|
495
|
+
});
|
|
496
|
+
const result = Array.isArray(res) ? res : [];
|
|
497
|
+
giftProductsCache.current = {
|
|
498
|
+
data: result,
|
|
499
|
+
giftHandles: [...giftHandles]
|
|
500
|
+
};
|
|
501
|
+
return result;
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
revalidateOnFocus: false
|
|
505
|
+
}
|
|
506
|
+
);
|
|
501
507
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
502
508
|
if (giftProductsCache.current && !shouldFetch) {
|
|
503
509
|
return giftProductsCache.current.data || void 0;
|
|
@@ -550,12 +556,14 @@ var useScriptAutoFreeGift = ({
|
|
|
550
556
|
upgrade_multiple2 = 1.2;
|
|
551
557
|
upgrade_value2 = 40;
|
|
552
558
|
}
|
|
553
|
-
effectiveCart?.lineItems?.forEach(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
+
effectiveCart?.lineItems?.forEach(
|
|
560
|
+
({ customAttributes }) => {
|
|
561
|
+
customAttributes?.forEach(({ key, value }) => {
|
|
562
|
+
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
563
|
+
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
);
|
|
559
567
|
return [upgrade_multiple2, upgrade_value2];
|
|
560
568
|
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
561
569
|
const breakpoints = react.useMemo(() => {
|
|
@@ -620,18 +628,24 @@ var useScriptAutoFreeGift = ({
|
|
|
620
628
|
const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
|
|
621
629
|
return [currentLevel, nextLevel];
|
|
622
630
|
}, [breakpoints, involvedSubTotal, involvedLines.length]);
|
|
623
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
631
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
632
|
+
shouldFetch ? giftHandles : null,
|
|
633
|
+
async () => {
|
|
634
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
635
|
+
handles: giftHandles,
|
|
636
|
+
locale
|
|
637
|
+
});
|
|
638
|
+
const result = Array.isArray(res) ? res : [];
|
|
639
|
+
giftProductsCache.current = {
|
|
640
|
+
data: result,
|
|
641
|
+
giftHandles: [...giftHandles]
|
|
642
|
+
};
|
|
643
|
+
return result;
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
revalidateOnFocus: false
|
|
647
|
+
}
|
|
648
|
+
);
|
|
635
649
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
636
650
|
if (giftProductsCache.current && !shouldFetch) {
|
|
637
651
|
return giftProductsCache.current.data || void 0;
|
|
@@ -853,8 +867,29 @@ var useCartAttributes = ({
|
|
|
853
867
|
[memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
|
|
854
868
|
);
|
|
855
869
|
const extraAttributesInCart = react.useMemo(() => {
|
|
870
|
+
const commonAttributeKeys = [
|
|
871
|
+
// member attributes
|
|
872
|
+
"_token",
|
|
873
|
+
"_member_type",
|
|
874
|
+
"_user_type",
|
|
875
|
+
"_is_login",
|
|
876
|
+
"_login_user",
|
|
877
|
+
// function attributes
|
|
878
|
+
"_discounts_function_env",
|
|
879
|
+
// presell attributes
|
|
880
|
+
"_presale",
|
|
881
|
+
// weight attributes
|
|
882
|
+
"_weight",
|
|
883
|
+
"_app_source_name",
|
|
884
|
+
// tracking attributes
|
|
885
|
+
"utm_params",
|
|
886
|
+
// referral attributes
|
|
887
|
+
"_invite_code",
|
|
888
|
+
"_play_mode_id",
|
|
889
|
+
"_popup"
|
|
890
|
+
];
|
|
856
891
|
return cart?.customAttributes?.filter(
|
|
857
|
-
(item) => !
|
|
892
|
+
(item) => !commonAttributeKeys.includes(item.key)
|
|
858
893
|
) || [];
|
|
859
894
|
}, [cart]);
|
|
860
895
|
return react.useMemo(
|
|
@@ -1079,7 +1114,12 @@ function CartProvider({
|
|
|
1079
1114
|
const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
|
|
1080
1115
|
ahooks.useRequest(
|
|
1081
1116
|
() => {
|
|
1082
|
-
const newAttributes = [...attributes
|
|
1117
|
+
const newAttributes = [...attributes];
|
|
1118
|
+
customAttributes.forEach((item) => {
|
|
1119
|
+
if (item.value && !newAttributes.some((attr) => attr.key === item.key)) {
|
|
1120
|
+
newAttributes.push(item);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1083
1123
|
const needUpdate = cart && checkAttributesUpdateNeeded(
|
|
1084
1124
|
cart.customAttributes,
|
|
1085
1125
|
newAttributes,
|