Commit 0b89cb8931e28c796181a3d251f07727559f589e
1 parent
260cc9aed1
Exists in
master
Logica para elegirProducto cuando es una promo.
Showing
1 changed file
with
16 additions
and
2 deletions
Show diff stats
src/app/components/busqueda-productos/busqueda-productos.component.ts
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
2 | import { ProductoService } from 'src/app/services/producto.service'; | 2 | import { ProductoService } from 'src/app/services/producto.service'; |
3 | import { Producto } from 'src/app/wrappers/producto'; | 3 | import { Producto } from 'src/app/wrappers/producto'; |
4 | import { Categoria } from 'src/app/wrappers/categoria'; | 4 | import { Categoria } from 'src/app/wrappers/categoria'; |
5 | import { appSettings } from 'src/etc/AppSettings'; | 5 | import { appSettings } from 'src/etc/AppSettings'; |
6 | import { Router } from '@angular/router'; | 6 | import { Router } from '@angular/router'; |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'app-busqueda-productos', | 9 | selector: 'app-busqueda-productos', |
10 | templateUrl: './busqueda-productos.component.html', | 10 | templateUrl: './busqueda-productos.component.html', |
11 | styleUrls: ['./busqueda-productos.component.scss'] | 11 | styleUrls: ['./busqueda-productos.component.scss'] |
12 | }) | 12 | }) |
13 | export class BusquedaProductosComponent implements OnInit { | 13 | export class BusquedaProductosComponent implements OnInit { |
14 | 14 | ||
15 | private productos: Producto[] = []; | 15 | private productos: Producto[] = []; |
16 | private auxProductos: Producto[] = []; | 16 | private auxProductos: Producto[] = []; |
17 | private searchTerm: string = ''; | 17 | private searchTerm: string = ''; |
18 | private categoriaActive: number = null; | 18 | private categoriaActive: number = null; |
19 | private showSpinner: boolean = true; | 19 | private showSpinner: boolean = true; |
20 | private verCategorias: boolean = true; | 20 | private verCategorias: boolean = true; |
21 | private apiUrl: string = appSettings.apiUrl; | 21 | private apiUrl: string = appSettings.apiUrl; |
22 | private categorias: Categoria[] = []; | 22 | private categorias: Categoria[] = []; |
23 | 23 | ||
24 | constructor( | 24 | constructor( |
25 | private productoService: ProductoService, | 25 | private productoService: ProductoService, |
26 | private router: Router) { } | 26 | private router: Router) { } |
27 | 27 | ||
28 | ngOnInit() { | 28 | ngOnInit() { |
29 | 29 | ||
30 | this.verCategorias = this.productoService.verCategoriasProductos; | 30 | this.verCategorias = this.productoService.verCategoriasProductos; |
31 | 31 | ||
32 | this.productoService.getCategorias() | 32 | this.productoService.getCategorias() |
33 | .subscribe((categorias: Categoria[]) => { | 33 | .subscribe((categorias: Categoria[]) => { |
34 | this.categorias = categorias; | 34 | this.categorias = categorias; |
35 | this.categoriaActive = this.verCategorias ? 1 : categorias[0].id; | 35 | this.categoriaActive = this.verCategorias ? 1 : categorias[0].id; |
36 | }); | 36 | }); |
37 | 37 | ||
38 | this.productoService.productoAcargar = undefined; | 38 | this.productoService.productoAcargar = undefined; |
39 | this.productoService.getAll() | 39 | this.productoService.getAll() |
40 | .subscribe((data: Producto[]) => { | 40 | .subscribe((data: Producto[]) => { |
41 | 41 | ||
42 | this.productos = data; | 42 | this.productos = data; |
43 | this.filterItems(); | 43 | this.filterItems(); |
44 | }, (error) => { | 44 | }, (error) => { |
45 | this.showSpinner = false; | 45 | this.showSpinner = false; |
46 | console.error(error); | 46 | console.error(error); |
47 | }); | 47 | }); |
48 | } | 48 | } |
49 | 49 | ||
50 | filterItems() { | 50 | filterItems() { |
51 | 51 | ||
52 | this.auxProductos = this.productos.filter(x => { | 52 | this.auxProductos = this.productos.filter(x => { |
53 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && | 53 | return x.DetArt.toLowerCase().includes(this.searchTerm.toLowerCase()) && |
54 | x.categoria_selfservice == this.categoriaActive; | 54 | x.categoria_selfservice == this.categoriaActive; |
55 | }); | 55 | }); |
56 | } | 56 | } |
57 | 57 | ||
58 | agregarAlCarrito(producto: Producto) { | 58 | agregarAlCarrito(producto: Producto) { |
59 | 59 | ||
60 | producto.cantidad = 1; | 60 | producto.cantidad = 1; |
61 | this.productoService.productos.push(producto); | 61 | this.productoService.productos.push(producto); |
62 | } | 62 | } |
63 | 63 | ||
64 | private elegirProducto(producto: Producto) { | 64 | private elegirProducto(producto: Producto) { |
65 | 65 | ||
66 | this.productoService.productoAcargar = producto; | 66 | if (producto.PRO) { |
67 | this.router.navigate(['inicio']); | 67 | |
68 | this.productoService.getPromocionByCodigos(producto.CodSec, producto.CodArt) | ||
69 | .subscribe(res => { | ||
70 | |||
71 | this.productoService.productoAcargar = res[0]; | ||
72 | this.router.navigate(['inicio']); | ||
73 | }, | ||
74 | error => { console.error(error); } | ||
75 | ); | ||
76 | }else { | ||
77 | |||
78 | this.productoService.productoAcargar = producto; | ||
79 | this.router.navigate(['inicio']); | ||
80 | } | ||
81 | |||
68 | } | 82 | } |
69 | } | 83 | } |
70 | 84 |