Skip to content

Commit

Permalink
fix: not adding orders to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Fernandez Teixeira committed Jun 25, 2024
1 parent 1d4853f commit cce894b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cardapio/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h3 class="menu-item-heading">
<div id='cart-items' class="sidebar-content">
<span id="close-btn" class="close-btn">&times;</span>
<h2>Carrinho</h2>
<p>Seu carrinho está vazio.</p>
<p id="emptycart">Seu carrinho está vazio.</p>
</div>
<div class="cart-footer">
<p>Total: R$<span id="cart-total">0.00</span></p>
Expand Down
13 changes: 8 additions & 5 deletions cardapio/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function addToCart(event) {
cartItem.setAttribute("data-product-name", productName);
cartItem.setAttribute("data-product-price", productPrice);
cartItem.innerHTML = `
<p>${productName} - R$<span class="total-price">${productPrice.toFixed(
<p class=\"item\">${productName} - R$<span class="total-price">${productPrice.toFixed(
2
)}</span>
<input type="number" class="quantity-input" value="1" min="1" data-product-price="${productPrice.toFixed(
Expand All @@ -58,7 +58,7 @@ function addToCart(event) {
`;

// Adicionar o item ao carrinho
const emptyMessage = cartItems?.querySelector("p");
const emptyMessage = document.getElementById("emptycart");
if (emptyMessage) {
emptyMessage.remove();
}
Expand Down Expand Up @@ -87,6 +87,9 @@ function updateTotalPrice(event) {
// Atualizar o total do carrinho
calculateCartTotal();
}
function addEmptyMessage(cartItems) {
cartItems.innerHTML = '<p id="emptycart">Seu carrinho está vazio.</p>';
}

// Função para remover um item do carrinho
function removeCartItem(event) {
Expand All @@ -96,17 +99,17 @@ function removeCartItem(event) {
// Verificar se o carrinho está vazio e exibir a mensagem apropriada
const cartItems = document.getElementById("cart-items");
if (cartItems.children.length === 0) {
cartItems.innerHTML = "<p>Seu carrinho está vazio.</p>";
addEmptyMessage(cartItems);
}

// Atualizar o total do carrinho
calculateCartTotal();
}

// Função para remover todos os itens do carrinho
function clearCart() {
const cartItems = document.getElementById("cart-items");
cartItems.innerHTML = "<p>Seu carrinho está vazio.</p>";

addEmptyMessage(cartItems);
// Atualizar o total do carrinho
calculateCartTotal();
}
Expand Down
17 changes: 16 additions & 1 deletion cardapio/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,25 @@ p {
animation-delay: 0.8s;
}

#emptycart {
animation-delay: 0.2s;
}

.cart-items {
animation-delay: 0.2s;
}

.sidebar p {
animation-delay: 0.2s;
}

a {
animation-delay: 1.6s;
}

.item {
display: flex;
justify-content: space-between;
}
button {
animation-delay: 0.2s;
}
Expand Down

0 comments on commit cce894b

Please sign in to comment.