@anker-in/shopify-react 0.1.1-beta.39 → 0.1.1-beta.40

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.
@@ -714,11 +714,23 @@ function useAddCartLines(options) {
714
714
  const { mutateCart, metafieldIdentifiers } = useCartContext();
715
715
  const addLines = useCallback(
716
716
  async (_key, { arg }) => {
717
- let updatedCart = await addCartLines(client, {
718
- ...arg,
719
- metafieldIdentifiers,
720
- cookieAdapter: cartCookieAdapter
721
- });
717
+ const { cartId, lines } = arg;
718
+ const id = cartId || cartCookieAdapter?.getCartId(locale);
719
+ let updatedCart;
720
+ if (!id) {
721
+ updatedCart = await createCart(client, {
722
+ lines,
723
+ metafieldIdentifiers,
724
+ cookieAdapter: cartCookieAdapter
725
+ });
726
+ } else {
727
+ updatedCart = await addCartLines(client, {
728
+ cartId: id,
729
+ lines,
730
+ metafieldIdentifiers,
731
+ cookieAdapter: cartCookieAdapter
732
+ });
733
+ }
722
734
  if (updatedCart) {
723
735
  const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
724
736
  if (unApplicableCodes.length > 0) {
@@ -990,7 +1002,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
990
1002
  const { trigger: applyCartCodes } = useApplyCartCodes();
991
1003
  const { trigger: removeInvalidCodes } = useRemoveCartCodes();
992
1004
  const { trigger: addCartLines2 } = useAddCartLines();
993
- const { trigger: createCart3 } = useCreateCart();
1005
+ const { trigger: createCart4 } = useCreateCart();
994
1006
  const addToCart = useCallback(
995
1007
  async (_key, { arg }) => {
996
1008
  const {
@@ -1025,7 +1037,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
1025
1037
  let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
1026
1038
  let resultCart = null;
1027
1039
  if (!cartId) {
1028
- resultCart = await createCart3({
1040
+ resultCart = await createCart4({
1029
1041
  lines,
1030
1042
  buyerIdentity,
1031
1043
  discountCodes,
@@ -1080,7 +1092,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
1080
1092
  cart,
1081
1093
  withTrack,
1082
1094
  performanceAdapter,
1083
- createCart3,
1095
+ createCart4,
1084
1096
  addCartLines2,
1085
1097
  applyCartCodes,
1086
1098
  removeInvalidCodes,