@ikas/storefront 0.1.22-alpha.1 → 0.1.22-alpha.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.
package/build/index.es.js CHANGED
@@ -23142,23 +23142,46 @@ var IkasCartStore = /** @class */ (function () {
23142
23142
  }
23143
23143
  });
23144
23144
  }); };
23145
+ this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
23146
+ var cartId;
23147
+ return __generator(this, function (_a) {
23148
+ switch (_a.label) {
23149
+ case 0:
23150
+ cartId = localStorage.getItem(CART_LS_KEY);
23151
+ if (!(this.cart && !cartId)) return [3 /*break*/, 1];
23152
+ this.removeCart();
23153
+ return [3 /*break*/, 3];
23154
+ case 1:
23155
+ if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
23156
+ return [4 /*yield*/, this.getCart()];
23157
+ case 2:
23158
+ _a.sent();
23159
+ _a.label = 3;
23160
+ case 3: return [2 /*return*/];
23161
+ }
23162
+ });
23163
+ }); };
23145
23164
  this.addItem = function (variant, product, initialQuantity) {
23146
23165
  if (initialQuantity === void 0) { initialQuantity = 1; }
23147
23166
  return __awaiter(_this, void 0, void 0, function () {
23148
- var existingItem, input, cart, eventId, item, err_2;
23167
+ var existingItem, cartId, input, cart, eventId, item, err_2;
23149
23168
  var _a, _b, _c;
23150
23169
  return __generator(this, function (_d) {
23151
23170
  switch (_d.label) {
23152
23171
  case 0:
23153
- _d.trys.push([0, 4, , 5]);
23172
+ _d.trys.push([0, 5, , 6]);
23173
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
23174
+ case 1:
23175
+ _d.sent();
23154
23176
  if (this.cart) {
23155
23177
  existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
23156
23178
  if (existingItem) {
23157
23179
  return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
23158
23180
  }
23159
23181
  }
23182
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
23160
23183
  input = {
23161
- cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23184
+ cartId: cartId,
23162
23185
  customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
23163
23186
  null,
23164
23187
  item: {
@@ -23176,14 +23199,14 @@ var IkasCartStore = /** @class */ (function () {
23176
23199
  storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23177
23200
  };
23178
23201
  return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23179
- case 1:
23202
+ case 2:
23180
23203
  cart = _d.sent();
23181
- if (!cart) return [3 /*break*/, 3];
23204
+ if (!cart) return [3 /*break*/, 4];
23182
23205
  return [4 /*yield*/, this.setCart(cart)];
23183
- case 2:
23184
- _d.sent();
23185
- _d.label = 3;
23186
23206
  case 3:
23207
+ _d.sent();
23208
+ _d.label = 4;
23209
+ case 4:
23187
23210
  if (this.cart) {
23188
23211
  eventId = this.cart.id + "-" + this.cart.updatedAt;
23189
23212
  item = this.cart.items.find(function (i) { return i.variant.id; });
@@ -23191,12 +23214,12 @@ var IkasCartStore = /** @class */ (function () {
23191
23214
  Analytics.addToCart(item, initialQuantity, eventId, this.cart);
23192
23215
  }
23193
23216
  }
23194
- return [3 /*break*/, 5];
23195
- case 4:
23217
+ return [3 /*break*/, 6];
23218
+ case 5:
23196
23219
  err_2 = _d.sent();
23197
23220
  console.log(err_2);
23198
- return [3 /*break*/, 5];
23199
- case 5: return [2 /*return*/];
23221
+ return [3 /*break*/, 6];
23222
+ case 6: return [2 /*return*/];
23200
23223
  }
23201
23224
  });
23202
23225
  });
@@ -23207,7 +23230,10 @@ var IkasCartStore = /** @class */ (function () {
23207
23230
  return __generator(this, function (_d) {
23208
23231
  switch (_d.label) {
23209
23232
  case 0:
23210
- _d.trys.push([0, 4, , 5]);
23233
+ _d.trys.push([0, 5, , 6]);
23234
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
23235
+ case 1:
23236
+ _d.sent();
23211
23237
  input = {
23212
23238
  cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23213
23239
  customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
@@ -23227,14 +23253,14 @@ var IkasCartStore = /** @class */ (function () {
23227
23253
  storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23228
23254
  };
23229
23255
  return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23230
- case 1:
23256
+ case 2:
23231
23257
  cart = _d.sent();
23232
- if (!cart) return [3 /*break*/, 3];
23258
+ if (!cart) return [3 /*break*/, 4];
23233
23259
  return [4 /*yield*/, this.setCart(cart)];
23234
- case 2:
23235
- _d.sent();
23236
- _d.label = 3;
23237
23260
  case 3:
23261
+ _d.sent();
23262
+ _d.label = 4;
23263
+ case 4:
23238
23264
  this.removeCardIfEmpty();
23239
23265
  if (this.cart) {
23240
23266
  eventId = this.cart.id + "-" + this.cart.updatedAt;
@@ -23246,12 +23272,12 @@ var IkasCartStore = /** @class */ (function () {
23246
23272
  Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
23247
23273
  }
23248
23274
  }
23249
- return [3 /*break*/, 5];
23250
- case 4:
23275
+ return [3 /*break*/, 6];
23276
+ case 5:
23251
23277
  err_3 = _d.sent();
23252
23278
  console.log(err_3);
23253
- return [3 /*break*/, 5];
23254
- case 5: return [2 /*return*/];
23279
+ return [3 /*break*/, 6];
23280
+ case 6: return [2 /*return*/];
23255
23281
  }
23256
23282
  });
23257
23283
  }); };
package/build/index.js CHANGED
@@ -23149,23 +23149,46 @@ var IkasCartStore = /** @class */ (function () {
23149
23149
  }
23150
23150
  });
23151
23151
  }); };
23152
+ this.beforeCartOperationCheck = function () { return __awaiter(_this, void 0, void 0, function () {
23153
+ var cartId;
23154
+ return __generator(this, function (_a) {
23155
+ switch (_a.label) {
23156
+ case 0:
23157
+ cartId = localStorage.getItem(CART_LS_KEY);
23158
+ if (!(this.cart && !cartId)) return [3 /*break*/, 1];
23159
+ this.removeCart();
23160
+ return [3 /*break*/, 3];
23161
+ case 1:
23162
+ if (!(!this.cart && !!cartId)) return [3 /*break*/, 3];
23163
+ return [4 /*yield*/, this.getCart()];
23164
+ case 2:
23165
+ _a.sent();
23166
+ _a.label = 3;
23167
+ case 3: return [2 /*return*/];
23168
+ }
23169
+ });
23170
+ }); };
23152
23171
  this.addItem = function (variant, product, initialQuantity) {
23153
23172
  if (initialQuantity === void 0) { initialQuantity = 1; }
23154
23173
  return __awaiter(_this, void 0, void 0, function () {
23155
- var existingItem, input, cart, eventId, item, err_2;
23174
+ var existingItem, cartId, input, cart, eventId, item, err_2;
23156
23175
  var _a, _b, _c;
23157
23176
  return __generator(this, function (_d) {
23158
23177
  switch (_d.label) {
23159
23178
  case 0:
23160
- _d.trys.push([0, 4, , 5]);
23179
+ _d.trys.push([0, 5, , 6]);
23180
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
23181
+ case 1:
23182
+ _d.sent();
23161
23183
  if (this.cart) {
23162
23184
  existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
23163
23185
  if (existingItem) {
23164
23186
  return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
23165
23187
  }
23166
23188
  }
23189
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
23167
23190
  input = {
23168
- cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23191
+ cartId: cartId,
23169
23192
  customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
23170
23193
  null,
23171
23194
  item: {
@@ -23183,14 +23206,14 @@ var IkasCartStore = /** @class */ (function () {
23183
23206
  storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23184
23207
  };
23185
23208
  return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23186
- case 1:
23209
+ case 2:
23187
23210
  cart = _d.sent();
23188
- if (!cart) return [3 /*break*/, 3];
23211
+ if (!cart) return [3 /*break*/, 4];
23189
23212
  return [4 /*yield*/, this.setCart(cart)];
23190
- case 2:
23191
- _d.sent();
23192
- _d.label = 3;
23193
23213
  case 3:
23214
+ _d.sent();
23215
+ _d.label = 4;
23216
+ case 4:
23194
23217
  if (this.cart) {
23195
23218
  eventId = this.cart.id + "-" + this.cart.updatedAt;
23196
23219
  item = this.cart.items.find(function (i) { return i.variant.id; });
@@ -23198,12 +23221,12 @@ var IkasCartStore = /** @class */ (function () {
23198
23221
  Analytics.addToCart(item, initialQuantity, eventId, this.cart);
23199
23222
  }
23200
23223
  }
23201
- return [3 /*break*/, 5];
23202
- case 4:
23224
+ return [3 /*break*/, 6];
23225
+ case 5:
23203
23226
  err_2 = _d.sent();
23204
23227
  console.log(err_2);
23205
- return [3 /*break*/, 5];
23206
- case 5: return [2 /*return*/];
23228
+ return [3 /*break*/, 6];
23229
+ case 6: return [2 /*return*/];
23207
23230
  }
23208
23231
  });
23209
23232
  });
@@ -23214,7 +23237,10 @@ var IkasCartStore = /** @class */ (function () {
23214
23237
  return __generator(this, function (_d) {
23215
23238
  switch (_d.label) {
23216
23239
  case 0:
23217
- _d.trys.push([0, 4, , 5]);
23240
+ _d.trys.push([0, 5, , 6]);
23241
+ return [4 /*yield*/, this.beforeCartOperationCheck()];
23242
+ case 1:
23243
+ _d.sent();
23218
23244
  input = {
23219
23245
  cartId: ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || null,
23220
23246
  customerId: ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.customerId) || ((_c = this.baseStore.customerStore.customer) === null || _c === void 0 ? void 0 : _c.id) ||
@@ -23234,14 +23260,14 @@ var IkasCartStore = /** @class */ (function () {
23234
23260
  storefrontThemeId: IkasStorefrontConfig.storefrontThemeId,
23235
23261
  };
23236
23262
  return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
23237
- case 1:
23263
+ case 2:
23238
23264
  cart = _d.sent();
23239
- if (!cart) return [3 /*break*/, 3];
23265
+ if (!cart) return [3 /*break*/, 4];
23240
23266
  return [4 /*yield*/, this.setCart(cart)];
23241
- case 2:
23242
- _d.sent();
23243
- _d.label = 3;
23244
23267
  case 3:
23268
+ _d.sent();
23269
+ _d.label = 4;
23270
+ case 4:
23245
23271
  this.removeCardIfEmpty();
23246
23272
  if (this.cart) {
23247
23273
  eventId = this.cart.id + "-" + this.cart.updatedAt;
@@ -23253,12 +23279,12 @@ var IkasCartStore = /** @class */ (function () {
23253
23279
  Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
23254
23280
  }
23255
23281
  }
23256
- return [3 /*break*/, 5];
23257
- case 4:
23282
+ return [3 /*break*/, 6];
23283
+ case 5:
23258
23284
  err_3 = _d.sent();
23259
23285
  console.log(err_3);
23260
- return [3 /*break*/, 5];
23261
- case 5: return [2 /*return*/];
23286
+ return [3 /*break*/, 6];
23287
+ case 6: return [2 /*return*/];
23262
23288
  }
23263
23289
  });
23264
23290
  }); };
@@ -17,6 +17,7 @@ export declare class IkasCartStore {
17
17
  get checkoutUrl(): string | undefined;
18
18
  private getCart;
19
19
  private setCart;
20
+ private beforeCartOperationCheck;
20
21
  addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number) => Promise<void>;
21
22
  changeItemQuantity: (item: IkasOrderLineItem, quantity: number) => Promise<void>;
22
23
  removeItem: (item: IkasOrderLineItem) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "0.1.22-alpha.1",
3
+ "version": "0.1.22-alpha.2",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.es.js",
6
6
  "author": "Umut Ozan Yıldırım",