0% found this document useful (0 votes)
11 views4 pages

Cart PHP

This document is a PHP script for a shopping cart system that manages user sessions and allows users to view, modify, and checkout their selected products. It retrieves product details from a database, displays them in a table format, and provides options for removing items and entering customer information for checkout. The page is styled with CSS for a user-friendly interface and includes functionality for different payment and delivery methods.

Uploaded by

dellfadel3230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Cart PHP

This document is a PHP script for a shopping cart system that manages user sessions and allows users to view, modify, and checkout their selected products. It retrieves product details from a database, displays them in a table format, and provides options for removing items and entering customer information for checkout. The page is styled with CSS for a user-friendly interface and includes functionality for different payment and delivery methods.

Uploaded by

dellfadel3230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

<?

php
session_start();
include '../db.php';

// Inisialisasi keranjang jika belum ada


if (!isset($_SESSION['cart'])) {
$_SESSION['cart'] = [];
}

// Hapus item dari keranjang


if (isset($_GET['hapus'])) {
$hapus_id = $_GET['hapus'];
unset($_SESSION['cart'][$hapus_id]);
}

// Ambil detail produk dari database


$produk_ids = array_keys($_SESSION['cart']);
$produk_list = [];

if (!empty($produk_ids)) {
$id_string = implode(',', array_map('intval', $produk_ids));
$query = "SELECT * FROM produk WHERE id IN ($id_string)";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
$produk_list[$row['id']] = $row;
}
}
?>

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Keranjang Belanja</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/6.5.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: #000;
color: white;
padding: 40px;
}

.container {
max-width: 900px;
margin: auto;
background: #111;
padding: 30px;
border-radius: 10px;
}

h2 {
text-align: center;
margin-bottom: 30px;
}

table {
width: 100%;
border-collapse: collapse;
margin-bottom: 30px;
}

th, td {
padding: 14px;
text-align: left;
}

th {
background-color: #1a1a1a;
}

tr:nth-child(even) {
background-color: #181818;
}

tr:hover {
background-color: #222;
}

.fa-trash {
color: #e74c3c;
font-size: 18px;
transition: 0.2s;
}

.fa-trash:hover {
color: #ff6b6b;
transform: scale(1.2);
}

form input, form select {


width: 100%;
padding: 10px;
background: #222;
color: white;
border: none;
border-radius: 5px;
margin-bottom: 15px;
}

form button {
padding: 12px;
background: #27ae60;
color: white;
border: none;
border-radius: 6px;
font-weight: bold;
cursor: pointer;
transition: 0.3s;
}

form button:hover {
background: #219150;
}

.back-link {
display: inline-block;
margin-bottom: 20px;
color: white;
text-decoration: none;
}

.back-link i {
margin-right: 6px;
}

.total {
text-align: right;
font-weight: bold;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<a href="index.php" class="back-link"><i class="fas fa-arrow-left"></i> Kembali
ke Toko</a>
<h2>Keranjang Belanja</h2>

<?php if (!empty($produk_list)): ?>


<table>
<tr>
<th>Produk</th>
<th>Jumlah</th>
<th>Harga</th>
<th>Total</th>
<th>Hapus</th>
</tr>
<?php
$total_semua = 0;
foreach ($_SESSION['cart'] as $id => $jumlah):
$produk = $produk_list[$id];
$total = $produk['harga'] * $jumlah;
$total_semua += $total;
?>
<tr>
<td><?= htmlspecialchars($produk['nama']) ?></td>
<td><?= $jumlah ?></td>
<td>Rp <?= number_format($produk['harga'], 0, ',', '.') ?></td>
<td>Rp <?= number_format($total, 0, ',', '.') ?></td>
<td><a href="?hapus=<?= $id ?>"><i class="fas fa-trash"></i></a></td>
</tr>
<?php endforeach; ?>
</table>

<div class="total">Total: Rp <?= number_format($total_semua, 0, ',', '.')


?></div>

<h3>Data Pemesan</h3>
<form action="checkout.php" method="POST">
<input type="text" name="nama_pemesan" placeholder="Nama Lengkap" required>
<input type="email" name="email" placeholder="Email" required>
<input type="tel" name="telepon" placeholder="Nomor Telepon" required>
<input type="text" name="alamat" placeholder="Alamat Lengkap" required>

<label for="metode">Metode Pengiriman File:</label>


<select name="metode_pengiriman" id="metode" required>
<option value="google_drive">Google Drive</option>
<option value="email">Email</option>
<option value="whatsapp">WhatsApp</option>
<option value="website">Unduh via Website (setelah pembayaran)</option>
</select>

<label for="metode_pembayaran">Metode Pembayaran</label>


<select name="metode_pembayaran" required>
<option value="">-- Pilih Pembayaran --</option>
<option value="Transfer Bank">Transfer Bank</option>
<option value="QRIS">QRIS</option>
<option value="COD">Bayar di Tempat (COD)</option>
<option value="E-Wallet">E-Wallet (Dana/OVO/Gopay)</option>
</select>

<button type="submit">Checkout</button>
</form>

<?php else: ?>


<p>Keranjang masih kosong. <a href="index.php">Belanja sekarang</a>.</p>
<?php endif; ?>
</div>
</body>
</html>

You might also like