Skip to content

Commit 316e2cb

Browse files
committed
20240708_004
1 parent 80a526c commit 316e2cb

File tree

3 files changed

+101
-117
lines changed

3 files changed

+101
-117
lines changed

Entregas/PruebasEntrega/hechoPorMi/js/cart.js

Lines changed: 0 additions & 116 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
listarProductosCarrito();
3+
4+
function listarProductosCarrito(){
5+
6+
// Obtener el carrito desde localStorage
7+
let carrito = JSON.parse(localStorage.getItem('carrito')) || [];
8+
9+
// Agrupar los productos por id
10+
let productosAgrupados = carrito.reduce((acc, producto) => {
11+
if (!acc[producto.id]) {
12+
acc[producto.id] = { ...producto, cantidad: 0 };
13+
}
14+
acc[producto.id].cantidad += 1;
15+
return acc;
16+
}, {});
17+
18+
// Convertir el objeto en un array
19+
productosAgrupados = Object.values(productosAgrupados);
20+
21+
// Obtener el contenedor del carrito
22+
const carritoContainer = document.getElementById('carrito-items');
23+
24+
// Mostrar los productos agrupados en el contenedor
25+
productosAgrupados.forEach(producto => {
26+
27+
const total = producto.precio*producto.cantidad;
28+
const productoElemento = document.createElement('tr');
29+
30+
productoElemento.innerHTML = `
31+
<tbody>
32+
<tr>
33+
<TD> ${producto.nombre} </TD>
34+
<TD> ${producto.precio} $ </TD>
35+
<TD> ${producto.cantidad} </TD>
36+
<TD> ${total} $ </TD>
37+
</tr>
38+
</tbody>
39+
40+
41+
`;
42+
carritoContainer.appendChild(productoElemento);
43+
});
44+
totalCarrito()
45+
}
46+
/**
47+
* Lo saue del inner de arriba:
48+
*
49+
* <td class="cantidadBTN">
50+
<button onclick="bajaCantidad()"> BAJAR </button>
51+
<button onclick="subirCantidad()"> SUBIR </button>
52+
</td>
53+
*/
54+
55+
56+
57+
function totalCarrito(){
58+
let IVA=22;
59+
let carrito = JSON.parse(localStorage.getItem('carrito')) || [];
60+
61+
// Obtener el contenedor del carrito
62+
const carritoTtoal = document.getElementById('carrito-values');
63+
64+
// Calcular el total de los precios
65+
let total = 0;
66+
carrito.forEach(item => {
67+
total += item.precio;
68+
});
69+
70+
// Crear la tabla HTML dinámicamente
71+
const tabla = document.createElement('tr');
72+
let aPagar=total+(total*(IVA)/100);
73+
tabla.innerHTML = `
74+
<tbody>
75+
<Tr>
76+
<Td> ${total} </Td>
77+
<Td> ${IVA}% </Td>
78+
<Td> </Th>
79+
<Td> ${aPagar} </Td>
80+
</Tr>
81+
</tbody>
82+
`;
83+
carritoTtoal.innerHTML = '';
84+
carritoTtoal.appendChild(tabla);
85+
86+
}//FIN DEL SCRIPT

Entregas/PruebasEntrega/hechoPorMi/src/views/ComprasCarrito.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ <h1>COMPRAS REALIZADAS</h1>
3535
</Thead>
3636
<tbody id="carrito-items"></tbody>
3737
</TABLE><BR>
38-
<DIV class="button-buy">
38+
39+
40+
<table class="producto-tabla">
41+
<Thead>
42+
<Tr>
43+
<TH> SUBTOTAL </TH>
44+
<TH> IVA </Th>
45+
<Th> </Th>
46+
<Th> TOTAL </Th>
47+
</Tr>
48+
</Thead>
49+
<tbody id="carrito-values"></tbody>
50+
51+
</table>
52+
<DIV class="button-buy">
3953
<button class="btn002" onclick="comprarCarrito()"> COMPRAR </button></DIV>
4054
</div>
4155

0 commit comments

Comments
 (0)