@anker-in/shopify-react 0.1.1-beta.18 → 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 +49 -34
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +49 -34
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +55 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -35
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +50 -31
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +50 -31
- 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, {
|
|
@@ -1762,8 +1776,9 @@ function useProductsByHandles(options = {}) {
|
|
|
1762
1776
|
metafieldIdentifiers
|
|
1763
1777
|
});
|
|
1764
1778
|
},
|
|
1765
|
-
|
|
1766
|
-
revalidateOnFocus: false
|
|
1779
|
+
{
|
|
1780
|
+
revalidateOnFocus: false,
|
|
1781
|
+
...swrOptions
|
|
1767
1782
|
}
|
|
1768
1783
|
);
|
|
1769
1784
|
}
|
|
@@ -3164,7 +3179,12 @@ function CartProvider({
|
|
|
3164
3179
|
const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
|
|
3165
3180
|
ahooks.useRequest(
|
|
3166
3181
|
() => {
|
|
3167
|
-
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
|
+
});
|
|
3168
3188
|
const needUpdate = cart && checkAttributesUpdateNeeded(
|
|
3169
3189
|
cart.customAttributes,
|
|
3170
3190
|
newAttributes,
|