@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/index.js
CHANGED
|
@@ -527,18 +527,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
527
527
|
}
|
|
528
528
|
return true;
|
|
529
529
|
}, [giftHandles]);
|
|
530
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
530
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
531
|
+
shouldFetch ? giftHandles : null,
|
|
532
|
+
async () => {
|
|
533
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
534
|
+
handles: giftHandles,
|
|
535
|
+
locale
|
|
536
|
+
});
|
|
537
|
+
const result = Array.isArray(res) ? res : [];
|
|
538
|
+
giftProductsCache.current = {
|
|
539
|
+
data: result,
|
|
540
|
+
giftHandles: [...giftHandles]
|
|
541
|
+
};
|
|
542
|
+
return result;
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
revalidateOnFocus: false
|
|
546
|
+
}
|
|
547
|
+
);
|
|
542
548
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
543
549
|
if (giftProductsCache.current && !shouldFetch) {
|
|
544
550
|
return giftProductsCache.current.data || void 0;
|
|
@@ -591,12 +597,14 @@ var useScriptAutoFreeGift = ({
|
|
|
591
597
|
upgrade_multiple2 = 1.2;
|
|
592
598
|
upgrade_value2 = 40;
|
|
593
599
|
}
|
|
594
|
-
effectiveCart?.lineItems?.forEach(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
effectiveCart?.lineItems?.forEach(
|
|
601
|
+
({ customAttributes }) => {
|
|
602
|
+
customAttributes?.forEach(({ key, value }) => {
|
|
603
|
+
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
604
|
+
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
);
|
|
600
608
|
return [upgrade_multiple2, upgrade_value2];
|
|
601
609
|
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
602
610
|
const breakpoints = react.useMemo(() => {
|
|
@@ -661,18 +669,24 @@ var useScriptAutoFreeGift = ({
|
|
|
661
669
|
const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
|
|
662
670
|
return [currentLevel, nextLevel];
|
|
663
671
|
}, [breakpoints, involvedSubTotal, involvedLines.length]);
|
|
664
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
672
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
673
|
+
shouldFetch ? giftHandles : null,
|
|
674
|
+
async () => {
|
|
675
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
676
|
+
handles: giftHandles,
|
|
677
|
+
locale
|
|
678
|
+
});
|
|
679
|
+
const result = Array.isArray(res) ? res : [];
|
|
680
|
+
giftProductsCache.current = {
|
|
681
|
+
data: result,
|
|
682
|
+
giftHandles: [...giftHandles]
|
|
683
|
+
};
|
|
684
|
+
return result;
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
revalidateOnFocus: false
|
|
688
|
+
}
|
|
689
|
+
);
|
|
676
690
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
677
691
|
if (giftProductsCache.current && !shouldFetch) {
|
|
678
692
|
return giftProductsCache.current.data || void 0;
|
|
@@ -935,7 +949,7 @@ function useApplyCartCodes(options) {
|
|
|
935
949
|
if (!discountCodes?.length) {
|
|
936
950
|
throw new Error("Invalid input used for this operation: Miss discountCode");
|
|
937
951
|
}
|
|
938
|
-
const cartId = providedCartId
|
|
952
|
+
const cartId = providedCartId || cart?.id;
|
|
939
953
|
if (!cartId) {
|
|
940
954
|
return void 0;
|
|
941
955
|
}
|
|
@@ -963,7 +977,7 @@ function useRemoveCartCodes(options) {
|
|
|
963
977
|
const removeCodes = react.useCallback(
|
|
964
978
|
async (_key, { arg }) => {
|
|
965
979
|
const { cartId: providedCartId, discountCodes } = arg;
|
|
966
|
-
const cartId = providedCartId
|
|
980
|
+
const cartId = providedCartId || cart?.id;
|
|
967
981
|
const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
|
|
968
982
|
const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
|
|
969
983
|
const updatedCart = await shopifySdk.updateCartCodes(client, {
|
|
@@ -1514,8 +1528,29 @@ var useCartAttributes = ({
|
|
|
1514
1528
|
[memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
|
|
1515
1529
|
);
|
|
1516
1530
|
const extraAttributesInCart = react.useMemo(() => {
|
|
1531
|
+
const commonAttributeKeys = [
|
|
1532
|
+
// member attributes
|
|
1533
|
+
"_token",
|
|
1534
|
+
"_member_type",
|
|
1535
|
+
"_user_type",
|
|
1536
|
+
"_is_login",
|
|
1537
|
+
"_login_user",
|
|
1538
|
+
// function attributes
|
|
1539
|
+
"_discounts_function_env",
|
|
1540
|
+
// presell attributes
|
|
1541
|
+
"_presale",
|
|
1542
|
+
// weight attributes
|
|
1543
|
+
"_weight",
|
|
1544
|
+
"_app_source_name",
|
|
1545
|
+
// tracking attributes
|
|
1546
|
+
"utm_params",
|
|
1547
|
+
// referral attributes
|
|
1548
|
+
"_invite_code",
|
|
1549
|
+
"_play_mode_id",
|
|
1550
|
+
"_popup"
|
|
1551
|
+
];
|
|
1517
1552
|
return cart?.customAttributes?.filter(
|
|
1518
|
-
(item) => !
|
|
1553
|
+
(item) => !commonAttributeKeys.includes(item.key)
|
|
1519
1554
|
) || [];
|
|
1520
1555
|
}, [cart]);
|
|
1521
1556
|
return react.useMemo(
|
|
@@ -1741,8 +1776,9 @@ function useProductsByHandles(options = {}) {
|
|
|
1741
1776
|
metafieldIdentifiers
|
|
1742
1777
|
});
|
|
1743
1778
|
},
|
|
1744
|
-
|
|
1745
|
-
revalidateOnFocus: false
|
|
1779
|
+
{
|
|
1780
|
+
revalidateOnFocus: false,
|
|
1781
|
+
...swrOptions
|
|
1746
1782
|
}
|
|
1747
1783
|
);
|
|
1748
1784
|
}
|
|
@@ -3143,7 +3179,12 @@ function CartProvider({
|
|
|
3143
3179
|
const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
|
|
3144
3180
|
ahooks.useRequest(
|
|
3145
3181
|
() => {
|
|
3146
|
-
const newAttributes = [...attributes
|
|
3182
|
+
const newAttributes = [...attributes];
|
|
3183
|
+
customAttributes.forEach((item) => {
|
|
3184
|
+
if (item.value && !newAttributes.some((attr) => attr.key === item.key)) {
|
|
3185
|
+
newAttributes.push(item);
|
|
3186
|
+
}
|
|
3187
|
+
});
|
|
3147
3188
|
const needUpdate = cart && checkAttributesUpdateNeeded(
|
|
3148
3189
|
cart.customAttributes,
|
|
3149
3190
|
newAttributes,
|