Commit 0b977744143a58515257f815b86966a388a241f0
Exists in
master
and in
1 other branch
Merge branch 'master' into 'master'
Master(mpuebla) See merge request !62
Showing
3 changed files
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
| ... | ... | @@ -61,6 +61,8 @@ export class BusquedaProductosComponent implements OnInit { |
| 61 | 61 | this.productoService.getAll() |
| 62 | 62 | .subscribe((data: Producto[]) => { |
| 63 | 63 | |
| 64 | + this.setProductosSinImagen(data); | |
| 65 | + | |
| 64 | 66 | if (this.queMostrar == 'ordenar') { |
| 65 | 67 | |
| 66 | 68 | this.categorias.forEach((categoria: Categoria) => { |
| ... | ... | @@ -127,4 +129,12 @@ export class BusquedaProductosComponent implements OnInit { |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | } |
| 132 | + | |
| 133 | + private setProductosSinImagen(productos: Producto[]) { | |
| 134 | + | |
| 135 | + productos.forEach((producto: Producto) => { | |
| 136 | + producto.imagenes = producto.imagenes.length == 0 ? | |
| 137 | + [{ imagen: 'noImage.jpg' }] : producto.imagenes; | |
| 138 | + }) | |
| 139 | + } | |
| 130 | 140 | } |
src/app/components/inicio/inicio.component.ts
| ... | ... | @@ -80,7 +80,7 @@ export class InicioComponent implements OnInit, AfterViewInit { |
| 80 | 80 | if (res.length === 0) { |
| 81 | 81 | |
| 82 | 82 | this.productoAcargar.cantidad = 1; |
| 83 | - this.productoService.productos.push(this.productoAcargar); | |
| 83 | + this.productoService.setProductos(this.productoAcargar); | |
| 84 | 84 | this.productoAcargar = this.productoService.productoAcargar = undefined; |
| 85 | 85 | } else { |
| 86 | 86 | |
| ... | ... | @@ -94,7 +94,7 @@ export class InicioComponent implements OnInit, AfterViewInit { |
| 94 | 94 | |
| 95 | 95 | var producto = this.promoAcargar ? this.promoAcargar : this.productoAcargar; |
| 96 | 96 | producto.cantidad = 1; |
| 97 | - this.productoService.productos.push(producto); | |
| 97 | + this.productoService.setProductos(producto); | |
| 98 | 98 | this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined; |
| 99 | 99 | this.promociones = []; |
| 100 | 100 | this.popoverDirective.hide(); |
src/app/services/producto.service.ts
| ... | ... | @@ -28,6 +28,23 @@ export class ProductoService { |
| 28 | 28 | |
| 29 | 29 | setProductos(producto: Producto) { |
| 30 | 30 | |
| 31 | + for (let i = 0; i < this.productos.length; i++) { | |
| 32 | + | |
| 33 | + if (this.productos[i].id === producto.id) { | |
| 34 | + | |
| 35 | + if (producto.PRO) { | |
| 36 | + if (this.promosIdenticas(this.productos[i], producto)) { | |
| 37 | + this.productos[i].cantidad++; | |
| 38 | + return; | |
| 39 | + } else { | |
| 40 | + break; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + this.productos[i].cantidad++; | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 31 | 48 | this.productos.push(producto); |
| 32 | 49 | } |
| 33 | 50 | |
| ... | ... | @@ -66,4 +83,24 @@ export class ProductoService { |
| 66 | 83 | }); |
| 67 | 84 | } |
| 68 | 85 | |
| 86 | + private promosIdenticas(promoEnCarrito: Producto, promo: Producto) { | |
| 87 | + | |
| 88 | + var sonIdenticas = true; | |
| 89 | + var productosPromoCarrito = promoEnCarrito.productos; | |
| 90 | + var productosPromoAcargar = promo.productos; | |
| 91 | + | |
| 92 | + if (productosPromoCarrito.length !== productosPromoAcargar.length) { | |
| 93 | + return false; | |
| 94 | + } | |
| 95 | + | |
| 96 | + for (let i = 0; i < productosPromoCarrito.length; i++) { | |
| 97 | + | |
| 98 | + if (productosPromoCarrito[i].id !== productosPromoAcargar[i].id) { | |
| 99 | + return false; | |
| 100 | + } | |
| 101 | + } | |
| 102 | + | |
| 103 | + return sonIdenticas; | |
| 104 | + } | |
| 105 | + | |
| 69 | 106 | } |