@ikas/storefront 0.1.21 → 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.
@@ -0,0 +1,11 @@
1
+ export interface addCouponCodeToCheckout_addCouponCodeToCheckout {
2
+ __typename: "Checkout";
3
+ id: string;
4
+ }
5
+ export interface addCouponCodeToCheckout {
6
+ addCouponCodeToCheckout: addCouponCodeToCheckout_addCouponCodeToCheckout;
7
+ }
8
+ export interface addCouponCodeToCheckoutVariables {
9
+ checkoutId: string;
10
+ couponCode: string;
11
+ }
@@ -14,6 +14,7 @@ export declare class IkasCheckoutAPI {
14
14
  static retrieveInstallmentInfo(input: IkasInstallmentInfoInput): Promise<IkasInstallmentInfo | undefined>;
15
15
  static checkStocks(lines: CheckStocksLineInput[], stockLocationIdList: string[]): Promise<CheckStocksTypes.checkStocks_checkStocks | undefined>;
16
16
  static listCheckoutSettings(): Promise<IkasCheckoutSettings[] | undefined>;
17
+ static addCouponCodeToCheckout(checkoutId: string, couponCode: string): Promise<true | undefined>;
17
18
  }
18
19
  declare type CheckStocksLineInput = {
19
20
  quantity: number;
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
  }); };
@@ -23843,26 +23869,32 @@ var CheckoutViewModel = /** @class */ (function () {
23843
23869
  });
23844
23870
  }); };
23845
23871
  this.onCouponCodeApply = function () { return __awaiter(_this, void 0, void 0, function () {
23846
- var newCheckout, oldCheckout;
23872
+ var isCouponSaveSuccess, newCheckout, oldCheckout;
23847
23873
  return __generator(this, function (_a) {
23848
23874
  switch (_a.label) {
23849
23875
  case 0:
23850
- _a.trys.push([0, 3, , 4]);
23851
- return [4 /*yield*/, this.saveCheckout()];
23876
+ if (!this.checkout.couponCode)
23877
+ return [2 /*return*/];
23878
+ _a.label = 1;
23852
23879
  case 1:
23853
- _a.sent();
23854
- return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
23880
+ _a.trys.push([1, 5, , 6]);
23881
+ return [4 /*yield*/, IkasCheckoutAPI.addCouponCodeToCheckout(this.checkout.id, this.checkout.couponCode)];
23855
23882
  case 2:
23883
+ isCouponSaveSuccess = _a.sent();
23884
+ if (!isCouponSaveSuccess) return [3 /*break*/, 4];
23885
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
23886
+ case 3:
23856
23887
  newCheckout = _a.sent();
23857
23888
  if (newCheckout) {
23858
23889
  oldCheckout = this.checkout;
23859
23890
  this.checkout = new IkasCheckout(__assign(__assign({}, newCheckout), { shippingAddress: oldCheckout.shippingAddress, billingAddress: oldCheckout.billingAddress, customer: oldCheckout.customer }));
23860
23891
  }
23861
- return [3 /*break*/, 4];
23862
- case 3:
23892
+ _a.label = 4;
23893
+ case 4: return [3 /*break*/, 6];
23894
+ case 5:
23863
23895
  _a.sent();
23864
- return [3 /*break*/, 4];
23865
- case 4: return [2 /*return*/];
23896
+ return [3 /*break*/, 6];
23897
+ case 6: return [2 /*return*/];
23866
23898
  }
23867
23899
  });
23868
23900
  }); };
@@ -41662,9 +41694,41 @@ var IkasCheckoutAPI = /** @class */ (function () {
41662
41694
  });
41663
41695
  });
41664
41696
  };
41697
+ IkasCheckoutAPI.addCouponCodeToCheckout = function (checkoutId, couponCode) {
41698
+ return __awaiter(this, void 0, void 0, function () {
41699
+ var MUTATION, data;
41700
+ return __generator(this, function (_a) {
41701
+ switch (_a.label) {
41702
+ case 0:
41703
+ MUTATION = src(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n mutation addCouponCodeToCheckout(\n $checkoutId: String!\n $couponCode: String!\n ) {\n addCouponCodeToCheckout(\n checkoutId: $checkoutId\n couponCode: $couponCode\n ) {\n id\n }\n }\n "], ["\n mutation addCouponCodeToCheckout(\n $checkoutId: String!\n $couponCode: String!\n ) {\n addCouponCodeToCheckout(\n checkoutId: $checkoutId\n couponCode: $couponCode\n ) {\n id\n }\n }\n "])));
41704
+ _a.label = 1;
41705
+ case 1:
41706
+ _a.trys.push([1, 3, , 4]);
41707
+ return [4 /*yield*/, apollo
41708
+ .getClient()
41709
+ .query({
41710
+ query: MUTATION,
41711
+ variables: {
41712
+ checkoutId: checkoutId,
41713
+ couponCode: couponCode,
41714
+ },
41715
+ })];
41716
+ case 2:
41717
+ data = (_a.sent()).data;
41718
+ if (data && data.addCouponCodeToCheckout.id)
41719
+ return [2 /*return*/, true];
41720
+ return [3 /*break*/, 4];
41721
+ case 3:
41722
+ _a.sent();
41723
+ return [3 /*break*/, 4];
41724
+ case 4: return [2 /*return*/];
41725
+ }
41726
+ });
41727
+ });
41728
+ };
41665
41729
  return IkasCheckoutAPI;
41666
41730
  }());
41667
- var templateObject_1$4, templateObject_2$3, templateObject_3$1, templateObject_4$1, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
41731
+ var templateObject_1$4, templateObject_2$3, templateObject_3$1, templateObject_4$1, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
41668
41732
 
41669
41733
  var IkasCityAPI = /** @class */ (function () {
41670
41734
  function IkasCityAPI() {
@@ -42162,7 +42226,7 @@ var IkasCustomerAPI = /** @class */ (function () {
42162
42226
  return __generator(this, function (_b) {
42163
42227
  switch (_b.label) {
42164
42228
  case 0:
42165
- LIST_ORDER_TRANSACTIONS = src(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "], ["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "])));
42229
+ LIST_ORDER_TRANSACTIONS = src(templateObject_10$1 || (templateObject_10$1 = __makeTemplateObject(["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "], ["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "])));
42166
42230
  _b.label = 1;
42167
42231
  case 1:
42168
42232
  _b.trys.push([1, 3, , 4]);
@@ -42367,7 +42431,7 @@ var IkasCustomerAPI = /** @class */ (function () {
42367
42431
  };
42368
42432
  return IkasCustomerAPI;
42369
42433
  }());
42370
- var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9$1, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
42434
+ var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9$1, templateObject_10$1, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
42371
42435
 
42372
42436
  var IkasDistrictAPI = /** @class */ (function () {
42373
42437
  function IkasDistrictAPI() {
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
  }); };
@@ -23850,26 +23876,32 @@ var CheckoutViewModel = /** @class */ (function () {
23850
23876
  });
23851
23877
  }); };
23852
23878
  this.onCouponCodeApply = function () { return __awaiter(_this, void 0, void 0, function () {
23853
- var newCheckout, oldCheckout;
23879
+ var isCouponSaveSuccess, newCheckout, oldCheckout;
23854
23880
  return __generator(this, function (_a) {
23855
23881
  switch (_a.label) {
23856
23882
  case 0:
23857
- _a.trys.push([0, 3, , 4]);
23858
- return [4 /*yield*/, this.saveCheckout()];
23883
+ if (!this.checkout.couponCode)
23884
+ return [2 /*return*/];
23885
+ _a.label = 1;
23859
23886
  case 1:
23860
- _a.sent();
23861
- return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
23887
+ _a.trys.push([1, 5, , 6]);
23888
+ return [4 /*yield*/, IkasCheckoutAPI.addCouponCodeToCheckout(this.checkout.id, this.checkout.couponCode)];
23862
23889
  case 2:
23890
+ isCouponSaveSuccess = _a.sent();
23891
+ if (!isCouponSaveSuccess) return [3 /*break*/, 4];
23892
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
23893
+ case 3:
23863
23894
  newCheckout = _a.sent();
23864
23895
  if (newCheckout) {
23865
23896
  oldCheckout = this.checkout;
23866
23897
  this.checkout = new IkasCheckout(__assign(__assign({}, newCheckout), { shippingAddress: oldCheckout.shippingAddress, billingAddress: oldCheckout.billingAddress, customer: oldCheckout.customer }));
23867
23898
  }
23868
- return [3 /*break*/, 4];
23869
- case 3:
23899
+ _a.label = 4;
23900
+ case 4: return [3 /*break*/, 6];
23901
+ case 5:
23870
23902
  _a.sent();
23871
- return [3 /*break*/, 4];
23872
- case 4: return [2 /*return*/];
23903
+ return [3 /*break*/, 6];
23904
+ case 6: return [2 /*return*/];
23873
23905
  }
23874
23906
  });
23875
23907
  }); };
@@ -41641,9 +41673,41 @@ var IkasCheckoutAPI = /** @class */ (function () {
41641
41673
  });
41642
41674
  });
41643
41675
  };
41676
+ IkasCheckoutAPI.addCouponCodeToCheckout = function (checkoutId, couponCode) {
41677
+ return __awaiter(this, void 0, void 0, function () {
41678
+ var MUTATION, data;
41679
+ return __generator(this, function (_a) {
41680
+ switch (_a.label) {
41681
+ case 0:
41682
+ MUTATION = src(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n mutation addCouponCodeToCheckout(\n $checkoutId: String!\n $couponCode: String!\n ) {\n addCouponCodeToCheckout(\n checkoutId: $checkoutId\n couponCode: $couponCode\n ) {\n id\n }\n }\n "], ["\n mutation addCouponCodeToCheckout(\n $checkoutId: String!\n $couponCode: String!\n ) {\n addCouponCodeToCheckout(\n checkoutId: $checkoutId\n couponCode: $couponCode\n ) {\n id\n }\n }\n "])));
41683
+ _a.label = 1;
41684
+ case 1:
41685
+ _a.trys.push([1, 3, , 4]);
41686
+ return [4 /*yield*/, apollo
41687
+ .getClient()
41688
+ .query({
41689
+ query: MUTATION,
41690
+ variables: {
41691
+ checkoutId: checkoutId,
41692
+ couponCode: couponCode,
41693
+ },
41694
+ })];
41695
+ case 2:
41696
+ data = (_a.sent()).data;
41697
+ if (data && data.addCouponCodeToCheckout.id)
41698
+ return [2 /*return*/, true];
41699
+ return [3 /*break*/, 4];
41700
+ case 3:
41701
+ _a.sent();
41702
+ return [3 /*break*/, 4];
41703
+ case 4: return [2 /*return*/];
41704
+ }
41705
+ });
41706
+ });
41707
+ };
41644
41708
  return IkasCheckoutAPI;
41645
41709
  }());
41646
- var templateObject_1$4, templateObject_2$3, templateObject_3$1, templateObject_4$1, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
41710
+ var templateObject_1$4, templateObject_2$3, templateObject_3$1, templateObject_4$1, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
41647
41711
 
41648
41712
  var IkasCityAPI = /** @class */ (function () {
41649
41713
  function IkasCityAPI() {
@@ -42141,7 +42205,7 @@ var IkasCustomerAPI = /** @class */ (function () {
42141
42205
  return __generator(this, function (_b) {
42142
42206
  switch (_b.label) {
42143
42207
  case 0:
42144
- LIST_ORDER_TRANSACTIONS = src(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "], ["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "])));
42208
+ LIST_ORDER_TRANSACTIONS = src(templateObject_10$1 || (templateObject_10$1 = __makeTemplateObject(["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "], ["\n query listOrderTransactions(\n $checkoutId: StringFilterInput\n $id: StringFilterInput\n $orderId: StringFilterInput\n ) {\n listOrderTransactions(\n checkoutId: $checkoutId\n id: $id\n orderId: $orderId\n ) {\n amount\n checkoutId\n createdAt\n currencyCode\n customerId\n deleted\n error {\n code\n declineCode\n message\n }\n id\n orderId\n paymentGatewayId\n paymentGatewayName\n paymentMethod\n paymentMethodDetail {\n bankName\n binNumber\n cardAssociation\n cardFamily\n cardType\n installment {\n installmentCount\n installmentPrice\n totalPrice\n }\n lastFourDigits\n threeDSecure\n }\n processedAt\n refundReason\n status\n type\n updatedAt\n }\n }\n "])));
42145
42209
  _b.label = 1;
42146
42210
  case 1:
42147
42211
  _b.trys.push([1, 3, , 4]);
@@ -42346,7 +42410,7 @@ var IkasCustomerAPI = /** @class */ (function () {
42346
42410
  };
42347
42411
  return IkasCustomerAPI;
42348
42412
  }());
42349
- var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9$1, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
42413
+ var templateObject_1$7, templateObject_2$5, templateObject_3$3, templateObject_4$2, templateObject_5$1, templateObject_6$1, templateObject_7$1, templateObject_8$1, templateObject_9$1, templateObject_10$1, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
42350
42414
 
42351
42415
  var IkasDistrictAPI = /** @class */ (function () {
42352
42416
  function IkasDistrictAPI() {
@@ -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.21",
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",