Commit 4f1673d9e01b14084bdac9ce68be34a2a8d93f8e
Exists in
master
Merge branch 'master' of git.focasoftware.com:angular/autoservicio
# Conflicts: # src/app/components/busqueda-productos/busqueda-productos.component.ts
Showing
1 changed file
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
| ... | ... | @@ -32,22 +32,23 @@ export class BusquedaProductosComponent implements OnInit { |
| 32 | 32 | |
| 33 | 33 | this.productoService.getCategorias() |
| 34 | 34 | .subscribe((categorias: Categoria[]) => { |
| 35 | - this.categorias = categorias; | |
| 36 | 35 | |
| 37 | 36 | switch (this.queMostrar) { |
| 38 | 37 | case 'todos': |
| 39 | - this.categoriaActive = 1; | |
| 38 | + this.categorias = categorias; | |
| 39 | + this.categoriaActive = 0; | |
| 40 | 40 | break; |
| 41 | 41 | case 'promociones': |
| 42 | + this.categorias = categorias; | |
| 42 | 43 | this.categoriaActive = 1; |
| 43 | 44 | break; |
| 44 | 45 | case 'ordenar': |
| 45 | 46 | |
| 46 | - this.categorias = this.categorias.filter((categoria: Categoria) => { | |
| 47 | + this.categorias = categorias.filter((categoria: Categoria) => { | |
| 47 | 48 | return categoria.ES_PEDIDO; |
| 48 | 49 | }); |
| 49 | 50 | |
| 50 | - this.categoriaActive = this.categorias[0].id; | |
| 51 | + this.categoriaActive = 0; | |
| 51 | 52 | |
| 52 | 53 | break; |
| 53 | 54 | default: |
| ... | ... | @@ -60,7 +61,20 @@ export class BusquedaProductosComponent implements OnInit { |
| 60 | 61 | this.productoService.getAll() |
| 61 | 62 | .subscribe((data: Producto[]) => { |
| 62 | 63 | |
| 63 | - this.productos = data; | |
| 64 | + if (this.queMostrar == 'ordenar') { | |
| 65 | + | |
| 66 | + this.categorias.forEach((categoria: Categoria) => { | |
| 67 | + | |
| 68 | + let tempProductos = data.filter((producto: Producto) => { | |
| 69 | + return producto.categoria_selfservice == categoria.id; | |
| 70 | + }); | |
| 71 | + | |
| 72 | + this.productos = this.productos.concat(tempProductos); | |
| 73 | + | |
| 74 | + }); | |
| 75 | + } else { | |
| 76 | + this.productos = data; | |
| 77 | + } | |
| 64 | 78 | this.filterItems(); |
| 65 | 79 | }, (error) => { |
| 66 | 80 | this.showSpinner = false; |
| ... | ... | @@ -72,13 +86,14 @@ export class BusquedaProductosComponent implements OnInit { |
| 72 | 86 | |
| 73 | 87 | this.auxProductos = this.productos.filter(x => { |
| 74 | 88 | if (this.categoriaActive === 0) { |
| 75 | - return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) | |
| 89 | + return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()); | |
| 76 | 90 | } |
| 77 | 91 | else { |
| 78 | 92 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
| 79 | 93 | x.categoria_selfservice === this.categoriaActive; |
| 80 | 94 | } |
| 81 | 95 | }); |
| 96 | + | |
| 82 | 97 | } |
| 83 | 98 | |
| 84 | 99 | agregarAlCarrito(producto: Producto) { |