From 4062317f9fa5dc22e2e4974d5745803faf7132d1 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Thu, 22 Aug 2019 17:44:58 -0300 Subject: [PATCH] filtros categorias --- .../busqueda-productos.component.ts | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/components/busqueda-productos/busqueda-productos.component.ts b/src/app/components/busqueda-productos/busqueda-productos.component.ts index b8962b5..bb6664e 100644 --- a/src/app/components/busqueda-productos/busqueda-productos.component.ts +++ b/src/app/components/busqueda-productos/busqueda-productos.component.ts @@ -32,18 +32,19 @@ export class BusquedaProductosComponent implements OnInit { this.productoService.getCategorias() .subscribe((categorias: Categoria[]) => { - this.categorias = categorias; switch (this.queMostrar) { case 'todos': - this.categoriaActive = 1; + this.categorias = categorias; + this.categoriaActive = 0; break; case 'promociones': + this.categorias = categorias; this.categoriaActive = 1; break; case 'ordenar': - this.categorias = this.categorias.filter((categoria: Categoria) => { + this.categorias = categorias.filter((categoria: Categoria) => { return categoria.ES_PEDIDO; }); @@ -60,7 +61,20 @@ export class BusquedaProductosComponent implements OnInit { this.productoService.getAll() .subscribe((data: Producto[]) => { - this.productos = data; + if (this.queMostrar == 'ordenar') { + + this.categorias.forEach((categoria: Categoria) => { + + let tempProductos = data.filter((producto: Producto) => { + return producto.categoria_selfservice == categoria.id; + }); + + this.productos = this.productos.concat(tempProductos); + + }); + } else { + this.productos = data; + } this.filterItems(); }, (error) => { this.showSpinner = false; @@ -72,13 +86,14 @@ export class BusquedaProductosComponent implements OnInit { this.auxProductos = this.productos.filter(x => { if (this.categoriaActive === 0) { - return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) + return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()); } else { return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && x.categoria_selfservice === this.categoriaActive; } }); + } agregarAlCarrito(producto: Producto) { -- 1.9.1