-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
309 lines (243 loc) · 13.2 KB
/
cart.php
File metadata and controls
309 lines (243 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<!DOCTYPE html>
<html lang="en">
<head>
<title>Keranjang</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet">
<link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/aos.css">
<link rel="stylesheet" href="css/ionicons.min.css">
<link rel="stylesheet" href="css/bootstrap-datepicker.css">
<link rel="stylesheet" href="css/jquery.timepicker.css">
<link rel="stylesheet" href="css/flaticon.css">
<link rel="stylesheet" href="css/icomoon.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header.php'; ?>
<section class="home-slider owl-carousel">
<div class="slider-item" style="background-image: url(images/bg_1.jpg);" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<div class="container">
<div class="row slider-text justify-content-center align-items-center">
<div class="col-md-7 col-sm-12 text-center ftco-animate">
<h1 class="mb-3 mt-5 bread">Keranjang</h1>
<p class="breadcrumbs"><span class="mr-2"><a href="index.php">Home</a></span> <span><a href="#">Keranjang</a></span></p>
</div>
</div>
</div>
</div>
</section>
<?php
include('koneksi.php');
// Mendapatkan data dari tabel cart
$query = "SELECT * FROM cart";
$result = mysqli_query($koneksi, $query);
?>
<section class="ftco-section ftco-cart">
<div class="container">
<div class="row">
<div class="col-md-12 ftco-animate">
<div class="cart-list">
<div class="table-responsive">
<table class="table">
<thead class="thead-primary">
<tr class="text-center">
<!-- Kolom-kolom tabel -->
<th> </th>
<th>Gambar</th>
<th>Produk</th>
<th>Harga</th>
<th>Quantity</th>
<th>Harga Total</th>
</tr>
</thead>
<tbody>
<?php
// Perulangan untuk setiap item di tabel cart
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr class="text-center align-middle">
<td class="product-remove">
<a href="hapus_item.php?item_id=<?php echo $row['id']; ?>"><span class="icon-close"></span></a>
</td>
<!-- Menampilkan gambar produk -->
<td class="image-prod">
<div class="img" style="background-image: url(uploads/<?php echo $row['image']; ?>);"></div>
</td>
<!-- Menampilkan Nama dan detail Produk -->
<td class="product-name text-left align-middle">
<h3><?php echo $row['nama_produk']; ?></h3>
<p><?php echo $row['details']; ?></p>
</td>
<td class="price align-middle"><?php echo 'Rp. ' . $row['harga_total']; ?></td>
<td class="quantity text-right align-middle">
<div class="input-group mb-3">
<input type="number" name="total_pesanan" class="quantity form-control input-number" value="<?php echo $row['quantity']; ?>" min="1" max="10" data-product-id="<?php echo $row['id']; ?>">
</div>
</td>
<td class="total text-right align-middle"><?php echo 'Rp. ' . $row['harga_total']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<br><br>
<div class="container">
<div class="row">
<div class="col-md-6">
<form id="billingForm" action="proses_pesanan.php" method="POST" class="billing-form ftco-bg-dark p-3 p-md-5">
<h3 class="mb-4 billing-heading">Details</h3>
<div class="form-group">
<label for="firstname">Name</label>
<input type="text" name="nama_pelanggan" class="form-control text-left text-dark" placeholder="Name" required>
</div>
<div class="form-group">
<label for="country">Nomor Meja</label>
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="nomor_meja" class="form-control text-left">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row justify-content-end">
<div class="col-lg-6 col-md-12 mt-5 cart-wrap ftco-animate">
<div class="cart-total mb-3">
<h3>Total</h3>
<hr>
<!-- Isi Total -->
<p class="d-flex total-price">
<span>Total</span>
<span id="total-amount"><?php echo 'Rp. ' . $row['total']; ?></span>
<input type="hidden" name="total_harga" id="total-harga" value="<?php echo 'Rp. ' . $row['total']; ?>">
</p>
</div>
</form><!-- END -->
<!-- Tombol Pesan Sekarang -->
<p class="text-center">
<button form="billingForm" type="submit" class="btn btn-secondary btn-block">Pesan Sekarang</button>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include 'footer.php'; ?>
<!-- loader -->
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px">
<circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee" />
<circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00" />
</svg></div>
<!-- INI BAGIAN TOTAL TABLE DAN QUANTITY -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
// Memanggil fungsi perhitungan total saat halaman dimuat
calculateTotals();
$(".input-number").on("input", function() {
var row = $(this).closest("tr");
var price = parseFloat(row.find(".price").text().replace("Rp. ", ""));
var quantity = parseInt($(this).val());
var total = price * quantity;
// Set total harga pada kolom Total
row.find(".total").text('Rp. ' + total.toFixed(3));
// Memanggil kembali fungsi perhitungan total setiap kali input diubah
calculateTotals();
});
// Validasi input hanya angka pada kolom kuantitas
$(".input-number").on("keypress", function(event) {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
event.preventDefault();
}
});
// Fungsi untuk menghitung total keseluruhan
function calculateTotals() {
var grandTotal = 0;
$(".table tbody tr").each(function() {
var row = $(this);
var price = parseFloat(row.find(".price").text().replace("Rp. ", ""));
var quantity = parseInt(row.find(".quantity input").val());
var total = price * quantity;
row.find(".total").text('Rp. ' + total.toFixed(3));
grandTotal += total;
});
// Menampilkan total keseluruhan di bagian Total
$("#total-amount").text('Rp. ' + grandTotal.toFixed(3));
// Setelah menghitung total
$("#total-harga").val(grandTotal.toFixed(3)); // Mengatur nilai total_harga pada input tersembunyi
}
});
</script>
<!-- JavaScript untuk mengirim data ke server saat `quantity` diubah -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".input-number").on("input", function() {
var productId = $(this).data("product-id");
var newQuantity = $(this).val();
$.ajax({
method: "POST",
url: "update_quantity.php", // File PHP untuk memperbarui `quantity` di database
data: {
product_id: productId,
new_quantity: newQuantity
},
success: function(response) {
// Lakukan sesuatu setelah `quantity` diperbarui di server jika diperlukan
console.log("Quantity updated successfully.");
},
error: function(xhr, status, error) {
console.error("Error updating quantity:", error);
}
});
});
});
</script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate-3.0.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.waypoints.min.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/jquery.animateNumber.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.timepicker.min.js"></script>
<script src="js/scrollax.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
<script src="js/google-map.js"></script>
<script src="js/main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</body>
</html>