@ikas/storefront 0.2.0-beta.1 → 0.2.0

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.
@@ -1,24 +1,10 @@
1
- import { AmountTypeEnum, ProductOptionTypeEnum, OrderLineItemStatusEnum, CartStatusEnum } from "../../../__generated__/global-types";
1
+ import { AmountTypeEnum, OrderLineItemStatusEnum, CartStatusEnum } from "../../../__generated__/global-types";
2
2
  export interface getCart_getCart_items_discount {
3
3
  __typename: "OrderLineDiscount";
4
4
  amount: number;
5
5
  amountType: AmountTypeEnum;
6
6
  reason: string | null;
7
7
  }
8
- export interface getCart_getCart_items_options_values {
9
- __typename: "OrderLineOptionValue";
10
- name: string | null;
11
- price: number | null;
12
- value: string;
13
- }
14
- export interface getCart_getCart_items_options {
15
- __typename: "OrderLineOption";
16
- name: string;
17
- productOptionId: string;
18
- productOptionsSetId: string;
19
- type: ProductOptionTypeEnum;
20
- values: getCart_getCart_items_options_values[];
21
- }
22
8
  export interface getCart_getCart_items_variant_variantValues {
23
9
  __typename: "OrderLineVariantVariantValues";
24
10
  order: number;
@@ -46,7 +32,6 @@ export interface getCart_getCart_items {
46
32
  discountPrice: number | null;
47
33
  finalPrice: number | null;
48
34
  id: string;
49
- options: getCart_getCart_items_options[] | null;
50
35
  originalOrderLineItemId: string | null;
51
36
  price: number;
52
37
  quantity: number;
package/build/index.es.js CHANGED
@@ -19867,28 +19867,6 @@ var moment = createCommonjsModule(function (module, exports) {
19867
19867
  })));
19868
19868
  });
19869
19869
 
19870
- var ProductOptionTypeEnum;
19871
- (function (ProductOptionTypeEnum) {
19872
- ProductOptionTypeEnum["CHECKBOX"] = "CHECKBOX";
19873
- ProductOptionTypeEnum["CHOICE"] = "CHOICE";
19874
- ProductOptionTypeEnum["COLOR_PICKER"] = "COLOR_PICKER";
19875
- ProductOptionTypeEnum["DATE_PICKER"] = "DATE_PICKER";
19876
- ProductOptionTypeEnum["FILE"] = "FILE";
19877
- ProductOptionTypeEnum["IMAGE"] = "IMAGE";
19878
- ProductOptionTypeEnum["TEXT"] = "TEXT";
19879
- ProductOptionTypeEnum["TEXT_AREA"] = "TEXT_AREA";
19880
- })(ProductOptionTypeEnum || (ProductOptionTypeEnum = {}));
19881
- var IkasOrderLineOptions = /** @class */ (function () {
19882
- function IkasOrderLineOptions(data) {
19883
- this.name = data.name;
19884
- this.productOptionId = data.productOptionId;
19885
- this.productOptionsSetId = data.productOptionsSetId;
19886
- this.type = data.type;
19887
- this.values = data.values;
19888
- }
19889
- return IkasOrderLineOptions;
19890
- }());
19891
-
19892
19870
  var IkasOrderLineItem = /** @class */ (function () {
19893
19871
  function IkasOrderLineItem(data) {
19894
19872
  this.discount = null;
@@ -19916,9 +19894,6 @@ var IkasOrderLineItem = /** @class */ (function () {
19916
19894
  ? new IkasOrderLineVariant(data.variant)
19917
19895
  : new IkasOrderLineVariant();
19918
19896
  this.status = data.status || OrderLineItemStatusEnum.FULFILLED;
19919
- this.options = data.options
19920
- ? data.options.map(function (oP) { return new IkasOrderLineOptions(oP); })
19921
- : null;
19922
19897
  makeAutoObservable(this);
19923
19898
  }
19924
19899
  Object.defineProperty(IkasOrderLineItem.prototype, "orderedAtDays", {
@@ -21184,19 +21159,6 @@ var IkasProduct = /** @class */ (function () {
21184
21159
  enumerable: false,
21185
21160
  configurable: true
21186
21161
  });
21187
- Object.defineProperty(IkasProduct.prototype, "canAddToCart", {
21188
- get: function () {
21189
- if (this.productOptionSetId) {
21190
- return (!!this.productOptionSet &&
21191
- this.productOptionSet.options.every(function (o) { return o.hasValidValues; }));
21192
- }
21193
- else {
21194
- return true;
21195
- }
21196
- },
21197
- enumerable: false,
21198
- configurable: true
21199
- });
21200
21162
  return IkasProduct;
21201
21163
  }());
21202
21164
  var IkasProductType;
@@ -24053,8 +24015,8 @@ var IkasProductOptionType;
24053
24015
  IkasProductOptionType["CHOICE"] = "CHOICE";
24054
24016
  IkasProductOptionType["TEXT"] = "TEXT";
24055
24017
  IkasProductOptionType["TEXT_AREA"] = "TEXT_AREA";
24056
- // IMAGE = "IMAGE",
24057
- // FILE = "FILE",
24018
+ IkasProductOptionType["IMAGE"] = "IMAGE";
24019
+ IkasProductOptionType["FILE"] = "FILE";
24058
24020
  IkasProductOptionType["COLOR_PICKER"] = "COLOR_PICKER";
24059
24021
  // DATE_PICKER = "DATE_PICKER",
24060
24022
  IkasProductOptionType["CHECKBOX"] = "CHECKBOX";
@@ -24098,16 +24060,16 @@ var IkasProductOptionSetTranslations = /** @class */ (function () {
24098
24060
  var IkasProductOptionSelectValue = /** @class */ (function () {
24099
24061
  function IkasProductOptionSelectValue(data) {
24100
24062
  if (data === void 0) { data = {}; }
24101
- this.thumbnailImage = null;
24102
- this.id = data.id || "";
24103
24063
  this.order = data.order || 0;
24104
24064
  this.value = data.value || "";
24105
24065
  this.price = data.price || null;
24106
24066
  this.thumbnailImageId = data.thumbnailImageId || null;
24107
24067
  this.colorCode = data.colorCode || null;
24108
- this.thumbnailImage = this.thumbnailImageId
24109
- ? new IkasImage(this.thumbnailImageId)
24110
- : null;
24068
+ this.thumbnailImage =
24069
+ data.thumbnailImage ||
24070
+ (this.thumbnailImageId
24071
+ ? new IkasImage(this.thumbnailImageId)
24072
+ : undefined);
24111
24073
  makeAutoObservable(this);
24112
24074
  }
24113
24075
  return IkasProductOptionSelectValue;
@@ -24117,14 +24079,8 @@ var IkasProductOptionSelectSettings = /** @class */ (function () {
24117
24079
  if (data === void 0) { data = {}; }
24118
24080
  var _a;
24119
24081
  this.type = data.type || IkasProductOptionSelectType.BOX;
24120
- this.minSelect =
24121
- data.minSelect !== null && data.minSelect !== undefined
24122
- ? data.minSelect
24123
- : null;
24124
- this.maxSelect =
24125
- data.maxSelect !== null && data.maxSelect !== undefined
24126
- ? data.maxSelect
24127
- : null;
24082
+ this.minSelect = data.minSelect || null;
24083
+ this.maxSelect = data.maxSelect || null;
24128
24084
  this.values =
24129
24085
  ((_a = data.values) === null || _a === void 0 ? void 0 : _a.map(function (o) { return new IkasProductOptionSelectValue(o); })) || [];
24130
24086
  makeAutoObservable(this);
@@ -24142,8 +24098,8 @@ var IkasProductOptionDateSettings = /** @class */ (function () {
24142
24098
  var IkasProductOptionTextSettings = /** @class */ (function () {
24143
24099
  function IkasProductOptionTextSettings(data) {
24144
24100
  if (data === void 0) { data = {}; }
24145
- this.min = data.min !== null && data.min !== undefined ? data.min : null;
24146
- this.max = data.max !== null && data.max !== undefined ? data.max : null;
24101
+ this.min = data.min || null;
24102
+ this.max = data.max || null;
24147
24103
  makeAutoObservable(this);
24148
24104
  }
24149
24105
  return IkasProductOptionTextSettings;
@@ -24151,51 +24107,14 @@ var IkasProductOptionTextSettings = /** @class */ (function () {
24151
24107
  var IkasProductOptionFileSettings = /** @class */ (function () {
24152
24108
  function IkasProductOptionFileSettings(data) {
24153
24109
  this.allowedExtensions = data.allowedExtensions || null;
24154
- this.minQuantity =
24155
- data.minQuantity !== null && data.minQuantity !== undefined
24156
- ? data.minQuantity
24157
- : null;
24158
- this.maxQuantity =
24159
- data.maxQuantity !== null && data.maxQuantity !== undefined
24160
- ? data.maxQuantity
24161
- : null;
24110
+ this.minQuantity = data.minQuantity || null;
24111
+ this.maxQuantity = data.maxQuantity || null;
24162
24112
  makeAutoObservable(this);
24163
24113
  }
24164
24114
  return IkasProductOptionFileSettings;
24165
24115
  }());
24166
24116
  var IkasProductOption = /** @class */ (function () {
24167
24117
  function IkasProductOption(data) {
24168
- var _this = this;
24169
- this._values = [];
24170
- this.childOptions = [];
24171
- this.initValues = function () {
24172
- if (!_this.isOptional) {
24173
- _this.values = [];
24174
- if (_this.childOptions) {
24175
- _this.childOptions.forEach(function (co) { return co.initValues(); });
24176
- }
24177
- }
24178
- };
24179
- this.isValidTextOptionValue = function () {
24180
- return (!!_this.textSettings &&
24181
- (_this.textSettings.min !== null
24182
- ? _this.values[0].length >= _this.textSettings.min
24183
- : true) &&
24184
- (_this.textSettings.max !== null
24185
- ? _this.values[0].length <= _this.textSettings.max
24186
- : true));
24187
- };
24188
- this.isValidChoiceOptionValue = function () {
24189
- return (!!_this.selectSettings &&
24190
- (_this.selectSettings.minSelect !== null
24191
- ? _this.values.length >= _this.selectSettings.minSelect
24192
- : true) &&
24193
- (_this.selectSettings.maxSelect !== null
24194
- ? _this.values.length <= _this.selectSettings.maxSelect
24195
- : true));
24196
- };
24197
- this.id = data.id || "";
24198
- this.productOptionSetId = data.productOptionSetId || "";
24199
24118
  this.name = data.name || "";
24200
24119
  this.order = data.order || 0;
24201
24120
  this.type = data.type || IkasProductOptionType.CHOICE;
@@ -24216,134 +24135,19 @@ var IkasProductOption = /** @class */ (function () {
24216
24135
  this.optionalText = data.optionalText || null;
24217
24136
  this.requiredOptionId = data.requiredOptionId || null;
24218
24137
  this.requiredOptionValueIds = data.requiredOptionValueIds || null;
24219
- this.values = data.values || [];
24220
- this.childOptions = data.childOptions || [];
24221
24138
  makeAutoObservable(this);
24222
24139
  }
24223
- Object.defineProperty(IkasProductOption.prototype, "displayedChildOptions", {
24224
- get: function () {
24225
- var _this = this;
24226
- return this.childOptions.filter(function (co) {
24227
- var _a;
24228
- // Check if all required options are selected
24229
- if ((_a = co.requiredOptionValueIds) === null || _a === void 0 ? void 0 : _a.length) {
24230
- return co.requiredOptionValueIds.every(function (rovId) {
24231
- return _this.values.some(function (v) { return v === rovId; });
24232
- });
24233
- }
24234
- else {
24235
- return !!_this.values.length;
24236
- }
24237
- });
24238
- },
24239
- enumerable: false,
24240
- configurable: true
24241
- });
24242
- Object.defineProperty(IkasProductOption.prototype, "hasValidValues", {
24243
- get: function () {
24244
- if (!this.values.length && !this.isOptional) {
24245
- return false;
24246
- }
24247
- var hasValidValues = false;
24248
- switch (this.type) {
24249
- case IkasProductOptionType.TEXT:
24250
- case IkasProductOptionType.TEXT_AREA:
24251
- hasValidValues = this.isValidTextOptionValue();
24252
- break;
24253
- case IkasProductOptionType.CHECKBOX:
24254
- case IkasProductOptionType.COLOR_PICKER:
24255
- hasValidValues = true;
24256
- break;
24257
- case IkasProductOptionType.CHOICE:
24258
- hasValidValues = this.isValidChoiceOptionValue();
24259
- break;
24260
- }
24261
- return hasValidValues && this.childOptions.every(function (co) { return co.hasValidValues; });
24262
- },
24263
- enumerable: false,
24264
- configurable: true
24265
- });
24266
- Object.defineProperty(IkasProductOption.prototype, "values", {
24267
- get: function () {
24268
- return this._values;
24269
- },
24270
- set: function (values) {
24271
- this._values = values;
24272
- if (!values.length) {
24273
- this.childOptions.forEach(function (co) { return (co.values = []); });
24274
- }
24275
- },
24276
- enumerable: false,
24277
- configurable: true
24278
- });
24279
24140
  return IkasProductOption;
24280
24141
  }());
24281
24142
  var IkasProductOptionSet = /** @class */ (function () {
24282
24143
  function IkasProductOptionSet(data) {
24283
- var _this = this;
24284
24144
  var _a, _b;
24285
- this.initOptionValues = function () { return __awaiter(_this, void 0, void 0, function () {
24286
- return __generator(this, function (_a) {
24287
- this.options.forEach(function (o) { return o.initValues(); });
24288
- return [2 /*return*/];
24289
- });
24290
- }); };
24291
- this.id = data.id || "";
24292
24145
  this.name = data.name || "";
24293
- this.options =
24294
- ((_a = data.options) === null || _a === void 0 ? void 0 : _a.map(function (o) {
24295
- return new IkasProductOption(__assign(__assign({}, o), { productOptionSetId: _this.id }));
24296
- })) || [];
24146
+ this.options = ((_a = data.options) === null || _a === void 0 ? void 0 : _a.map(function (o) { return new IkasProductOption(o); })) || [];
24297
24147
  this.translations = data.translations
24298
24148
  ? (_b = data.translations) === null || _b === void 0 ? void 0 : _b.map(function (o) { return new IkasProductOptionSetTranslations(o); }) : null;
24299
- this.setChildOptions();
24300
- this.setTranslations();
24301
- this.initOptionValues();
24302
24149
  makeAutoObservable(this);
24303
24150
  }
24304
- Object.defineProperty(IkasProductOptionSet.prototype, "displayedOptions", {
24305
- get: function () {
24306
- return this.options.filter(function (o) { return !o.requiredOptionId; });
24307
- },
24308
- enumerable: false,
24309
- configurable: true
24310
- });
24311
- IkasProductOptionSet.prototype.setTranslations = function () {
24312
- var _this = this;
24313
- var _a;
24314
- var locale = IkasStorefrontConfig.getCurrentLocale();
24315
- if (this.translations &&
24316
- this.translations.some(function (t) { return t.locale === locale; })) {
24317
- var localeTranslations = this.translations.find(function (t) { return t.locale === locale; });
24318
- (_a = localeTranslations === null || localeTranslations === void 0 ? void 0 : localeTranslations.options) === null || _a === void 0 ? void 0 : _a.forEach(function (translatedOption) {
24319
- var _a;
24320
- var option = _this.options.find(function (o) { return o.id === translatedOption.id; });
24321
- if (option) {
24322
- option.name = translatedOption.name || option.name;
24323
- option.optionalText =
24324
- translatedOption.optionalText || option.optionalText;
24325
- if (option.type === IkasProductOptionType.CHOICE) {
24326
- (_a = translatedOption.values) === null || _a === void 0 ? void 0 : _a.forEach(function (translatedValue) {
24327
- var _a;
24328
- var selectValue = (_a = option.selectSettings) === null || _a === void 0 ? void 0 : _a.values.find(function (sv) { return sv.id === translatedValue.id; });
24329
- if (selectValue) {
24330
- selectValue.value = translatedValue.value || selectValue.value;
24331
- }
24332
- });
24333
- }
24334
- }
24335
- });
24336
- }
24337
- };
24338
- IkasProductOptionSet.prototype.setChildOptions = function () {
24339
- var _this = this;
24340
- this.options.forEach(function (option) {
24341
- var childOptions = _this.options.filter(function (o) { return o.requiredOptionId === option.id; });
24342
- if (childOptions.length) {
24343
- option.childOptions = childOptions;
24344
- }
24345
- });
24346
- };
24347
24151
  return IkasProductOptionSet;
24348
24152
  }());
24349
24153
 
@@ -37961,7 +37765,7 @@ var ProductOptionSelectTypeEnum;
37961
37765
  ProductOptionSelectTypeEnum["SELECT"] = "SELECT";
37962
37766
  ProductOptionSelectTypeEnum["SWATCH"] = "SWATCH";
37963
37767
  })(ProductOptionSelectTypeEnum || (ProductOptionSelectTypeEnum = {}));
37964
- var ProductOptionTypeEnum$1;
37768
+ var ProductOptionTypeEnum;
37965
37769
  (function (ProductOptionTypeEnum) {
37966
37770
  ProductOptionTypeEnum["CHECKBOX"] = "CHECKBOX";
37967
37771
  ProductOptionTypeEnum["CHOICE"] = "CHOICE";
@@ -37971,7 +37775,7 @@ var ProductOptionTypeEnum$1;
37971
37775
  ProductOptionTypeEnum["IMAGE"] = "IMAGE";
37972
37776
  ProductOptionTypeEnum["TEXT"] = "TEXT";
37973
37777
  ProductOptionTypeEnum["TEXT_AREA"] = "TEXT_AREA";
37974
- })(ProductOptionTypeEnum$1 || (ProductOptionTypeEnum$1 = {}));
37778
+ })(ProductOptionTypeEnum || (ProductOptionTypeEnum = {}));
37975
37779
  var ProductSearchShowStockOptionEnum;
37976
37780
  (function (ProductSearchShowStockOptionEnum) {
37977
37781
  ProductSearchShowStockOptionEnum["HIDE_OUT_OF_STOCK"] = "HIDE_OUT_OF_STOCK";
@@ -41489,7 +41293,7 @@ var IkasCartAPI = /** @class */ (function () {
41489
41293
  return __generator(this, function (_b) {
41490
41294
  switch (_b.label) {
41491
41295
  case 0:
41492
- MUTATION = src(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "], ["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionsSetId\n productOptionId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "])));
41296
+ MUTATION = src(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "], ["\n mutation saveItemToCart($input: SaveItemToCartInput!) {\n saveItemToCart(input: $input) {\n id\n createdAt\n updatedAt\n dueDate\n currencyCode\n customerId\n merchantId\n itemCount\n totalPrice\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n taxLines {\n price\n rate\n }\n items {\n createdAt\n currencyCode\n deleted\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n originalOrderLineItemId\n price\n quantity\n status\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n id\n name\n sku\n slug\n barcodeList\n mainImageId\n productId\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n }\n }\n "])));
41493
41297
  _b.label = 1;
41494
41298
  case 1:
41495
41299
  _b.trys.push([1, 3, , 4]);
@@ -41524,7 +41328,7 @@ var IkasCartAPI = /** @class */ (function () {
41524
41328
  return __generator(this, function (_b) {
41525
41329
  switch (_b.label) {
41526
41330
  case 0:
41527
- QUERY = src(templateObject_2$1 || (templateObject_2$1 = __makeTemplateObject(["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "], ["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n options {\n name\n productOptionId\n productOptionsSetId\n type\n values {\n name\n price\n value\n }\n }\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "])));
41331
+ QUERY = src(templateObject_2$1 || (templateObject_2$1 = __makeTemplateObject(["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "], ["\n query getCart(\n $cartId: String\n $customerId: String\n $storefrontRoutingId: String\n ) {\n getCart(\n id: $cartId\n customerId: $customerId\n storefrontRoutingId: $storefrontRoutingId\n ) {\n createdAt\n currencyCode\n customerId\n dueDate\n id\n itemCount\n salesChannelId\n storefrontId\n storefrontRoutingId\n storefrontThemeId\n items {\n createdAt\n currencyCode\n discount {\n amount\n amountType\n reason\n }\n discountPrice\n finalPrice\n id\n originalOrderLineItemId\n price\n quantity\n status\n deleted\n statusUpdatedAt\n stockLocationId\n taxValue\n updatedAt\n variant {\n slug\n barcodeList\n id\n mainImageId\n name\n productId\n sku\n variantValues {\n order\n variantTypeId\n variantTypeName\n variantValueId\n variantValueName\n }\n }\n }\n merchantId\n status\n totalPrice\n updatedAt\n }\n }\n "])));
41528
41332
  _b.label = 1;
41529
41333
  case 1:
41530
41334
  _b.trys.push([1, 3, , 4]);
@@ -43640,9 +43444,7 @@ var IkasProductOptionSetAPI = /** @class */ (function () {
43640
43444
  return [2 /*return*/];
43641
43445
  }
43642
43446
  return [2 /*return*/, {
43643
- data: data.listProductOptionSet.map(function (c) {
43644
- return new IkasProductOptionSet(c);
43645
- }),
43447
+ data: data.listProductOptionSet.map(function (c) { return new IkasProductOptionSet(c); }),
43646
43448
  }];
43647
43449
  case 2:
43648
43450
  err_1 = _b.sent();
@@ -70737,17 +70539,6 @@ var Note = observer(function (_a) {
70737
70539
  isSuccessStep ? (createElement("div", { className: styles$g.CheckoutNoteDisplay }, vm.checkout.note)) : (createElement(FormItem, { style: { width: "100%" }, type: FormItemType.TEXT_AREA, disableResize: true, label: "", value: vm.checkout.note || "", onChange: onCheckoutNoteChange }))))));
70738
70540
  });
70739
70541
 
70740
- var IkasProductCartLineOption = /** @class */ (function () {
70741
- function IkasProductCartLineOption(data) {
70742
- if (data === void 0) { data = {}; }
70743
- this.productOptionId = data.productOptionId || "";
70744
- this.productOptionsSetId = data.productOptionsSetId || "";
70745
- this.values = data.values || [];
70746
- makeAutoObservable(this);
70747
- }
70748
- return IkasProductCartLineOption;
70749
- }());
70750
-
70751
70542
  var CART_LS_KEY = "cartId";
70752
70543
  var CHECKOUT_LS_KEY = "checkoutId";
70753
70544
  var IkasCartStore = /** @class */ (function () {
@@ -70773,7 +70564,9 @@ var IkasCartStore = /** @class */ (function () {
70773
70564
  cartId = ((_b = this.cart) === null || _b === void 0 ? void 0 : _b.id) || localStorage.getItem(CART_LS_KEY);
70774
70565
  if (!cartId && !customerId)
70775
70566
  return [2 /*return*/];
70776
- return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined)];
70567
+ return [4 /*yield*/, IkasCartAPI.getCart(cartId || undefined
70568
+ // customerId || undefined // TODO reopen this when we have a way of telling backend that we cleared a cart
70569
+ )];
70777
70570
  case 2:
70778
70571
  cart = _c.sent();
70779
70572
  if (!cart) return [3 /*break*/, 4];
@@ -70837,89 +70630,28 @@ var IkasCartStore = /** @class */ (function () {
70837
70630
  }
70838
70631
  });
70839
70632
  }); };
70840
- this.findExistingItem = function (variant, product) {
70841
- var _a, _b, _c, _d, _e;
70842
- if (!product.productOptionSetId) {
70843
- return (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.items.find(function (item) { return item.variant.id === variant.id; });
70844
- }
70845
- var existingItems = ((_b = _this.cart) === null || _b === void 0 ? void 0 : _b.items.filter(function (item) { return item.variant.id === variant.id; })) || [];
70846
- for (var _i = 0, existingItems_1 = existingItems; _i < existingItems_1.length; _i++) {
70847
- var item = existingItems_1[_i];
70848
- if (item.options) {
70849
- var hasSameOptionValues = true;
70850
- var _loop_1 = function (option) {
70851
- var existingOptionValues = option.values.map(function (v) { return v.value; });
70852
- var productOptionValues = (_e = (_d = (_c = product.productOptionSet) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.find(function (o) { return o.id === option.productOptionId; })) === null || _e === void 0 ? void 0 : _e.values;
70853
- hasSameOptionValues =
70854
- hasSameOptionValues &&
70855
- existingOptionValues.length === (productOptionValues === null || productOptionValues === void 0 ? void 0 : productOptionValues.values.length) &&
70856
- existingOptionValues.every(function (val) { return productOptionValues === null || productOptionValues === void 0 ? void 0 : productOptionValues.includes(val); });
70857
- if (!hasSameOptionValues)
70858
- return "break";
70859
- };
70860
- for (var _f = 0, _g = item.options; _f < _g.length; _f++) {
70861
- var option = _g[_f];
70862
- var state_1 = _loop_1(option);
70863
- if (state_1 === "break")
70864
- break;
70865
- }
70866
- if (hasSameOptionValues)
70867
- return item;
70868
- }
70869
- }
70870
- };
70871
- this.createCartLineOptions = function (item) {
70872
- if (item && item.options) {
70873
- var options = [];
70874
- for (var _i = 0, _a = item.options; _i < _a.length; _i++) {
70875
- var option = _a[_i];
70876
- var data = new IkasProductCartLineOption({});
70877
- data.productOptionId = option.productOptionId;
70878
- data.productOptionsSetId = option.productOptionsSetId;
70879
- data.values = option.values.map(function (val) { return val.value; });
70880
- options.push(data);
70881
- }
70882
- return options;
70883
- }
70884
- else {
70885
- return null;
70886
- }
70887
- };
70888
70633
  this.addItem = function (variant, product, initialQuantity) {
70889
70634
  if (initialQuantity === void 0) { initialQuantity = 1; }
70890
70635
  return __awaiter(_this, void 0, void 0, function () {
70891
- var existingItem, optionValues_1, cartId, input, cart, eventId, item, err_2;
70892
- var _a, _b, _c, _d, _e;
70893
- return __generator(this, function (_f) {
70894
- switch (_f.label) {
70636
+ var existingItem, cartId, input, cart, eventId, item, err_2;
70637
+ var _a, _b, _c;
70638
+ return __generator(this, function (_d) {
70639
+ switch (_d.label) {
70895
70640
  case 0:
70896
- _f.trys.push([0, 5, , 6]);
70897
- if (!product.canAddToCart)
70898
- return [2 /*return*/, false];
70641
+ _d.trys.push([0, 5, , 6]);
70899
70642
  return [4 /*yield*/, this.beforeCartOperationCheck()];
70900
70643
  case 1:
70901
- _f.sent();
70644
+ _d.sent();
70902
70645
  if (this.cart) {
70903
- existingItem = this.findExistingItem(variant, product);
70646
+ existingItem = this.cart.items.find(function (item) { return item.variant.id === variant.id; });
70904
70647
  if (existingItem) {
70905
- (_a = product.productOptionSet) === null || _a === void 0 ? void 0 : _a.initOptionValues();
70906
70648
  return [2 /*return*/, this.changeItemQuantity(existingItem, existingItem.quantity + 1)];
70907
70649
  }
70908
70650
  }
70909
- optionValues_1 = [];
70910
- (_b = product.productOptionSet) === null || _b === void 0 ? void 0 : _b.options.forEach(function (o) {
70911
- if (o.values.length) {
70912
- optionValues_1.push(new IkasProductCartLineOption({
70913
- productOptionId: o.id,
70914
- productOptionsSetId: o.productOptionSetId,
70915
- values: o.values,
70916
- }));
70917
- }
70918
- });
70919
- cartId = ((_c = this.cart) === null || _c === void 0 ? void 0 : _c.id) || localStorage.getItem(CART_LS_KEY);
70651
+ cartId = ((_a = this.cart) === null || _a === void 0 ? void 0 : _a.id) || localStorage.getItem(CART_LS_KEY);
70920
70652
  input = {
70921
70653
  cartId: cartId,
70922
- customerId: ((_d = this.cart) === null || _d === void 0 ? void 0 : _d.customerId) || ((_e = this.baseStore.customerStore.customer) === null || _e === void 0 ? void 0 : _e.id) ||
70654
+ 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) ||
70923
70655
  null,
70924
70656
  item: {
70925
70657
  id: null,
@@ -70929,7 +70661,6 @@ var IkasCartStore = /** @class */ (function () {
70929
70661
  name: product.name,
70930
70662
  },
70931
70663
  },
70932
- options: optionValues_1.length ? optionValues_1 : null,
70933
70664
  priceListId: IkasStorefrontConfig.priceListId || null,
70934
70665
  salesChannelId: IkasStorefrontConfig.salesChannelId,
70935
70666
  storefrontId: IkasStorefrontConfig.storefrontId,
@@ -70938,12 +70669,12 @@ var IkasCartStore = /** @class */ (function () {
70938
70669
  };
70939
70670
  return [4 /*yield*/, IkasCartAPI.saveItemToCart(input)];
70940
70671
  case 2:
70941
- cart = _f.sent();
70672
+ cart = _d.sent();
70942
70673
  if (!cart) return [3 /*break*/, 4];
70943
70674
  return [4 /*yield*/, this.setCart(cart)];
70944
70675
  case 3:
70945
- _f.sent();
70946
- _f.label = 4;
70676
+ _d.sent();
70677
+ _d.label = 4;
70947
70678
  case 4:
70948
70679
  if (this.cart) {
70949
70680
  eventId = this.cart.id + "-" + this.cart.updatedAt;
@@ -70952,11 +70683,11 @@ var IkasCartStore = /** @class */ (function () {
70952
70683
  Analytics.addToCart(item, initialQuantity, eventId, this.cart);
70953
70684
  }
70954
70685
  }
70955
- return [2 /*return*/, true];
70686
+ return [3 /*break*/, 6];
70956
70687
  case 5:
70957
- err_2 = _f.sent();
70688
+ err_2 = _d.sent();
70958
70689
  console.log(err_2);
70959
- return [2 /*return*/, false];
70690
+ return [3 /*break*/, 6];
70960
70691
  case 6: return [2 /*return*/];
70961
70692
  }
70962
70693
  });
@@ -70984,7 +70715,6 @@ var IkasCartStore = /** @class */ (function () {
70984
70715
  name: item.variant.name,
70985
70716
  },
70986
70717
  },
70987
- options: this.createCartLineOptions(item),
70988
70718
  priceListId: IkasStorefrontConfig.priceListId || null,
70989
70719
  salesChannelId: IkasStorefrontConfig.salesChannelId,
70990
70720
  storefrontId: IkasStorefrontConfig.storefrontId,
@@ -71011,11 +70741,11 @@ var IkasCartStore = /** @class */ (function () {
71011
70741
  Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
71012
70742
  }
71013
70743
  }
71014
- return [2 /*return*/, true];
70744
+ return [3 /*break*/, 6];
71015
70745
  case 5:
71016
70746
  err_3 = _d.sent();
71017
70747
  console.log(err_3);
71018
- return [2 /*return*/, false];
70748
+ return [3 /*break*/, 6];
71019
70749
  case 6: return [2 /*return*/];
71020
70750
  }
71021
70751
  });