Commit 79da0a8fc606029ba6c88df9fcc1be5040fc3f27

Authored by Marcelo Puebla
1 parent 81dc2dfae2
Exists in master

Borrado metodo.

src/app/components/sidebar/sidebar.component.ts
1 import { Component, OnInit } from '@angular/core'; 1 import { Component, OnInit } from '@angular/core';
2 import { Producto } from 'src/app/wrappers/producto'; 2 import { Producto } from 'src/app/wrappers/producto';
3 import { appSettings } from 'src/etc/AppSettings'; 3 import { appSettings } from 'src/etc/AppSettings';
4 import { ProductoService } from 'src/app/services/producto.service'; 4 import { ProductoService } from 'src/app/services/producto.service';
5 import { Router } from '@angular/router'; 5 import { Router } from '@angular/router';
6 6
7 @Component({ 7 @Component({
8 selector: 'app-sidebar', 8 selector: 'app-sidebar',
9 templateUrl: './sidebar.component.html', 9 templateUrl: './sidebar.component.html',
10 styleUrls: ['./sidebar.component.scss'], 10 styleUrls: ['./sidebar.component.scss'],
11 }) 11 })
12 export class SidebarComponent implements OnInit { 12 export class SidebarComponent implements OnInit {
13 13
14 private cantTotal: number = 0; 14 private cantTotal: number = 0;
15 private cantMin: number = 1; 15 private cantMin: number = 1;
16 private cantMax: number = 50; 16 private cantMax: number = 50;
17 private total: number = 0; 17 private total: number = 0;
18 private apiUrl: string = appSettings.apiUrl; 18 private apiUrl: string = appSettings.apiUrl;
19 19
20 public productosCarrito: Producto[] = []; 20 public productosCarrito: Producto[] = [];
21 21
22 constructor( 22 constructor(
23 private productoService: ProductoService, 23 private productoService: ProductoService,
24 private router: Router) { 24 private router: Router) {
25 this.router.routeReuseStrategy.shouldReuseRoute = function () { 25 this.router.routeReuseStrategy.shouldReuseRoute = function () {
26 return false; 26 return false;
27 } 27 }
28 } 28 }
29 29
30 ngOnInit() { 30 ngOnInit() {
31 31
32 this.productosCarrito = this.productoService.productos; 32 this.productosCarrito = this.productoService.productos;
33 } 33 }
34 34
35 getCantidadProductos() { 35 getCantidadProductos() {
36 36
37 setTimeout(() => { 37 setTimeout(() => {
38 var cantTotalAux = 0; 38 var cantTotalAux = 0;
39 this.productosCarrito.forEach(producto => { 39 this.productosCarrito.forEach(producto => {
40 40
41 cantTotalAux += producto.cantidad; 41 cantTotalAux += producto.cantidad;
42 }, 250); 42 }, 250);
43 this.cantTotal = cantTotalAux; 43 this.cantTotal = cantTotalAux;
44 }) 44 })
45 return this.cantTotal; 45 return this.cantTotal;
46 } 46 }
47 47
48 getTotal() { 48 getTotal() {
49 49
50 var subTotal = 0; 50 var subTotal = 0;
51 for (let i = 0; i < this.productosCarrito.length; i++) { 51 for (let i = 0; i < this.productosCarrito.length; i++) {
52 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); 52 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
53 } 53 }
54 return this.total = subTotal; 54 return this.total = subTotal;
55 } 55 }
56 56
57 aumentarCantidad(producto: Producto) { 57 aumentarCantidad(producto: Producto) {
58 58
59 if (producto.cantidad < this.cantMax) { 59 if (producto.cantidad < this.cantMax) {
60 producto.cantidad++; 60 producto.cantidad++;
61 this.cantTotal++ 61 this.cantTotal++
62 } 62 }
63 } 63 }
64 64
65 restarCantidad(producto: Producto) { 65 restarCantidad(producto: Producto) {
66 66
67 if (producto.cantidad > this.cantMin) { 67 if (producto.cantidad > this.cantMin) {
68 producto.cantidad--; 68 producto.cantidad--;
69 this.cantTotal--; 69 this.cantTotal--;
70 } 70 }
71 } 71 }
72 72
73 deleteProducto(producto: Producto, index: number) { 73 deleteProducto(producto: Producto, index: number) {
74 74
75 this.cantTotal -= producto.cantidad; 75 this.cantTotal -= producto.cantidad;
76 this.total -= producto.PreVen * producto.cantidad; 76 this.total -= producto.PreVen * producto.cantidad;
77 this.productosCarrito.reverse().splice(index, 1); 77 this.productosCarrito.reverse().splice(index, 1);
78 return; 78 return;
79 } 79 }
80 80
81 esPersonalizable(producto: Producto) {
82
83 var esPersonalizable: boolean = false;
84 if (producto.tieneSinonimos)
85 esPersonalizable = true;
86
87 return esPersonalizable;
88 }
89
90 personalizarPromo(producto: Producto, index) { 81 personalizarPromo(producto: Producto, index) {
91 82
92 this.productoService.productoAcargar = producto; 83 this.productoService.productoAcargar = producto;
93 this.deleteProducto(producto, index); 84 this.deleteProducto(producto, index);
94 this.router.navigate(['inicio']); 85 this.router.navigate(['inicio']);
95 } 86 }
96 87
97 } 88 }
98 89