Commit 82667f75feb854354c7c92e756d54dfe65a49885

Authored by Eric Fernandez
Exists in master and in 1 other branch validar_pve

Merge branch 'master' into 'master'

Master(mpuebla)

See merge request !36
src/app/components/inicio/inicio.component.ts
... ... @@ -98,8 +98,7 @@ export class InicioComponent implements OnInit {
98 98 confirmarProducto() {
99 99 this.promoAcargar.cantidad = 1;
100 100 this.productoService.productos.push(this.promoAcargar);
101   - this.promoAcargar = undefined;
102   - this.productoAcargar = undefined;
  101 + this.productoService.productoAcargar = this.promoAcargar = this.productoAcargar = undefined;
103 102 this.promociones = [];
104 103 this.popoverDirective.hide();
105 104 }
... ... @@ -154,6 +153,8 @@ export class InicioComponent implements OnInit {
154 153 this.sinonimos = res;
155 154 if (res.length > 0)
156 155 this.showPopover();
  156 + else
  157 + this.popoverDirective.hide();
157 158 })
158 159 } else {
159 160 this.popoverDirective.hide();
... ... @@ -170,6 +171,7 @@ export class InicioComponent implements OnInit {
170 171 })
171 172  
172 173 this.promoAcargar.productos = productosPersonalizados;
  174 + this.confirmarProducto();
173 175 }
174 176  
175 177 buscarByCodigoBarras(busqueda) {
src/app/components/popover-sinonimos/popover-sinonimos.component.ts
... ... @@ -23,15 +23,20 @@ export class PopoverSinonimosComponent implements OnInit {
23 23  
24 24 ngOnInit() {
25 25  
26   - //Seteo en la variable a emitir el sinonimo que sea padre
27 26 this.popoverContent.forEach(sinonimo => {
28 27  
29 28 this.cantidadRestanteSinonimos.push(0);
30   - // this.sinonimo = sinonimo.productoPadre ? sinonimo : undefined;
31 29  
32   - sinonimo.productos.forEach(producto => {
  30 + sinonimo.productos.forEach((producto, index) => {
  31 +
  32 + if (producto.id === sinonimo.productoPadre) {
  33 + sinonimo.productos.splice(index, 1);
  34 + sinonimo.productos.splice(0, 0, producto);
  35 + producto.cantidad = sinonimo.cantidad;
  36 + } else {
  37 + producto.cantidad = 0;
  38 + }
33 39  
34   - producto.cantidad = (producto.id === sinonimo.productoPadre) ? sinonimo.cantidad : 0;
35 40 })
36 41 })
37 42 }
src/app/components/sidebar/sidebar.component.html
... ... @@ -24,34 +24,46 @@
24 24  
25 25 <!-- BOTONES -->
26 26 <div class="row m-0 d-flex justify-content-between">
  27 +
27 28 <!-- SUMAR - RESTAR CANTIDAD -->
28 29 <div class="col-auto px-1 my-2">
29 30 <div class="btn-group-sm btn-group float-left my-auto" role="group">
30   - <button type="button" class="btn btn-light btn-sm my-auto border" (click)="aumentarContador(i)">
  31 + <button
  32 + type="button"
  33 + class="btn btn-light btn-sm my-auto border shadow"
  34 + (click)="aumentarCantidad(producto)">
31 35 <i class="fa fa-plus" aria-hidden="true"></i>
32 36 </button>
33   - <div class="bg-white border border-white px-3 my-auto text-dark h5">
  37 + <div class="bg-white border border-white px-3 my-auto text-dark h5 shadow">
34 38 <small>{{producto.cantidad}}</small>
35 39 </div>
36   - <button type="button" class="btn btn-light btn-sm my-auto border" (click)="decrementarContador(i)">
  40 + <button
  41 + type="button"
  42 + class="btn btn-light btn-sm my-auto border shadow"
  43 + (click)="restarCantidad(producto)">
37 44 <i class="fa fa-minus" aria-hidden="true"></i>
38 45 </button>
39 46 </div>
40 47 </div>
  48 +
41 49 <!-- PERSONALIZAR -->
42 50 <div class="col-auto px-1 my-2">
43 51 <button
44 52 *ngIf="esPersonalizable(producto)"
45 53 type="button"
46   - class="btn btn-light btn-sm my-auto float-left border"
  54 + class="btn btn-light btn-sm my-auto float-left border shadow"
47 55 (click)="personalizarPromo">
48 56 <i class="fa fa-hand-o-up" aria-hidden="true"></i>
49 57 </button>
50 58 </div>
  59 +
51 60 <!-- BORRAR -->
52 61 <div class="col-auto px-1 my-2">
53   - <button type="button" class="btn btn-secondary btn-sm my-auto" (click)="deleteProducto(i)">
54   - <i class="fa fa-times" aria-hidden="true"></i>
  62 + <button
  63 + type="button"
  64 + class="btn btn-secondary btn-sm my-auto shadow"
  65 + (click)="deleteProducto(producto, i)">
  66 + <i class="fa fa-trash" aria-hidden="true"></i>
55 67 </button>
56 68 </div>
57 69 </div>
... ... @@ -62,13 +74,19 @@
62 74 <div class="card rounded-top-sm mt-auto blue-gradient border-0">
63 75 <div class="card-body row">
64 76 <div class="col-12">
65   - <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont === 1">({{cont}}) item</p>
66   - <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont > 1">({{cont}}) items</p>
  77 + <p
  78 + class="h4 border-bottom border-secondary text-secondary pb-2">
  79 + ({{getCantidadProductos()}}) items
  80 + </p>
67 81 <p class="h3 text-secondary">Total</p>
68 82 <p class="h3 font-weight-bold">{{getTotal() | currency}}</p>
69 83 </div>
70 84 <div class="col-12">
71   - <button type="button" class="btn btn-block btn-light btn-lg shadow mb-2 p-1" routerLink="/confirmacion-carrito">
  85 + <button
  86 + *ngIf="cantTotal > 0"
  87 + type="button"
  88 + class="btn btn-block btn-light btn-lg shadow mb-2 p-1"
  89 + routerLink="/confirmacion-carrito">
72 90 <span class="font-weight-bold pr-1">Finalizar y Pagar</span>
73 91 <i class="fa fa-check text-success" aria-hidden="true"></i>
74 92 </button>
src/app/components/sidebar/sidebar.component.ts
... ... @@ -3,7 +3,6 @@ import { Producto } from &#39;src/app/wrappers/producto&#39;;
3 3 import { appSettings } from 'src/etc/AppSettings';
4 4 import { ProductoService } from 'src/app/services/producto.service';
5 5  
6   -
7 6 @Component({
8 7 selector: 'app-sidebar',
9 8 templateUrl: './sidebar.component.html',
... ... @@ -11,93 +10,65 @@ import { ProductoService } from &#39;src/app/services/producto.service&#39;;
11 10 })
12 11 export class SidebarComponent implements OnInit {
13 12  
14   - private cont: number = 1;
15   - private min: number = 1;
16   - private max: number = 50;
  13 + private cantTotal: number = 0;
  14 + private cantMin: number = 1;
  15 + private cantMax: number = 50;
17 16 private total: number = 0;
18 17 private apiUrl: string = appSettings.apiUrl;
19 18  
20 19 public productosCarrito: Producto[] = [];
21 20  
22   - constructor(private productoService: ProductoService) {
23   -
24   - this.productosCarrito = this.productoService.productos;
25   - }
  21 + constructor(private productoService: ProductoService) { }
26 22  
27 23 ngOnInit() {
28 24  
  25 + this.productosCarrito = this.productoService.productos;
29 26 }
30 27  
31 28 getCantidadProductos() {
32 29  
33   - for (let i = 0; i < this.productosCarrito.length; i++) {
34   - this.productosCarrito[i].cantidad = 1
35   - this.cont++;
36   - }
37   - return this.cont;
  30 + setTimeout(() => {
  31 + var cantTotalAux = 0;
  32 + this.productosCarrito.forEach(producto => {
  33 +
  34 + cantTotalAux += producto.cantidad;
  35 + }, 250);
  36 + this.cantTotal = cantTotalAux;
  37 + })
  38 + return this.cantTotal;
38 39 }
39 40  
40 41 getTotal() {
41 42  
42   - let subTotal = 0;
  43 + var subTotal = 0;
43 44 for (let i = 0; i < this.productosCarrito.length; i++) {
44 45 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
45 46 }
46 47 return this.total = subTotal;
47 48 }
48 49  
49   - public aumentarContador(index) {
50   -
51   - this.cont++;
52   - for (let i = 0; i < this.productosCarrito.length; i++) {
53   - if (i === index) {
54   - this.total = this.total + this.productosCarrito[i].PreVen;
55   - return (this.productosCarrito[i].cantidad === this.max) ?
56   - this.productosCarrito[i].cantidad : this.productosCarrito[i].cantidad++;
57   -
58   - }
59   - }
60   - }
61   -
62   - decrementarContador(index) {
  50 + aumentarCantidad(producto: Producto) {
63 51  
64   - for (let i = 0; i < this.productosCarrito.length; i++) {
65   - if (i === index && this.productosCarrito[i].cantidad > this.min) {
66   - this.productosCarrito[i].cantidad--;
67   - this.cont--;
68   - break;
69   - }
  52 + if (producto.cantidad < this.cantMax) {
  53 + producto.cantidad++;
  54 + this.cantTotal++
70 55 }
71   -
72   - this.getTotal()
73 56 }
74 57  
75   - setCantidadItems() {
  58 + restarCantidad(producto: Producto) {
76 59  
77   - this.cont = 0;
78   - for (let i = 0; i < this.productosCarrito.length; i++) {
79   - this.cont += this.productosCarrito[i].cantidad;
80   - }
81   - }
82   -
83   - deleteProducto(index: number) {
84   -
85   - for (let i = 0; i < this.productosCarrito.length; i++) {
86   - if (i === index) {
87   - this.cont -= this.productosCarrito[i].cantidad;
88   - //Elimina del total el PreVen de todo el item
89   - this.total = this.total - (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
90   - this.productosCarrito.reverse().splice(i, 1);
91   - return;
92   - }
  60 + if (producto.cantidad > this.cantMin) {
  61 + producto.cantidad--;
  62 + this.cantTotal--;
93 63 }
94 64 }
95 65  
96   - cleanCarrito() {
  66 + deleteProducto(producto: Producto, index: number) {
97 67  
98   - this.productoService.productos = this.productosCarrito = [];
99   - this.total = 0;
100   - this.cont = 0;
  68 + this.cantTotal -= producto.cantidad;
  69 + this.total -= producto.PreVen * producto.cantidad;
  70 + this.productosCarrito.reverse().splice(index, 1);
  71 + return;
101 72 }
102 73  
103 74 esPersonalizable(producto: Producto) {