@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.
package/dist/index.mjs CHANGED
@@ -793,11 +793,23 @@ function useAddCartLines(options) {
793
793
  const { mutateCart, metafieldIdentifiers } = useCartContext();
794
794
  const addLines = useCallback(
795
795
  async (_key, { arg }) => {
796
- let updatedCart = await addCartLines(client, {
797
- ...arg,
798
- metafieldIdentifiers,
799
- cookieAdapter: cartCookieAdapter
800
- });
796
+ const { cartId, lines } = arg;
797
+ const id = cartId || cartCookieAdapter?.getCartId(locale);
798
+ let updatedCart;
799
+ if (!id) {
800
+ updatedCart = await createCart(client, {
801
+ lines,
802
+ metafieldIdentifiers,
803
+ cookieAdapter: cartCookieAdapter
804
+ });
805
+ } else {
806
+ updatedCart = await addCartLines(client, {
807
+ cartId: id,
808
+ lines,
809
+ metafieldIdentifiers,
810
+ cookieAdapter: cartCookieAdapter
811
+ });
812
+ }
801
813
  if (updatedCart) {
802
814
  const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
803
815
  if (unApplicableCodes.length > 0) {
@@ -1104,7 +1116,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
1104
1116
  const { trigger: applyCartCodes } = useApplyCartCodes();
1105
1117
  const { trigger: removeInvalidCodes } = useRemoveCartCodes();
1106
1118
  const { trigger: addCartLines2 } = useAddCartLines();
1107
- const { trigger: createCart3 } = useCreateCart();
1119
+ const { trigger: createCart4 } = useCreateCart();
1108
1120
  const addToCart = useCallback(
1109
1121
  async (_key, { arg }) => {
1110
1122
  const {
@@ -1139,7 +1151,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
1139
1151
  let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
1140
1152
  let resultCart = null;
1141
1153
  if (!cartId) {
1142
- resultCart = await createCart3({
1154
+ resultCart = await createCart4({
1143
1155
  lines,
1144
1156
  buyerIdentity,
1145
1157
  discountCodes,
@@ -1194,7 +1206,7 @@ function useAddToCart({ withTrack = true } = {}, swrOptions) {
1194
1206
  cart,
1195
1207
  withTrack,
1196
1208
  performanceAdapter,
1197
- createCart3,
1209
+ createCart4,
1198
1210
  addCartLines2,
1199
1211
  applyCartCodes,
1200
1212
  removeInvalidCodes,