diff --git a/src/app/components/inicio/inicio.component.ts b/src/app/components/inicio/inicio.component.ts index d4a9956..3e4abfc 100644 --- a/src/app/components/inicio/inicio.component.ts +++ b/src/app/components/inicio/inicio.component.ts @@ -5,6 +5,7 @@ import { Producto } from 'src/app/wrappers/producto'; import { ProductoService } from 'src/app/services/producto.service'; import { Router } from '@angular/router'; import { Promocion } from 'src/app/wrappers/promocion'; +import { Sinonimo } from 'src/app/wrappers/sinonimo'; @Component({ @@ -20,7 +21,8 @@ export class InicioComponent implements OnInit { private tienePromo = false; private productoEsPromo = false; - popoverContent: Promocion[] = [] + promociones: Promocion[] = []; + sinonimos: Sinonimo[] = []; apiUrl: string = appSettings.apiUrl constructor( @@ -34,9 +36,9 @@ export class InicioComponent implements OnInit { var sector = this.productoAcargar.CodSec; var codigo = this.productoAcargar.CodArt; this.productoService.getPromocion(sector, codigo) - .subscribe((promociones: Promocion[]) => { + .subscribe((res: Promocion[]) => { - if (promociones.length === 0) { + if (res.length === 0) { //Si no tiene promociones la cargará al carrito despues de un tiempo setTimeout(() => { this.productoService.productos.push(this.productoAcargar); @@ -45,7 +47,7 @@ export class InicioComponent implements OnInit { }, 2000) } else { - this.popoverContent = promociones; + this.promociones = res; this.tienePromo = true; this.popoverDirective.show(); } @@ -64,22 +66,32 @@ export class InicioComponent implements OnInit { } deshacerCarga() { - if(this.productoEsPromo) { - this.promoAcargar = undefined; + if (this.productoEsPromo) { + this.promoAcargar = undefined; this.productoEsPromo = false; this.popoverDirective.show(); - }else{ + } else { this.productoAcargar = undefined; this.tienePromo = false; this.popoverDirective.hide(); } } - - promoSeleccionada($event : Promocion){ - + + promoSeleccionada($event: Promocion) { + this.productoEsPromo = true; this.promoAcargar = $event; this.popoverDirective.hide(); + if (this.promoAcargar.sinonimos) { + var sector = this.promoAcargar.sector; + var codigo = this.promoAcargar.codigo; + this.productoService.getPromocionSinonimos(sector, codigo) + .subscribe((res : Sinonimo[]) => { + + this.sinonimos = res; + this.showPopover(); + }) + } } }