Commit 55a68043f082c9f0ee76b9b2a8555d7e2380fbee

Authored by Marcelo Puebla
1 parent b695e77f11
Exists in master and in 1 other branch validar_pve

Logica empezada para poder personalizar un producto en el carrito,

src/app/components/sidebar/sidebar.component.html
1 <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center"> 1 <div class="disable-user-select d-flex align-items-center flex-column h-100 pt-2 text-center">
2 2
3 <p class="h4 border-bottom border-white text-white mt-4 pb-2"> 3 <p class="h4 border-bottom border-white text-white mt-4 pb-2">
4 Mi compra 4 Mi compra
5 <i class="fa fa-shopping-cart" aria-hidden="true"></i> 5 <i class="fa fa-shopping-cart" aria-hidden="true"></i>
6 </p> 6 </p>
7 7
8 <div class="overflow-auto overflow-scroll mb-2 w-100"> 8 <div class="overflow-auto overflow-scroll mb-2 w-100">
9 <!-- PRODUCTOS CARRITO --> 9 <!-- PRODUCTOS CARRITO -->
10 <div 10 <div
11 class="slide-in-bl my-2 bg-white border-0 rounded-sm" 11 class="slide-in-bl my-2 bg-white border-0 rounded-sm"
12 *ngFor="let producto of productosCarrito.slice().reverse(); let i = index"> 12 *ngFor="let producto of productosCarrito.slice().reverse(); let i = index">
13 <img class="w-100 m-auto rounded-sm shadow" src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}"> 13 <!-- <img class="w-100 m-auto rounded-sm shadow" src="{{apiUrl}}/imagenes/{{producto.imagenes[0].imagen}}"> -->
14 <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm"> 14 <div class="row m-0 p-0 px-1 py-1 shadow rounded-sm">
15 <div class="col-12 p-0 pt-2 text-left my-auto"> 15 <div class="col-12 p-0 pt-2 text-left my-auto">
16 <p class="m-0 h6"><small>{{producto.DetArt}}</small></p> 16 <p class="m-0 h6"><small>{{producto.DetArt}}</small></p>
17 <p class="m-0 h6"><small>COD: {{producto.CodRub}}</small></p> 17 <p class="m-0 h6"><small>COD: {{producto.CodRub}}</small></p>
18 </div> 18 </div>
19 <div class="col-12 pr-1 text-right h6 my-auto "> 19 <div class="col-12 pr-1 text-right h6 my-auto ">
20 <p class="m-0">{{producto.PreVen | currency}}</p> 20 <p class="m-0">{{producto.PreVen | currency}}</p>
21 </div> 21 </div>
22 </div> 22 </div>
23 <div class="row m-0 p-0"> 23 <div class="row m-0 p-0">
24 <div class="col-6 px-2 my-2"> 24 <div class="col-6 px-2 my-2">
25 <div class="btn-group-sm btn-group float-left my-auto" role="group"> 25 <div class="btn-group-sm btn-group float-left my-auto" role="group">
26 <button type="button" class="btn btn-light btn-sm my-auto border" (click)="aumentarContador(i)"> 26 <button type="button" class="btn btn-light btn-sm my-auto border" (click)="aumentarContador(i)">
27 <i class="fa fa-plus" aria-hidden="true"></i> 27 <i class="fa fa-plus" aria-hidden="true"></i>
28 </button> 28 </button>
29 <div class="bg-white border border-white px-3 my-auto text-dark h5"> 29 <div class="bg-white border border-white px-3 my-auto text-dark h5">
30 <small>{{producto.cantidad}}</small> 30 <small>{{producto.cantidad}}</small>
31 </div> 31 </div>
32 <button type="button" class="btn btn-light btn-sm my-auto border" (click)="decrementarContador(i)"> 32 <button type="button" class="btn btn-light btn-sm my-auto border" (click)="decrementarContador(i)">
33 <i class="fa fa-minus" aria-hidden="true"></i> 33 <i class="fa fa-minus" aria-hidden="true"></i>
34 </button> 34 </button>
35 </div> 35 </div>
36 </div> 36 </div>
37 <div class="col-6 px-2 my-2"> 37 <div class="col-6 px-2 my-2">
38 <div class="btn-group-sm btn-group float-right my-auto" role="group"> 38 <div class="btn-group-sm btn-group float-right my-auto" role="group">
39 <button type="button" class="btn btn-light btn-sm my-auto float-left border mr-2"> 39 <button
40 *ngIf="esPersonalizable(producto)"
41 type="button"
42 class="btn btn-light btn-sm my-auto float-left border mr-2"
43 (click)="personalizarPromo">
40 <i class="fa fa-hand-o-up" aria-hidden="true"></i> 44 <i class="fa fa-hand-o-up" aria-hidden="true"></i>
41 </button> 45 </button>
42 <button type="button" class="btn btn-secondary btn-sm my-auto ml-2" (click)="deleteProducto(i)"> 46 <button type="button" class="btn btn-secondary btn-sm my-auto ml-2" (click)="deleteProducto(i)">
43 <i class="fa fa-times" aria-hidden="true"></i> 47 <i class="fa fa-times" aria-hidden="true"></i>
44 </button> 48 </button>
45 </div> 49 </div>
46 </div> 50 </div>
47 </div> 51 </div>
48 </div> 52 </div>
49 </div> 53 </div>
50 54
51 <!-- TOTAL --> 55 <!-- TOTAL -->
52 <div class="card rounded-top-sm mt-auto blue-gradient border-0"> 56 <div class="card rounded-top-sm mt-auto blue-gradient border-0">
53 <div class="card-body row"> 57 <div class="card-body row">
54 <div class="col-12"> 58 <div class="col-12">
55 <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont === 1">({{cont}}) item</p> 59 <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont === 1">({{cont}}) item</p>
56 <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont > 1">({{cont}}) items</p> 60 <p class="h4 border-bottom border-secondary text-secondary pb-2" *ngIf="cont > 1">({{cont}}) items</p>
57 <p class="h3 text-secondary">Total</p> 61 <p class="h3 text-secondary">Total</p>
58 <p class="h3 font-weight-bold">{{getTotal() | currency}}</p> 62 <p class="h3 font-weight-bold">{{getTotal() | currency}}</p>
59 </div> 63 </div>
60 <div class="col-12"> 64 <div class="col-12">
61 <button type="button" class="btn btn-block btn-light btn-lg shadow mb-2 p-1" routerLink="/confirmacion-carrito"> 65 <button type="button" class="btn btn-block btn-light btn-lg shadow mb-2 p-1" routerLink="/confirmacion-carrito">
62 <span class="font-weight-bold pr-1">Finalizar y Pagar</span> 66 <span class="font-weight-bold pr-1">Finalizar y Pagar</span>
63 <i class="fa fa-check text-success" aria-hidden="true"></i> 67 <i class="fa fa-check text-success" aria-hidden="true"></i>
64 </button> 68 </button>
65 <button 69 <button
66 type="button" 70 type="button"
67 class="btn btn-block btn-light shadow btn-sm shadow" 71 class="btn btn-block btn-light shadow btn-sm shadow"
68 [routerLink]="['/cancelar-compra']"> 72 [routerLink]="['/cancelar-compra']">
69 <span class="pr-1">Cancelar</span> 73 <span class="pr-1">Cancelar</span>
70 <i class="fa fa-times text-danger" aria-hidden="true"></i> 74 <i class="fa fa-times text-danger" aria-hidden="true"></i>
71 </button> 75 </button>
72 </div> 76 </div>
73 </div> 77 </div>
74 </div> 78 </div>
75 </div> 79 </div>
76 80
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 5
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 cont: number = 1; 14 private cont: number = 1;
15 private min: number = 1; 15 private min: number = 1;
16 private max: number = 50; 16 private max: 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(private productoService: ProductoService) { 22 constructor(private productoService: ProductoService) {
23 23
24 this.productosCarrito = this.productoService.productos; 24 this.productosCarrito = this.productoService.productos;
25 } 25 }
26 26
27 ngOnInit() { 27 ngOnInit() {
28 28
29 } 29 }
30 30
31 getCantidadProductos() { 31 getCantidadProductos() {
32 32
33 for (let i = 0; i < this.productosCarrito.length; i++) { 33 for (let i = 0; i < this.productosCarrito.length; i++) {
34 this.productosCarrito[i].cantidad = 1 34 this.productosCarrito[i].cantidad = 1
35 this.cont++; 35 this.cont++;
36 } 36 }
37 return this.cont; 37 return this.cont;
38 } 38 }
39 39
40 getTotal() { 40 getTotal() {
41 41
42 let subTotal = 0; 42 let subTotal = 0;
43 for (let i = 0; i < this.productosCarrito.length; i++) { 43 for (let i = 0; i < this.productosCarrito.length; i++) {
44 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); 44 subTotal = subTotal + (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
45 } 45 }
46 return this.total = subTotal; 46 return this.total = subTotal;
47 } 47 }
48 48
49 public aumentarContador(index) { 49 public aumentarContador(index) {
50 50
51 this.cont++; 51 this.cont++;
52 for (let i = 0; i < this.productosCarrito.length; i++) { 52 for (let i = 0; i < this.productosCarrito.length; i++) {
53 if (i === index) { 53 if (i === index) {
54 this.total = this.total + this.productosCarrito[i].PreVen; 54 this.total = this.total + this.productosCarrito[i].PreVen;
55 return (this.productosCarrito[i].cantidad === this.max) ? 55 return (this.productosCarrito[i].cantidad === this.max) ?
56 this.productosCarrito[i].cantidad : this.productosCarrito[i].cantidad++; 56 this.productosCarrito[i].cantidad : this.productosCarrito[i].cantidad++;
57 57
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 decrementarContador(index) { 62 decrementarContador(index) {
63 63
64 for (let i = 0; i < this.productosCarrito.length; i++) { 64 for (let i = 0; i < this.productosCarrito.length; i++) {
65 if (i === index && this.productosCarrito[i].cantidad > this.min) { 65 if (i === index && this.productosCarrito[i].cantidad > this.min) {
66 this.productosCarrito[i].cantidad--; 66 this.productosCarrito[i].cantidad--;
67 this.cont--; 67 this.cont--;
68 break; 68 break;
69 } 69 }
70 } 70 }
71 71
72 this.getTotal() 72 this.getTotal()
73 } 73 }
74 74
75 setCantidadItems() { 75 setCantidadItems() {
76 76
77 this.cont = 0; 77 this.cont = 0;
78 for (let i = 0; i < this.productosCarrito.length; i++) { 78 for (let i = 0; i < this.productosCarrito.length; i++) {
79 this.cont += this.productosCarrito[i].cantidad; 79 this.cont += this.productosCarrito[i].cantidad;
80 } 80 }
81 } 81 }
82 82
83 deleteProducto(index: number) { 83 deleteProducto(index: number) {
84 84
85 for (let i = 0; i < this.productosCarrito.length; i++) { 85 for (let i = 0; i < this.productosCarrito.length; i++) {
86 if (i === index) { 86 if (i === index) {
87 this.cont -= this.productosCarrito[i].cantidad; 87 this.cont -= this.productosCarrito[i].cantidad;
88 //Elimina del total el PreVen de todo el item 88 //Elimina del total el PreVen de todo el item
89 this.total = this.total - (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad); 89 this.total = this.total - (this.productosCarrito[i].PreVen * this.productosCarrito[i].cantidad);
90 this.productosCarrito.reverse().splice(i, 1); 90 this.productosCarrito.reverse().splice(i, 1);
91 return; 91 return;
92 } 92 }
93 } 93 }
94 } 94 }
95 95
96 cleanCarrito() { 96 cleanCarrito() {
97 97
98 this.productoService.productos = this.productosCarrito = []; 98 this.productoService.productos = this.productosCarrito = [];
99 this.total = 0; 99 this.total = 0;
100 this.cont = 0; 100 this.cont = 0;
101 } 101 }
102
103 esPersonalizable(producto: Producto) {
104
105 var esPersonalizable: boolean = false;
106 if (producto.tieneSinonimos)
107 esPersonalizable = true;
108
109 return esPersonalizable;
110 }
111
102 } 112 }
103 113