94 lines
5.0 KiB
PHP
94 lines
5.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../app/Controllers/CartController.php';
|
|
require_once __DIR__ . '/../app/Views/public/header.php';
|
|
|
|
$cart_items = CartController::getCartContents();
|
|
$cart_total = CartController::getCartTotal();
|
|
?>
|
|
|
|
<main class="container my-5">
|
|
<div class="page-header-cart">
|
|
<h1 class="display-4">Seu Carrinho</h1>
|
|
<p class="lead">Revise seus itens e prossiga para o checkout.</p>
|
|
</div>
|
|
|
|
<?php if (empty($cart_items)): ?>
|
|
<div class="alert alert-info text-center">
|
|
<p>Seu carrinho está vazio.</p>
|
|
<a href="catalog.php" class="btn btn-primary">Ver Produtos</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" colspan="2">Produto</th>
|
|
<th scope="col">Preço</th>
|
|
<th scope="col">Quantidade</th>
|
|
<th scope="col">Subtotal</th>
|
|
<th scope="col"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($cart_items as $item): ?>
|
|
<tr>
|
|
<td style="width: 100px;">
|
|
<a href="product.php?slug=<?= htmlspecialchars($item['slug']) ?>">
|
|
<img src="uploads/products/<?= htmlspecialchars($item['image']) ?>" alt="<?= htmlspecialchars($item['name']) ?>" class="img-fluid rounded" style="max-height: 75px;">
|
|
</a>
|
|
</td>
|
|
<td>
|
|
<a href="product.php?slug=<?= htmlspecialchars($item['slug']) ?>" class="text-decoration-none text-dark fw-bold"><?= htmlspecialchars($item['name']) ?></a>
|
|
</td>
|
|
<td>R$ <?= number_format($item['price'], 2, ',', '.') ?></td>
|
|
<td>
|
|
<form action="/app/Controllers/CartController.php" method="POST" class="d-flex">
|
|
<input type="hidden" name="action" value="update">
|
|
<input type="hidden" name="product_id" value="<?= $item['product_id'] ?>">
|
|
<input type="number" name="quantity" class="form-control form-control-sm" value="<?= $item['quantity'] ?>" min="1" style="width: 70px;">
|
|
<button type="submit" class="btn btn-outline-secondary btn-sm ms-2">Atualizar</button>
|
|
</form>
|
|
</td>
|
|
<td>R$ <?= number_format($item['price'] * $item['quantity'], 2, ',', '.') ?></td>
|
|
<td>
|
|
<form action="/app/Controllers/CartController.php" method="POST">
|
|
<input type="hidden" name="action" value="remove">
|
|
<input type="hidden" name="product_id" value="<?= $item['product_id'] ?>">
|
|
<button type="submit" class="btn btn-danger btn-sm"><i data-feather="trash-2"></i></button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Resumo do Pedido</h5>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
Subtotal
|
|
<span>R$ <?= number_format($cart_total, 2, ',', '.') ?></span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center fw-bold">
|
|
Total
|
|
<span>R$ <?= number_format($cart_total, 2, ',', '.') ?></span>
|
|
</li>
|
|
</ul>
|
|
<div class="d-grid mt-3">
|
|
<a href="checkout.php" class="btn btn-primary">Finalizar Compra</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<?php
|
|
require_once __DIR__ . '/../app/Views/public/footer.php';
|
|
?>
|