@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.js
CHANGED
|
@@ -456,18 +456,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
456
456
|
}
|
|
457
457
|
return true;
|
|
458
458
|
}, [giftHandles]);
|
|
459
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
459
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
460
|
+
shouldFetch ? giftHandles : null,
|
|
461
|
+
async () => {
|
|
462
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
463
|
+
handles: giftHandles,
|
|
464
|
+
locale
|
|
465
|
+
});
|
|
466
|
+
const result = Array.isArray(res) ? res : [];
|
|
467
|
+
giftProductsCache.current = {
|
|
468
|
+
data: result,
|
|
469
|
+
giftHandles: [...giftHandles]
|
|
470
|
+
};
|
|
471
|
+
return result;
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
revalidateOnFocus: false
|
|
475
|
+
}
|
|
476
|
+
);
|
|
471
477
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
472
478
|
if (giftProductsCache.current && !shouldFetch) {
|
|
473
479
|
return giftProductsCache.current.data || void 0;
|
|
@@ -520,12 +526,14 @@ var useScriptAutoFreeGift = ({
|
|
|
520
526
|
upgrade_multiple2 = 1.2;
|
|
521
527
|
upgrade_value2 = 40;
|
|
522
528
|
}
|
|
523
|
-
effectiveCart?.lineItems?.forEach(
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
+
effectiveCart?.lineItems?.forEach(
|
|
530
|
+
({ customAttributes }) => {
|
|
531
|
+
customAttributes?.forEach(({ key, value }) => {
|
|
532
|
+
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
533
|
+
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
);
|
|
529
537
|
return [upgrade_multiple2, upgrade_value2];
|
|
530
538
|
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
531
539
|
const breakpoints = react.useMemo(() => {
|
|
@@ -590,18 +598,24 @@ var useScriptAutoFreeGift = ({
|
|
|
590
598
|
const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
|
|
591
599
|
return [currentLevel, nextLevel];
|
|
592
600
|
}, [breakpoints, involvedSubTotal, involvedLines.length]);
|
|
593
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
601
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
602
|
+
shouldFetch ? giftHandles : null,
|
|
603
|
+
async () => {
|
|
604
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
605
|
+
handles: giftHandles,
|
|
606
|
+
locale
|
|
607
|
+
});
|
|
608
|
+
const result = Array.isArray(res) ? res : [];
|
|
609
|
+
giftProductsCache.current = {
|
|
610
|
+
data: result,
|
|
611
|
+
giftHandles: [...giftHandles]
|
|
612
|
+
};
|
|
613
|
+
return result;
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
revalidateOnFocus: false
|
|
617
|
+
}
|
|
618
|
+
);
|
|
605
619
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
606
620
|
if (giftProductsCache.current && !shouldFetch) {
|
|
607
621
|
return giftProductsCache.current.data || void 0;
|
|
@@ -839,7 +853,7 @@ function useApplyCartCodes(options) {
|
|
|
839
853
|
if (!discountCodes?.length) {
|
|
840
854
|
throw new Error("Invalid input used for this operation: Miss discountCode");
|
|
841
855
|
}
|
|
842
|
-
const cartId = providedCartId
|
|
856
|
+
const cartId = providedCartId || cart?.id;
|
|
843
857
|
if (!cartId) {
|
|
844
858
|
return void 0;
|
|
845
859
|
}
|
|
@@ -867,7 +881,7 @@ function useRemoveCartCodes(options) {
|
|
|
867
881
|
const removeCodes = react.useCallback(
|
|
868
882
|
async (_key, { arg }) => {
|
|
869
883
|
const { cartId: providedCartId, discountCodes } = arg;
|
|
870
|
-
const cartId = providedCartId
|
|
884
|
+
const cartId = providedCartId || cart?.id;
|
|
871
885
|
const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
|
|
872
886
|
const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
|
|
873
887
|
const updatedCart = await shopifySdk.updateCartCodes(client, {
|
|
@@ -1666,8 +1680,9 @@ function useProductsByHandles(options = {}) {
|
|
|
1666
1680
|
metafieldIdentifiers
|
|
1667
1681
|
});
|
|
1668
1682
|
},
|
|
1669
|
-
|
|
1670
|
-
revalidateOnFocus: false
|
|
1683
|
+
{
|
|
1684
|
+
revalidateOnFocus: false,
|
|
1685
|
+
...swrOptions
|
|
1671
1686
|
}
|
|
1672
1687
|
);
|
|
1673
1688
|
}
|