mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 14:52:04 +00:00
86 lines
3.9 KiB
PHP
86 lines
3.9 KiB
PHP
<?php
|
|
session_start();
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Carrello - TechStore</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
<script src="assets/js/cart.js"></script>
|
|
</head>
|
|
<body>
|
|
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
|
|
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php"><img src="img/logo.png" alt="Logo TechStore" height="32px"></a></div>
|
|
<div>
|
|
<a href="cart.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
|
|
<?php if (isset($_SESSION['user'])): ?>
|
|
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
|
|
<span style="margin-left: 10px;">Benvenuto, <?php echo htmlspecialchars($_SESSION['user']); ?></span>
|
|
<?php else: ?>
|
|
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="cart-container">
|
|
<h1>Il tuo carrello</h1>
|
|
|
|
<?php
|
|
$cart = [];
|
|
$cartCookie = isset($_COOKIE['cart']) ? $_COOKIE['cart'] : '';
|
|
|
|
if ($cartCookie) {
|
|
$cart = json_decode(urldecode($cartCookie), true);
|
|
}
|
|
|
|
if (empty($cart)): ?>
|
|
<div class="empty-cart">
|
|
<p>Il tuo carrello è vuoto.</p>
|
|
<a href="index.php"><button style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 10px;">Torna ai prodotti</button></a>
|
|
</div>
|
|
<?php else: ?>
|
|
<table class="cart-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Prodotto</th>
|
|
<th>Prezzo</th>
|
|
<th>Quantità</th>
|
|
<th>Totale</th>
|
|
<th>Azione</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$grand_total = 0;
|
|
foreach ($cart as $index => $item):
|
|
$item_total = $item['price'] * $item['quantity'];
|
|
$grand_total += $item_total;
|
|
?>
|
|
<tr>
|
|
<td><a href="product.php?id=<?php echo $item['id']; ?>"><?php echo htmlspecialchars($item['name']); ?></a></td>
|
|
<td>€<?php echo number_format($item['price'], 2, ',', '.'); ?></td>
|
|
<td><?php echo $item['quantity']; ?></td>
|
|
<td>€<?php echo number_format($item_total, 2, ',', '.'); ?></td>
|
|
<td>
|
|
<button onclick="removeFromCart(<?php echo $index; ?>)">Rimuovi</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="cart-summary">
|
|
<p>Totale: €<?php echo number_format($grand_total, 2, ',', '.'); ?></p>
|
|
</div>
|
|
|
|
<div style="text-align: right; margin-top: 20px;">
|
|
<button class="clear-cart-btn" onclick="clearCart()">Svuota carrello</button>
|
|
<button class="checkout-btn">Procedi all'acquisto</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</body>
|
|
</html>
|