Commit ac0476557b8e66d7708ecf48ca9c5c486947924a

Authored by Marcelo Puebla
1 parent 736faa380a
Exists in master

Agregado logica para traer los sinonimos de promociones.

Showing 1 changed file with 22 additions and 10 deletions   Show diff stats
src/app/components/inicio/inicio.component.ts
... ... @@ -5,6 +5,7 @@ import { Producto } from 'src/app/wrappers/producto';
5 5 import { ProductoService } from 'src/app/services/producto.service';
6 6 import { Router } from '@angular/router';
7 7 import { Promocion } from 'src/app/wrappers/promocion';
  8 +import { Sinonimo } from 'src/app/wrappers/sinonimo';
8 9  
9 10  
10 11 @Component({
... ... @@ -20,7 +21,8 @@ export class InicioComponent implements OnInit {
20 21 private tienePromo = false;
21 22 private productoEsPromo = false;
22 23  
23   - popoverContent: Promocion[] = []
  24 + promociones: Promocion[] = [];
  25 + sinonimos: Sinonimo[] = [];
24 26 apiUrl: string = appSettings.apiUrl
25 27  
26 28 constructor(
... ... @@ -34,9 +36,9 @@ export class InicioComponent implements OnInit {
34 36 var sector = this.productoAcargar.CodSec;
35 37 var codigo = this.productoAcargar.CodArt;
36 38 this.productoService.getPromocion(sector, codigo)
37   - .subscribe((promociones: Promocion[]) => {
  39 + .subscribe((res: Promocion[]) => {
38 40  
39   - if (promociones.length === 0) {
  41 + if (res.length === 0) {
40 42 //Si no tiene promociones la cargará al carrito despues de un tiempo
41 43 setTimeout(() => {
42 44 this.productoService.productos.push(this.productoAcargar);
... ... @@ -45,7 +47,7 @@ export class InicioComponent implements OnInit {
45 47 }, 2000)
46 48 } else {
47 49  
48   - this.popoverContent = promociones;
  50 + this.promociones = res;
49 51 this.tienePromo = true;
50 52 this.popoverDirective.show();
51 53 }
... ... @@ -64,22 +66,32 @@ export class InicioComponent implements OnInit {
64 66 }
65 67  
66 68 deshacerCarga() {
67   - if(this.productoEsPromo) {
68   - this.promoAcargar = undefined;
  69 + if (this.productoEsPromo) {
  70 + this.promoAcargar = undefined;
69 71 this.productoEsPromo = false;
70 72 this.popoverDirective.show();
71   - }else{
  73 + } else {
72 74 this.productoAcargar = undefined;
73 75 this.tienePromo = false;
74 76 this.popoverDirective.hide();
75 77 }
76 78 }
77   -
78   - promoSeleccionada($event : Promocion){
79   -
  79 +
  80 + promoSeleccionada($event: Promocion) {
  81 +
80 82 this.productoEsPromo = true;
81 83 this.promoAcargar = $event;
82 84 this.popoverDirective.hide();
  85 + if (this.promoAcargar.sinonimos) {
  86 + var sector = this.promoAcargar.sector;
  87 + var codigo = this.promoAcargar.codigo;
  88 + this.productoService.getPromocionSinonimos(sector, codigo)
  89 + .subscribe((res : Sinonimo[]) => {
  90 +
  91 + this.sinonimos = res;
  92 + this.showPopover();
  93 + })
  94 + }
83 95 }
84 96  
85 97 }