@anker-in/shopify-react 1.0.0 → 1.0.1-beta.2

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.
@@ -67,6 +67,7 @@ interface AddCartLinesInput {
67
67
  cartId?: string;
68
68
  /** Lines to add */
69
69
  lines: CartLineInput[];
70
+ updateCookie?: boolean;
70
71
  }
71
72
  /**
72
73
  * Hook for adding lines to cart
@@ -67,6 +67,7 @@ interface AddCartLinesInput {
67
67
  cartId?: string;
68
68
  /** Lines to add */
69
69
  lines: CartLineInput[];
70
+ updateCookie?: boolean;
70
71
  }
71
72
  /**
72
73
  * Hook for adding lines to cart
@@ -722,14 +722,15 @@ function useAddCartLines(options) {
722
722
  const { mutateCart, metafieldIdentifiers } = useCartContext();
723
723
  const addLines = react.useCallback(
724
724
  async (_key, { arg }) => {
725
- const { cartId, lines } = arg;
725
+ const { cartId, lines, updateCookie = true } = arg;
726
726
  const id = cartId || cartCookieAdapter?.getCartId(locale);
727
727
  let updatedCart;
728
728
  if (!id) {
729
729
  updatedCart = await shopifySdk.createCart(client, {
730
730
  lines,
731
731
  metafieldIdentifiers,
732
- cookieAdapter: cartCookieAdapter
732
+ cookieAdapter: cartCookieAdapter,
733
+ updateCookie
733
734
  });
734
735
  } else {
735
736
  updatedCart = await shopifySdk.addCartLines(client, {
@@ -891,14 +892,10 @@ function useApplyCartCodes(options) {
891
892
  const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
892
893
  const applyCodes = react.useCallback(
893
894
  async (_key, { arg }) => {
894
- const { cartId: providedCartId, discountCodes, replaceExistingCodes } = arg;
895
+ const { cartId, discountCodes, replaceExistingCodes } = arg;
895
896
  if (!discountCodes?.length) {
896
897
  throw new Error("Invalid input used for this operation: Miss discountCode");
897
898
  }
898
- const cartId = providedCartId || cart?.id;
899
- if (!cartId) {
900
- return void 0;
901
- }
902
899
  const updatedCart = await shopifySdk.updateCartCodes(client, {
903
900
  cartId,
904
901
  discountCodes: replaceExistingCodes ? discountCodes : [
@@ -928,8 +925,7 @@ function useRemoveCartCodes(options) {
928
925
  const { mutateCart, cart, metafieldIdentifiers } = useCartContext();
929
926
  const removeCodes = react.useCallback(
930
927
  async (_key, { arg }) => {
931
- const { cartId: providedCartId, discountCodes } = arg;
932
- const cartId = providedCartId || cart?.id;
928
+ const { cartId, discountCodes } = arg;
933
929
  const codes = cart?.discountCodes?.filter((code) => !!code.applicable) || [];
934
930
  const leftCodes = codes.filter((code) => discountCodes?.length ? !discountCodes.includes(code.code) : code.code).map((code) => code.code);
935
931
  const updatedCart = await shopifySdk.updateCartCodes(client, {