ng-easycommerce 0.0.679 → 0.0.680

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.
@@ -7859,6 +7859,31 @@ var CartEcComponent = /** @class */ (function (_super) {
7859
7859
  _this.cartLoading = false;
7860
7860
  _this.enableFieldNotesInArticleFile = false;
7861
7861
  _this.toDecimal = function (amount) { return _this.consts.toDecimal(amount); };
7862
+ _this.cartItemPlus = function (item) {
7863
+ var _a, _b;
7864
+ var multipleQty = ((_a = item.product.variants[0]) === null || _a === void 0 ? void 0 : _a.multipleQuantity) || 0;
7865
+ var step = multipleQty || 1;
7866
+ var stock = (_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.stock;
7867
+ var current = item.quantity;
7868
+ var next = step > 1 && current % step !== 0
7869
+ ? Math.ceil(current / step) * step
7870
+ : current + step;
7871
+ _this.actualizarCantidad(item, next, stock, 'cartPlus');
7872
+ };
7873
+ _this.cartItemLess = function (item) {
7874
+ var _a, _b, _c;
7875
+ var multipleQty = ((_a = item.product.variants[0]) === null || _a === void 0 ? void 0 : _a.multipleQuantity) || 0;
7876
+ var minimumQty = ((_b = item.product.variants[0]) === null || _b === void 0 ? void 0 : _b.minimumItemsQuantity) || 0;
7877
+ var step = multipleQty || 1;
7878
+ var floor = minimumQty || step;
7879
+ var current = item.quantity;
7880
+ var next = step > 1 && current % step !== 0
7881
+ ? Math.floor(current / step) * step
7882
+ : current - step;
7883
+ if (next >= floor) {
7884
+ _this.actualizarCantidad(item, next, (_c = item.product.variants[0]) === null || _c === void 0 ? void 0 : _c.stock, 'cartLess');
7885
+ }
7886
+ };
7862
7887
  _this.redirectRegister = function () { return _this.router.navigateByUrl("/auth/login"); };
7863
7888
  _this.getVariants = function (product) {
7864
7889
  var item = product.product;
@@ -13956,6 +13981,9 @@ var ProductDetailEcComponent = /** @class */ (function (_super) {
13956
13981
  _this.hidePrices = false;
13957
13982
  _this.creditAccountShowPrices = null;
13958
13983
  _this.enableFieldNotesInArticleFile = false;
13984
+ _this.quantityError = '';
13985
+ _this.minimumItemsQty = null;
13986
+ _this.multipleQty = null;
13959
13987
  _this.addToCart = function () {
13960
13988
  var _a;
13961
13989
  var note = ((_a = _this.comments) === null || _a === void 0 ? void 0 : _a.trim()) || null;
@@ -13971,22 +13999,25 @@ var ProductDetailEcComponent = /** @class */ (function (_super) {
13971
13999
  };
13972
14000
  /**
13973
14001
  * @description actualiza la variable quantity sumandole 'x' contenido.
14002
+ * Si hay un multipleQuantity configurado, hace snap al siguiente múltiplo válido
14003
+ * cuando la cantidad actual ya es inválida.
13974
14004
  * @param stock número máximo disponible en stock.
13975
- * @param changeAmount cantidad que se quiere sumar.
13976
- * @param forceMultiple si es true, obliga a que el resultado sea múltiplo de changeAmount.
14005
+ * @param changeAmount cantidad que se quiere sumar (ignorado si multipleQty está seteado).
14006
+ * @param forceMultiple legacy — si es true, obliga a que el resultado sea múltiplo de changeAmount.
13977
14007
  */
13978
14008
  _this.plus = function (stock, changeAmount, forceMultiple) {
13979
14009
  if (changeAmount === void 0) { changeAmount = 1; }
13980
14010
  if (forceMultiple === void 0) { forceMultiple = false; }
14011
+ var step = _this.multipleQty || changeAmount;
13981
14012
  var currentQuantity = Number(_this.quantity);
13982
- var newQuantity = currentQuantity + changeAmount;
13983
- if (forceMultiple && changeAmount > 0) {
13984
- if (currentQuantity < changeAmount) {
13985
- newQuantity = changeAmount;
13986
- }
13987
- else {
13988
- newQuantity = Math.ceil(newQuantity / changeAmount) * changeAmount;
13989
- }
14013
+ var newQuantity;
14014
+ if (step > 1) {
14015
+ newQuantity = currentQuantity % step !== 0
14016
+ ? Math.ceil(currentQuantity / step) * step
14017
+ : currentQuantity + step;
14018
+ }
14019
+ else {
14020
+ newQuantity = currentQuantity + step;
13990
14021
  }
13991
14022
  if (!stock || newQuantity <= stock) {
13992
14023
  _this.quantity = newQuantity;
@@ -13994,35 +14025,59 @@ var ProductDetailEcComponent = /** @class */ (function (_super) {
13994
14025
  else {
13995
14026
  _this.toastrService.show('out-of-stock-actually');
13996
14027
  }
14028
+ _this.validateDetail();
13997
14029
  };
13998
14030
  /**
13999
14031
  * @description actualiza la variable quantity restandole 'x' contenido.
14000
- * @param changeAmount cantidad que se quiere restar.
14001
- * @param forceMultiple si es true, obliga a que el resultado sea múltiplo de changeAmount.
14032
+ * Si hay un multipleQuantity configurado, hace snap al múltiplo válido inferior
14033
+ * cuando la cantidad actual ya es inválida.
14034
+ * @param changeAmount cantidad que se quiere restar (ignorado si multipleQty está seteado).
14035
+ * @param minimum cantidad mínima permitida (ignorado si minimumItemsQty está seteado).
14036
+ * @param forceMultiple legacy — si es true, obliga a que el resultado sea múltiplo de changeAmount.
14002
14037
  */
14003
14038
  _this.less = function (changeAmount, minimum, forceMultiple) {
14004
14039
  if (changeAmount === void 0) { changeAmount = 1; }
14005
14040
  if (minimum === void 0) { minimum = 1; }
14006
14041
  if (forceMultiple === void 0) { forceMultiple = false; }
14007
- var newQuantity = _this.quantity - changeAmount;
14008
- if (forceMultiple && changeAmount > 0) {
14009
- if (_this.quantity <= changeAmount) {
14010
- newQuantity = changeAmount;
14011
- }
14012
- else {
14013
- newQuantity = Math.floor(newQuantity / changeAmount) * changeAmount;
14014
- }
14015
- if (newQuantity < changeAmount) {
14016
- newQuantity = changeAmount;
14017
- }
14042
+ var step = _this.multipleQty || changeAmount;
14043
+ var floor = _this.minimumItemsQty || (step > 1 ? step : minimum);
14044
+ var newQuantity;
14045
+ if (step > 1) {
14046
+ newQuantity = _this.quantity % step !== 0
14047
+ ? Math.floor(_this.quantity / step) * step
14048
+ : _this.quantity - step;
14018
14049
  }
14019
- if (newQuantity >= minimum) {
14020
- _this.quantity = newQuantity;
14050
+ else {
14051
+ newQuantity = _this.quantity - step;
14052
+ }
14053
+ _this.quantity = newQuantity >= floor ? newQuantity : floor;
14054
+ _this.validateDetail();
14055
+ };
14056
+ _this.onQuantityInput = function (value) {
14057
+ var parsed = parseInt(value, 10);
14058
+ if (!isNaN(parsed)) {
14059
+ _this.quantity = parsed;
14060
+ _this.validateDetail();
14061
+ }
14062
+ };
14063
+ _this.validateDetail = function () {
14064
+ if (_this.minimumItemsQty && _this.quantity < _this.minimumItemsQty) {
14065
+ _this.quantityError = 'La cantidad debe ser al menos ' + _this.minimumItemsQty;
14066
+ }
14067
+ else if (_this.multipleQty && _this.quantity % _this.multipleQty !== 0) {
14068
+ _this.quantityError = 'La cantidad debe ser m\u00faltiplo de ' + _this.multipleQty;
14021
14069
  }
14022
14070
  else {
14023
- _this.quantity = minimum;
14071
+ _this.quantityError = '';
14024
14072
  }
14025
14073
  };
14074
+ _this.isQuantityValidDetail = function () {
14075
+ if (_this.minimumItemsQty && _this.quantity < _this.minimumItemsQty)
14076
+ return false;
14077
+ if (_this.multipleQty && _this.quantity % _this.multipleQty !== 0)
14078
+ return false;
14079
+ return true;
14080
+ };
14026
14081
  _this.showContact = function () { return _this.show = true; };
14027
14082
  _this.hideContact = function () { return _this.show = false; };
14028
14083
  _this.thereIsMoreInfo = function (product) {
@@ -14104,6 +14159,13 @@ var ProductDetailEcComponent = /** @class */ (function (_super) {
14104
14159
  });
14105
14160
  _this.comments = (_o = (_m = match) === null || _m === void 0 ? void 0 : _m.comments, (_o !== null && _o !== void 0 ? _o : ''));
14106
14161
  });
14162
+ this.productService.asociatedData$.subscribe(function (ad) {
14163
+ var _a, _b;
14164
+ _this.minimumItemsQty = ((_a = ad) === null || _a === void 0 ? void 0 : _a.minimumItemsQuantity) || null;
14165
+ _this.multipleQty = ((_b = ad) === null || _b === void 0 ? void 0 : _b.multipleQuantity) || null;
14166
+ _this.quantity = _this.minimumItemsQty || _this.multipleQty || 1;
14167
+ _this.quantityError = '';
14168
+ });
14107
14169
  };
14108
14170
  ProductDetailEcComponent.prototype.ngOnDestroy = function () {
14109
14171
  var _a;
@@ -19324,7 +19386,77 @@ var MultipleItemsToCartEcComponent = /** @class */ (function (_super) {
19324
19386
  _this.totalItems = new EventEmitter();
19325
19387
  _this.total = 0;
19326
19388
  _this.countItems = 0;
19389
+ _this.quantity = 1;
19390
+ _this.spanInfo = '';
19327
19391
  _this.optionsProductForVariant = function () { return _this.product.productWithUniqueVariant; };
19392
+ _this.plus = function (product, stock, multipleQuantity) {
19393
+ if (multipleQuantity && multipleQuantity > 0) {
19394
+ var next = _this.quantity % multipleQuantity !== 0
19395
+ ? Math.ceil(_this.quantity / multipleQuantity) * multipleQuantity
19396
+ : _this.quantity + multipleQuantity;
19397
+ stock ? (next <= stock ? _this.quantity = next : _this.toastService.show('out-of-stock-actually'))
19398
+ : _this.quantity = next;
19399
+ _this.setQuantity(_this.quantity, product);
19400
+ _this.validateQuantity(_this.quantity, product);
19401
+ }
19402
+ else {
19403
+ stock ? (_this.quantity < stock ? _this.quantity = _this.quantity + 1 : _this.toastService.show('out-of-stock-actually'))
19404
+ : _this.quantity = _this.quantity + 1;
19405
+ _this.setQuantity(_this.quantity, product);
19406
+ }
19407
+ };
19408
+ _this.less = function (product, multipleQuantity, minimumItemsQuantity) {
19409
+ if (multipleQuantity && multipleQuantity >= 0) {
19410
+ var minimum = minimumItemsQuantity || multipleQuantity;
19411
+ var next = _this.quantity % multipleQuantity !== 0
19412
+ ? Math.floor(_this.quantity / multipleQuantity) * multipleQuantity
19413
+ : _this.quantity - multipleQuantity;
19414
+ if (next >= minimum) {
19415
+ _this.quantity = next;
19416
+ }
19417
+ _this.setQuantity(_this.quantity, product);
19418
+ _this.validateQuantity(_this.quantity, product);
19419
+ }
19420
+ else {
19421
+ _this.quantity > 0 ? _this.quantity = _this.quantity - 1 : null;
19422
+ _this.setQuantity(_this.quantity, product);
19423
+ }
19424
+ };
19425
+ _this.isQuantityValid = function (quantity, item) {
19426
+ var _a, _b, _c, _d, _e, _f;
19427
+ var minimumItemsQuantity = (_c = (_b = (_a = item) === null || _a === void 0 ? void 0 : _a.variants) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.minimumItemsQuantity;
19428
+ var multipleQuantity = (_f = (_e = (_d = item) === null || _d === void 0 ? void 0 : _d.variants) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.multipleQuantity;
19429
+ if (minimumItemsQuantity && quantity < minimumItemsQuantity)
19430
+ return false;
19431
+ if (multipleQuantity && quantity % multipleQuantity !== 0)
19432
+ return false;
19433
+ return true;
19434
+ };
19435
+ _this.validateQuantity = function (quantity, item) {
19436
+ var _a, _b, _c, _d, _e, _f;
19437
+ var minimumItemsQuantity = (_c = (_b = (_a = item) === null || _a === void 0 ? void 0 : _a.variants) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.minimumItemsQuantity;
19438
+ var multipleQuantity = (_f = (_e = (_d = item) === null || _d === void 0 ? void 0 : _d.variants) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.multipleQuantity;
19439
+ _this.spanInfo = '';
19440
+ if (minimumItemsQuantity && quantity < minimumItemsQuantity) {
19441
+ _this.spanInfo = 'La cantidad debe ser al menos ' + minimumItemsQuantity;
19442
+ }
19443
+ else if (multipleQuantity && quantity % multipleQuantity !== 0) {
19444
+ _this.spanInfo = 'La cantidad debe ser m\u00faltiplo de ' + multipleQuantity;
19445
+ }
19446
+ };
19447
+ _this.buildButtons = function (asociatedData) {
19448
+ var maximumNumberOfButtons = 6;
19449
+ if (asociatedData.multipleQuantity) {
19450
+ var maximum = asociatedData.maximumItemsQuantity || asociatedData.stock;
19451
+ var minimum = asociatedData.minimumItemsQuantity || asociatedData.multipleQuantity;
19452
+ var buttons = [];
19453
+ for (var i = minimum; i <= maximum; i = i + asociatedData.multipleQuantity) {
19454
+ buttons.push(i);
19455
+ }
19456
+ return buttons.length > maximumNumberOfButtons ? buttons.slice(0, maximumNumberOfButtons) : buttons;
19457
+ }
19458
+ return undefined;
19459
+ };
19328
19460
  _this.setQuantity = function (value, product) {
19329
19461
  var quantity = Number(value) > product.currentOption.stock ? product.currentOption.stock : Number(value);
19330
19462
  product.productToCartItem = {
@@ -19360,8 +19492,11 @@ var MultipleItemsToCartEcComponent = /** @class */ (function (_super) {
19360
19492
  return _this;
19361
19493
  }
19362
19494
  MultipleItemsToCartEcComponent.prototype.ngOnInit = function () {
19363
- var _a;
19495
+ var _a, _b, _c, _d, _e, _f, _g;
19364
19496
  this.product.productWithUniqueVariant = (_a = this.productService) === null || _a === void 0 ? void 0 : _a.getProductWithUniqueVariant(this.product, this.getObjectParamsWithVariant());
19497
+ var minQty = (_d = (_c = (_b = this.product) === null || _b === void 0 ? void 0 : _b.variants) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.minimumItemsQuantity;
19498
+ var multipleQty = (_g = (_f = (_e = this.product) === null || _e === void 0 ? void 0 : _e.variants) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.multipleQuantity;
19499
+ this.quantity = minQty || multipleQty || 1;
19365
19500
  this.ecOnInit();
19366
19501
  };
19367
19502
  MultipleItemsToCartEcComponent.ctorParameters = function () { return [