@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/index.mjs CHANGED
@@ -519,18 +519,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
519
519
  }
520
520
  return true;
521
521
  }, [giftHandles]);
522
- const { data: giftProductsResult } = useSWR(shouldFetch ? giftHandles : null, async () => {
523
- const res = await getProductsByHandles(client, {
524
- handles: giftHandles,
525
- locale
526
- });
527
- const result = Array.isArray(res) ? res : [];
528
- giftProductsCache.current = {
529
- data: result,
530
- giftHandles: [...giftHandles]
531
- };
532
- return result;
533
- });
522
+ const { data: giftProductsResult } = useSWR(
523
+ shouldFetch ? giftHandles : null,
524
+ async () => {
525
+ const res = await getProductsByHandles(client, {
526
+ handles: giftHandles,
527
+ locale
528
+ });
529
+ const result = Array.isArray(res) ? res : [];
530
+ giftProductsCache.current = {
531
+ data: result,
532
+ giftHandles: [...giftHandles]
533
+ };
534
+ return result;
535
+ },
536
+ {
537
+ revalidateOnFocus: false
538
+ }
539
+ );
534
540
  const finalGiftProductsResult = useMemo(() => {
535
541
  if (giftProductsCache.current && !shouldFetch) {
536
542
  return giftProductsCache.current.data || void 0;
@@ -583,12 +589,14 @@ var useScriptAutoFreeGift = ({
583
589
  upgrade_multiple2 = 1.2;
584
590
  upgrade_value2 = 40;
585
591
  }
586
- effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
587
- customAttributes?.forEach(({ key, value }) => {
588
- if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
589
- if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
590
- });
591
- });
592
+ effectiveCart?.lineItems?.forEach(
593
+ ({ customAttributes }) => {
594
+ customAttributes?.forEach(({ key, value }) => {
595
+ if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
596
+ if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
597
+ });
598
+ }
599
+ );
592
600
  return [upgrade_multiple2, upgrade_value2];
593
601
  }, [effectiveCart?.lineItems, points_subscribe]);
594
602
  const breakpoints = useMemo(() => {
@@ -653,18 +661,24 @@ var useScriptAutoFreeGift = ({
653
661
  const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
654
662
  return [currentLevel, nextLevel];
655
663
  }, [breakpoints, involvedSubTotal, involvedLines.length]);
656
- const { data: giftProductsResult } = useSWR(shouldFetch ? giftHandles : null, async () => {
657
- const res = await getProductsByHandles(client, {
658
- handles: giftHandles,
659
- locale
660
- });
661
- const result = Array.isArray(res) ? res : [];
662
- giftProductsCache.current = {
663
- data: result,
664
- giftHandles: [...giftHandles]
665
- };
666
- return result;
667
- });
664
+ const { data: giftProductsResult } = useSWR(
665
+ shouldFetch ? giftHandles : null,
666
+ async () => {
667
+ const res = await getProductsByHandles(client, {
668
+ handles: giftHandles,
669
+ locale
670
+ });
671
+ const result = Array.isArray(res) ? res : [];
672
+ giftProductsCache.current = {
673
+ data: result,
674
+ giftHandles: [...giftHandles]
675
+ };
676
+ return result;
677
+ },
678
+ {
679
+ revalidateOnFocus: false
680
+ }
681
+ );
668
682
  const finalGiftProductsResult = useMemo(() => {
669
683
  if (giftProductsCache.current && !shouldFetch) {
670
684
  return giftProductsCache.current.data || void 0;
@@ -927,7 +941,7 @@ function useApplyCartCodes(options) {
927
941
  if (!discountCodes?.length) {
928
942
  throw new Error("Invalid input used for this operation: Miss discountCode");
929
943
  }
930
- const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
944
+ const cartId = providedCartId || cart?.id;
931
945
  if (!cartId) {
932
946
  return void 0;
933
947
  }
@@ -955,7 +969,7 @@ function useRemoveCartCodes(options) {
955
969
  const removeCodes = useCallback(
956
970
  async (_key, { arg }) => {
957
971
  const { cartId: providedCartId, discountCodes } = arg;
958
- const cartId = providedCartId ? void 0 : providedCartId || cart?.id;
972
+ const cartId = providedCartId || cart?.id;
959
973
  const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
960
974
  const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
961
975
  const updatedCart = await updateCartCodes(client, {
@@ -1754,8 +1768,9 @@ function useProductsByHandles(options = {}) {
1754
1768
  metafieldIdentifiers
1755
1769
  });
1756
1770
  },
1757
- swrOptions || {
1758
- revalidateOnFocus: false
1771
+ {
1772
+ revalidateOnFocus: false,
1773
+ ...swrOptions
1759
1774
  }
1760
1775
  );
1761
1776
  }
@@ -3156,7 +3171,12 @@ function CartProvider({
3156
3171
  const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
3157
3172
  useRequest(
3158
3173
  () => {
3159
- const newAttributes = [...attributes, ...customAttributes];
3174
+ const newAttributes = [...attributes];
3175
+ customAttributes.forEach((item) => {
3176
+ if (item.value && !newAttributes.some((attr) => attr.key === item.key)) {
3177
+ newAttributes.push(item);
3178
+ }
3179
+ });
3160
3180
  const needUpdate = cart && checkAttributesUpdateNeeded(
3161
3181
  cart.customAttributes,
3162
3182
  newAttributes,