99 lines
4.6 KiB
PHP
99 lines
4.6 KiB
PHP
<?php
|
|
include '../template/template1.php';
|
|
include '../template/header.php';
|
|
include '../config.php'; // Sesuaikan dengan file koneksi Anda
|
|
|
|
// Pastikan user login
|
|
if (!isset($_SESSION['id_pembeli'])) {
|
|
header("Location: /login");
|
|
exit;
|
|
}
|
|
|
|
$query = mysqli_query($conn, "SELECT cart.*, produk.nama_produk, produk.harga_jual, produk.gambar, produk.stok
|
|
FROM cart
|
|
JOIN produk ON cart.id_produk = produk.id_produk
|
|
WHERE cart.id_pembeli = '{$_SESSION['id_pembeli']}'");
|
|
|
|
?>
|
|
<section class="section mt-4">
|
|
<div class="container">
|
|
<h2 class="text-center">Keranjang Saya</h2>
|
|
<?php if (mysqli_num_rows($query) > 0): ?>
|
|
<div class="row">
|
|
<!-- Kolom Keranjang -->
|
|
<div class="col-md-8">
|
|
<div class="card shadow-sm">
|
|
<div style="background-color: #FFA836;" class="card-header text-white">
|
|
<h5 class="mb-0 text-white">Keranjang Belanja</h5>
|
|
</div>
|
|
<div class="card-body table-responsive">
|
|
<table class="table table-striped">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Gambar</th>
|
|
<th>Nama Produk</th>
|
|
<th>Harga</th>
|
|
<th>Jumlah</th>
|
|
<th>Potongan</th>
|
|
<th>Total</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$grand_total = 0;
|
|
while ($row = mysqli_fetch_assoc($query)):
|
|
$total = $row['harga_jual'] * $row['jumlah'];
|
|
$grand_total += $total;
|
|
?>
|
|
<tr>
|
|
<td><img src="<?= $base_url; ?>/assets/img/produk/<?= $row['gambar']; ?>"
|
|
alt="<?= $row['nama_produk']; ?>"
|
|
class="img-thumbnail"
|
|
style="width: 80px; height: 80px; object-fit: cover;"></td>
|
|
<td><?= $row['nama_produk']; ?></td>
|
|
<td>Rp<?= number_format($row['harga_jual'], 0, ',', '.'); ?></td>
|
|
<td><?= $row['jumlah']; ?></td>
|
|
<td><?= $row['potong']; ?> potong</td>
|
|
<td><strong>Rp<?= number_format($total, 0, ',', '.'); ?></strong></td>
|
|
<td>
|
|
<a href="hapus-keranjang.php?id_cart=<?= $row['id_cart']; ?>"
|
|
class="btn btn-sm btn-danger">
|
|
<i class="fas fa-trash-alt"></i> Hapus
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Kolom Checkout -->
|
|
<div class="col-md-4">
|
|
<div class="card shadow-sm">
|
|
<div style="background-color: #FFA836; color: white;" class="card-header text-white">
|
|
<h5 class="mb-0 text-white">Ringkasan Belanja</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<h6>Total Keseluruhan:</h6>
|
|
<h4 class="text-primary">Rp<?= number_format($grand_total, 0, ',', '.'); ?></h4>
|
|
<hr>
|
|
<a href="/checkout" class="btn btn-lg w-100" style="background-color: #FFA836; color: white;">
|
|
<i class="fas fa-shopping-cart"></i> Checkout
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="text-center">Keranjang Anda kosong. <a href="/produk">Belanja sekarang</a>.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php include '../template/footer.php'; ?>
|
|
|
|
<?php include '../template/template2.php'; ?>
|