ng-easycommerce 0.0.572 → 0.0.573

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.
@@ -6110,6 +6110,8 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6110
6110
  this.promotions = [];
6111
6111
  this.cargando = false;
6112
6112
  this.channel = {};
6113
+ this.updateStock = false;
6114
+ this.exitUpdate = false;
6113
6115
  this.toDecimal = (amount) => this.consts.toDecimal(amount);
6114
6116
  this.actualizarCantidad = (item, cantidad, stock, id) => {
6115
6117
  if (id) {
@@ -6356,7 +6358,55 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6356
6358
  $('#' + id).modal('hide');
6357
6359
  }
6358
6360
  checkStock(item) {
6359
- return item.quantity > item.product.variants[0].stock;
6361
+ for (const variant of item.product.variants) {
6362
+ if (item.variant_id === variant.code) {
6363
+ if (variant.stock === 0) {
6364
+ this.updateStock = true;
6365
+ return '0';
6366
+ }
6367
+ else if (item.quantity > variant.stock) {
6368
+ this.updateStock = true;
6369
+ return variant.stock;
6370
+ }
6371
+ }
6372
+ }
6373
+ return false; // Solo se ejecuta si no se cumple la condición
6374
+ }
6375
+ updateAllStock() {
6376
+ const items = [];
6377
+ // Define la suscripción antes de usarla
6378
+ this.cartService.cartItems.subscribe(res => {
6379
+ res.forEach(item => {
6380
+ for (const variant of item.product.variants) {
6381
+ if (item.variant_id === variant.code && !this.exitUpdate) {
6382
+ if (variant.stock === 0) {
6383
+ this.cartService.deleteCartItem(item, false); // Borra el artículo
6384
+ }
6385
+ else if (item.quantity > variant.stock) {
6386
+ items.push({
6387
+ productCode: item.product.id,
6388
+ quantity: variant.stock,
6389
+ variantCode: variant.code,
6390
+ });
6391
+ }
6392
+ else {
6393
+ items.push({
6394
+ productCode: item.product.id,
6395
+ quantity: item.quantity,
6396
+ variantCode: variant.code,
6397
+ });
6398
+ }
6399
+ }
6400
+ }
6401
+ });
6402
+ if (items.length > 0 && !this.exitUpdate) {
6403
+ // subscription.unsubscribe(); // Desuscríbete antes de actualizar
6404
+ this.cartService.addAllToCart(items); // Actualiza el carrito
6405
+ this.updateStock = false;
6406
+ this.exitUpdate = true;
6407
+ // this.updateAllStock(); // Vuelve a verificar el stock
6408
+ }
6409
+ });
6360
6410
  }
6361
6411
  createDiscountMessage(saleprice, price) {
6362
6412
  if (isNaN(saleprice) || isNaN(price) || saleprice >= price || saleprice <= 0 || price <= 0) {