Skip to content

Commit 9930831

Browse files
committed
correcciones de codigo menores
1 parent 4632bf0 commit 9930831

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

css/styles.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/styles.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/carrito.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ function obtenerprodsPagPpalLS() {
44

55
const prodsPagPpal = obtenerprodsPagPpalLS();
66

7-
const guardarCarritoLS = (prods) => {
7+
const saveLsCarrito = (prods) => {
88
localStorage.setItem("carrito", JSON.stringify(prods));
99
}
1010

11-
const obtenerCarritoLS = () => {
11+
const GetCarritoLs = () => {
1212
return JSON.parse(localStorage.getItem("carrito")) || [];
1313
}
1414

15-
function obtenerIdProductoLS() {
15+
function getProdId() {
1616
return JSON.parse(localStorage.getItem("idProducto")) || 0;
1717
}
1818

19-
function buscarProd() {
20-
const id = obtenerIdProductoLS();
19+
function buscarProdConId() {
20+
const id = getProdId();
2121
const producto = prodsPagPpal.find(item => item.id === id);
2222
return producto;
2323
}
2424

2525
const agregarProdCarrito = () => {
26-
const producto = buscarProd();
27-
const carrito = obtenerCarritoLS();
26+
const producto = buscarProdConId();
27+
const carrito = GetCarritoLs();
2828
carrito.push(producto);
29-
guardarCarritoLS(carrito);
29+
saveLsCarrito(carrito);
3030
desplegarBotonCarrito();
3131
}
3232

3333
const eliminarProductoCarrito = (id) => {
34-
const carrito = obtenerCarritoLS();
35-
const carritoActualizado = carrito.filter(item => item.id !== id);
36-
guardarCarritoLS(carritoActualizado);
34+
const carrito = GetCarritoLs();
35+
const carritoActual = carrito.filter(item => item.id !== id);
36+
saveLsCarrito(carritoActual);
3737
desplegarGraficosCarrito();
3838
desplegarBotonCarrito();
3939
Swal.fire({
@@ -46,54 +46,57 @@ const eliminarProductoCarrito = (id) => {
4646
}
4747

4848
const sumaVrTotalProds = () => {
49-
const carrito = obtenerCarritoLS();
49+
const carrito = GetCarritoLs();
5050
return carrito.reduce((acumulador, item) => acumulador + item.precio, 0);
5151
}
5252

5353
const borrarTodoCarrito = () => {
54-
Swal.fire({
55-
title: "Deseas eliminar todo tu carrito de compras?",
56-
text: "Por favor, confirmar.",
54+
const swalOptions = {
55+
title: "¿Deseas eliminar todo tu carrito de compras?",
56+
text: "Por favor, confirma.",
5757
icon: "warning",
5858
showCancelButton: true,
5959
confirmButtonColor: "#113946",
6060
cancelButtonColor: "#ff4500",
61-
confirmButtonText: "Sí, eliminar",
62-
cancelButtonText: "no, deseo seguir comprando!"
63-
}).then((result) => {
61+
confirmButtonText: "Sí, eliminar mi carrito de compras",
62+
cancelButtonText: "No, deseo seguir comprando"
63+
};
64+
65+
Swal.fire(swalOptions).then((result) => {
6466
if (result.isConfirmed) {
6567
localStorage.removeItem("carrito");
6668
Swal.fire({
67-
title: "Carrito Eliminado!",
68-
text: "Tus productos fueron eliminados correctamente de tu carrito de compras!",
69-
icon: "success",
69+
title: "¡Carrito Eliminado!",
70+
text: "Tus productos fueron eliminados correctamente de tu carrito de compras.",
71+
icon: "success"
7072
});
7173
} else {
7274
desplegarGraficosCarrito();
7375
desplegarBotonCarrito();
7476
Swal.fire({
75-
title: "Guardado!",
76-
text: "Estas a un solo paso de tener tus productos favoritos!",
77+
title: "Guardado",
78+
text: "¡Estás a un solo paso de tener tus productos favoritos!",
7779
icon: "success"
7880
});
7981
}
8082
});
8183
}
8284

85+
8386
const desplegarBotonCarrito = () => {
84-
document.getElementById("totalCarrito").innerHTML = cantTotalProductos();
87+
document.getElementById("totalCarrito").innerHTML = QTotalProductos();
8588
}
8689

87-
const cantTotalProductos = () => {
88-
const carrito = obtenerCarritoLS();
90+
const QTotalProductos = () => {
91+
const carrito = GetCarritoLs();
8992
return carrito.length;
9093
}
9194

9295

9396
function desplegarGraficosCarrito() {
94-
const carrito = obtenerCarritoLS();
97+
const carrito = GetCarritoLs();
9598
let contenido = "";
96-
if (carrito && cantTotalProductos() > 0) {
99+
if (carrito && QTotalProductos() > 0) {
97100
contenido = `
98101
<div class="tituloArticuloVta col-12">
99102
<h1 class="articulo">Tu carrito</h1>
@@ -154,7 +157,7 @@ function desplegarGraficosCarrito() {
154157
</div>
155158
`;
156159
} else {
157-
contenido = `<h1 class="text-center" style="margin: 230px 0 230px 0">Tu carrito de compras se encuentra vacío!</h1>`;
160+
contenido = `<h1 class="textoCarritoVacio">Tu carrito de compras se encuentra vacío!</h1>`;
158161
}
159162
let contenidoCarrito = document.getElementById("contenidoGralCarrito")
160163
contenidoCarrito? contenidoCarrito.innerHTML = contenido: null;
@@ -214,7 +217,7 @@ const finalizarCompra = () => {
214217
const totalConDescto = document.getElementById('vrTotalProductos').innerText;
215218
const mensaje = codigoDescuentoAplicado ? `Tu valor a pagar es en ${totalConDescto} pesos.` : `Tu cuenta total es $${sumaVrTotalProds()} pesos.`;
216219

217-
Swal.fire({
220+
const swalOptions = {
218221
title: "¡Muchas gracias por tu compra, vuelve pronto!",
219222
text: mensaje,
220223
imageUrl: "../images/logo3.png",
@@ -224,7 +227,9 @@ const finalizarCompra = () => {
224227
confirmButtonColor: "#ff4500",
225228
cancelButtonColor: "#113946",
226229
confirmButtonText: "Aceptar"
227-
}).then((result) => {
230+
};
231+
232+
Swal.fire(swalOptions).then((result) => {
228233
if (result.isConfirmed) {
229234
localStorage.removeItem("carrito");
230235
Swal.fire({

scss/_carrito.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
.container-fluid {
44
margin-left: 25px;
55
}
6+
7+
#contenidoGralCarrito{
8+
.textoCarritoVacio {
9+
margin: 230px 0 230px 0;
10+
text-align: center;
11+
}
12+
}
13+
614
.tituloArticuloVta {
715
margin-top: 15px;
816
.articulo {

0 commit comments

Comments
 (0)