-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
101 lines (90 loc) · 4.56 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
<?php
include './scripts/utils.php';
session_start();
if(!isset($_SESSION['userId'])) header("Location: ../login.php");
if(isset($_SESSION['errors'])) unset($_SESSION['errors']);
if(!isset($_SESSION['cartProducts']) || count($_SESSION['cartProducts']) === 0) $_SESSION['cartProducts'] = array();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
<link rel="icon" type="image/png" sizes="32x32" href="./assets/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./assets/icons/favicon-16x16.png">
<title>Feetsh*t</title>
</head>
<body>
<?php require './components/header_guest.php'; ?>
<div class="flex flex-col my-16 w-full items-center justify-center">
<h1 class="font-bold text-gray-700 text-4xl text-center my-4">Cart</h1>
</div>
<div class="flex flex-col items-center justify-center w-full">
<table class="text-center text-sm font-light w-2/3">
<thead class="bg-neutral-800 font-medium text-white uppercase ">
<tr>
<th scope="col" class="px-6 py-4">Name</th>
<th scope="col" class="px-6 py-4">Size</th>
<th scope="col" class="px-6 py-4">Sale Price</th>
<th scope="col" class="px-6 py-4"></th>
</tr>
</thead>
<tbody>
<?php
$cartProducts = $_SESSION['cartProducts'];
$productId = "";
$size = "";
if (count($cartProducts) === 0){
echo '
<tr class="border-b transition duration-300 ease-in-out hover:bg-neutral-200">
<td colSpan="4" class="px-6 py-4 text-center">No items in cart</td>
</tr>
';
}else{
include './scripts/dbConnection.php';
foreach($cartProducts as $item) {
$size = $item["size"];
$productId = $item["productId"];
$sql = "SELECT * FROM products WHERE id = '$productId'";
$result = $conn->query($sql);
if ($result !== false && $result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '
<tr class="border-b transition duration-300 ease-in-out hover:bg-neutral-200">
<td class="px-6 py-4">'.$row["name"].'</td>
<td class="px-6 py-4">'.$size.'</td>
<td class="px-6 py-4">'.'$ '.number_format($row["salePrice"], 2).'</td>
<td class="py-4">
<form action="./scripts/cart_script.php?id='.$productId.'" method="POST">
<button name="deleteItemBtn" value="'.$row["id"].'" class="px-4 py-2 rounded-lg bg-red-500 text-white hover:bg-red-600">
<i class="fa fa-trash text-white px-2" aria-hidden="true"></i>Delete
</button>
</form>
</td>
</tr>
';
}
}
}
if ($conn) $conn-> close();
}
?>
</tbody>
</table>
<?php
if (count($cartProducts) > 0){
echo'
<div class="my-4">
<form action="./checkout.php" method="POST">
<input name="checkOutBtn" type="submit" value="Check out" class="px-8 py-3 rounded-lg bg-green-500 text-lg font-bold text-white hover:bg-green-600"/>
</form>
</div>
';
}
?>
<div>
</body>
</html>