@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/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, {
@@ -1506,8 +1520,29 @@ var useCartAttributes = ({
1506
1520
  [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
1507
1521
  );
1508
1522
  const extraAttributesInCart = useMemo(() => {
1523
+ const commonAttributeKeys = [
1524
+ // member attributes
1525
+ "_token",
1526
+ "_member_type",
1527
+ "_user_type",
1528
+ "_is_login",
1529
+ "_login_user",
1530
+ // function attributes
1531
+ "_discounts_function_env",
1532
+ // presell attributes
1533
+ "_presale",
1534
+ // weight attributes
1535
+ "_weight",
1536
+ "_app_source_name",
1537
+ // tracking attributes
1538
+ "utm_params",
1539
+ // referral attributes
1540
+ "_invite_code",
1541
+ "_play_mode_id",
1542
+ "_popup"
1543
+ ];
1509
1544
  return cart?.customAttributes?.filter(
1510
- (item) => !commonAttributes.some((attr) => attr.key === item.key)
1545
+ (item) => !commonAttributeKeys.includes(item.key)
1511
1546
  ) || [];
1512
1547
  }, [cart]);
1513
1548
  return useMemo(
@@ -1733,8 +1768,9 @@ function useProductsByHandles(options = {}) {
1733
1768
  metafieldIdentifiers
1734
1769
  });
1735
1770
  },
1736
- swrOptions || {
1737
- revalidateOnFocus: false
1771
+ {
1772
+ revalidateOnFocus: false,
1773
+ ...swrOptions
1738
1774
  }
1739
1775
  );
1740
1776
  }
@@ -3135,7 +3171,12 @@ function CartProvider({
3135
3171
  const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
3136
3172
  useRequest(
3137
3173
  () => {
3138
- 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
+ });
3139
3180
  const needUpdate = cart && checkAttributesUpdateNeeded(
3140
3181
  cart.customAttributes,
3141
3182
  newAttributes,