-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcart.php
125 lines (113 loc) · 3.89 KB
/
cart.php
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
<!DOCTYPE html>
<html lang="en">
<?php include("assets/template/header.php"); ?>
<?php include("config/config.php"); ?>
<body>
<!--Main layout-->
<main class="mt-5 pt-5">
<center>
<div class="table-responsive text-center" style="width: 95%;">
<table class="table table-hover table-bordered">
<thead class="black white-text">
<tr>
<th scope="col">No.</th>
<th scope="col">Nama Barang</th>
<th scope="col">Gambar</th>
<th scope="col">Jumlah</th>
<th scope="col">Harga Satuan</th>
<th scope="col">Sub Total</th>
<th scope="col">Options</th>
</tr>
</thead>
<tbody>
<?php
//MENAMPILKAN DETAIL KERANJANG BELANJA//
$total = 0;
$no = 1;
foreach($_SESSION as $name => $value){
if($value > 0){
if(substr($name, 0, 5) == 'cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = $db->query("SELECT * FROM tb_barang WHERE id='$id'");
while($get_row = $get->fetch_assoc()){
if($no % 2 == 0){
$warna = "#EAEAEA";
} else {
$warna = "#F4F4F4";
}
$sub = $get_row['harga'] * $value;
echo '
<tr bgcolor="'.$warna.'">
<td>'.$no.'</td>
<td>'.$get_row['namabarang'].'</td>
<td><img src="assets/img/'.$get_row['namagambar'].'" width="140"></td>
<td>'.$value.'</td>
<td>Rp. '.number_format($get_row['harga']).'</td>
<td>Rp. '.number_format($sub).'</td>
<td align="center">
<a href="cart.php?remove='.$id.'"><button type="submit" class="btn btn-warning" style="font-size: 13px;" name="submit"><i class="fa fa-minus"></i></button></a>
<a href="cart.php?add='.$id.'"><button type="submit" class="btn btn-success" style="font-size: 13px;" name="submit"><i class="fa fa-plus"></i></button></a>
<a href="cart.php?delete='.$id.'"><button type="submit" class="btn btn-danger" style="font-size: 13px;" name="submit"><i class="fa fa-trash"></i></button></a><br>
</td>
</tr>
';
$no++;
}
$total += $sub;
}
}
}
$_SESSION['total'] = $total;
if($total == 0){
echo '<div class="mt-5">';
echo '<tr><td colspan="7" align="center">Keranjang belanja masih kosong!</td></tr></table>';
echo '<p><div align="right">
<a href="index.php" class="btn btn-success btn-md"">« Lanjutkan Belanja</a>
</div></p>';
echo '</div>';
} else {
echo '
<div class="mt-5">
<tr style="background-color: #DDD;"><td colspan="5" align="right"><b>Total :</b></td><td align="right"><b>Rp. '.number_format($total).'</b></td></td></td><td></td></tr></table>
<p><div align="right">
<a href="index.php" class="btn btn-success btn-md">« Lanjutkan Belanja</a>
<a href="form.php?total='.$total.'" class="btn btn-success btn-md">Checkout »</a>
</div></p>
</div>
';
}
?>
<?php
//PROSES TAMBAH JUMLAH PRODUK//
if(isset($_GET['add'])){
$qt = $db->query('SELECT id, jumlahbarang FROM tb_barang WHERE id='.(int)$_GET['add']);
while($qt_row = $qt->fetch_assoc()){
if($qt_row['jumlahbarang'] != $_SESSION['cart_'.$_GET['add']]){
$_SESSION['cart_'.$_GET['add']]+'1';
header("Location: cart.php");
} else {
echo '<script language="javascript">alert("Stok barang tidak mencukupi"); document.location="cart.php";</script>';
}
}
}
//PROSES HAPUS 1 ITEM PRODUK//
if(isset($_GET['remove'])){
$_SESSION['cart_'.$_GET['remove']]--;
header("Location: cart.php");
}
//PROSES HAPUS SEMUA ITEM PRODUK//
if(isset($_GET['delete'])){
$_SESSION['cart_'.$_GET['delete']]='0';
header("Location: cart.php");
}
?>
</tbody>
</table>
</div>
</center>
</main>
<!--Main layout-->
<!-- footer -->
<?php include("assets/template/footer.php"); ?>
</body>
</html>