@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/hooks/index.mjs
CHANGED
|
@@ -447,18 +447,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
447
447
|
}
|
|
448
448
|
return true;
|
|
449
449
|
}, [giftHandles]);
|
|
450
|
-
const { data: giftProductsResult } = useSWR(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
450
|
+
const { data: giftProductsResult } = useSWR(
|
|
451
|
+
shouldFetch ? giftHandles : null,
|
|
452
|
+
async () => {
|
|
453
|
+
const res = await getProductsByHandles(client, {
|
|
454
|
+
handles: giftHandles,
|
|
455
|
+
locale
|
|
456
|
+
});
|
|
457
|
+
const result = Array.isArray(res) ? res : [];
|
|
458
|
+
giftProductsCache.current = {
|
|
459
|
+
data: result,
|
|
460
|
+
giftHandles: [...giftHandles]
|
|
461
|
+
};
|
|
462
|
+
return result;
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
revalidateOnFocus: false
|
|
466
|
+
}
|
|
467
|
+
);
|
|
462
468
|
const finalGiftProductsResult = useMemo(() => {
|
|
463
469
|
if (giftProductsCache.current && !shouldFetch) {
|
|
464
470
|
return giftProductsCache.current.data || void 0;
|
|
@@ -511,12 +517,14 @@ var useScriptAutoFreeGift = ({
|
|
|
511
517
|
upgrade_multiple2 = 1.2;
|
|
512
518
|
upgrade_value2 = 40;
|
|
513
519
|
}
|
|
514
|
-
effectiveCart?.lineItems?.forEach(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
+
effectiveCart?.lineItems?.forEach(
|
|
521
|
+
({ customAttributes }) => {
|
|
522
|
+
customAttributes?.forEach(({ key, value }) => {
|
|
523
|
+
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
524
|
+
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
);
|
|
520
528
|
return [upgrade_multiple2, upgrade_value2];
|
|
521
529
|
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
522
530
|
const breakpoints = useMemo(() => {
|
|
@@ -581,18 +589,24 @@ var useScriptAutoFreeGift = ({
|
|
|
581
589
|
const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
|
|
582
590
|
return [currentLevel, nextLevel];
|
|
583
591
|
}, [breakpoints, involvedSubTotal, involvedLines.length]);
|
|
584
|
-
const { data: giftProductsResult } = useSWR(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
592
|
+
const { data: giftProductsResult } = useSWR(
|
|
593
|
+
shouldFetch ? giftHandles : null,
|
|
594
|
+
async () => {
|
|
595
|
+
const res = await getProductsByHandles(client, {
|
|
596
|
+
handles: giftHandles,
|
|
597
|
+
locale
|
|
598
|
+
});
|
|
599
|
+
const result = Array.isArray(res) ? res : [];
|
|
600
|
+
giftProductsCache.current = {
|
|
601
|
+
data: result,
|
|
602
|
+
giftHandles: [...giftHandles]
|
|
603
|
+
};
|
|
604
|
+
return result;
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
revalidateOnFocus: false
|
|
608
|
+
}
|
|
609
|
+
);
|
|
596
610
|
const finalGiftProductsResult = useMemo(() => {
|
|
597
611
|
if (giftProductsCache.current && !shouldFetch) {
|
|
598
612
|
return giftProductsCache.current.data || void 0;
|
|
@@ -830,7 +844,7 @@ function useApplyCartCodes(options) {
|
|
|
830
844
|
if (!discountCodes?.length) {
|
|
831
845
|
throw new Error("Invalid input used for this operation: Miss discountCode");
|
|
832
846
|
}
|
|
833
|
-
const cartId = providedCartId
|
|
847
|
+
const cartId = providedCartId || cart?.id;
|
|
834
848
|
if (!cartId) {
|
|
835
849
|
return void 0;
|
|
836
850
|
}
|
|
@@ -858,7 +872,7 @@ function useRemoveCartCodes(options) {
|
|
|
858
872
|
const removeCodes = useCallback(
|
|
859
873
|
async (_key, { arg }) => {
|
|
860
874
|
const { cartId: providedCartId, discountCodes } = arg;
|
|
861
|
-
const cartId = providedCartId
|
|
875
|
+
const cartId = providedCartId || cart?.id;
|
|
862
876
|
const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
|
|
863
877
|
const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
|
|
864
878
|
const updatedCart = await updateCartCodes(client, {
|
|
@@ -1657,8 +1671,9 @@ function useProductsByHandles(options = {}) {
|
|
|
1657
1671
|
metafieldIdentifiers
|
|
1658
1672
|
});
|
|
1659
1673
|
},
|
|
1660
|
-
|
|
1661
|
-
revalidateOnFocus: false
|
|
1674
|
+
{
|
|
1675
|
+
revalidateOnFocus: false,
|
|
1676
|
+
...swrOptions
|
|
1662
1677
|
}
|
|
1663
1678
|
);
|
|
1664
1679
|
}
|