-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.php
186 lines (149 loc) · 8.76 KB
/
orders.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
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
<?php
session_start();
if (isset($_SESSION['user_id'])) {
// create a database connection
$mysqli = require __DIR__ . '/database.php';
// get the logged in user's id
$fetch_user_session = "SELECT * FROM users
WHERE id = {$_SESSION['user_id']}";
$result = $mysqli->query($fetch_user_session);
$user = $result->fetch_assoc();
} else {
header('Location: home.php');
}
?>
<!-- Fetch the details for the art_order for the user whose id is in the URL
<?php
$fetch_art_session = "SELECT * FROM art_orders WHERE user_id = {$_GET['id']}";
$result = $mysqli->query($fetch_art_session);
$art_order = $result->fetch_assoc();
// Check if there is no order matching the user id or if the order is empty
if (!$art_order || empty($art_order)) {
header("Location: home.php");
}
// fetch the additional details for the art piece that is in the order
$fetch_art_piece = "SELECT * FROM art WHERE id = {$art_order['piece_id']}";
$piece_result = $mysqli->query($fetch_art_piece);
$art = $piece_result->fetch_assoc();
?>
<!-- Fetch the order id from the art_orders table-->
<!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'>
<title> <?= substr($user['name'], 0, strpos($user['name'], ' ')) . '\'s Art Orders' ?> </title>
<!-- Styling imports -->
<link rel='stylesheet' href='styles/main.css'>
<link rel='stylesheet' href='styles/utility.css'>
<!-- Bootstrap Icons imports -->
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css'>
</head>
<body>
<?php include __DIR__ . '/navbar.php'; ?>
<!-- Start of main -->
<main>
<div class='container-cart'>
<div class='row mt-6'>
<div class='col-lg-8 col-md-8 col-sm-12'>
<div class='col-lg-12 col-md-8 px-2'>
<div class='row'>
<!-- Fetch all the orders whose isPaid = 0 made by the user whose id is in the URL -->
<?php
$fetch_orders = "SELECT * FROM art_orders WHERE user_id = {$_GET['id']} AND isPaid = 0";
$result = $mysqli->query($fetch_orders);
// if there are no orders, redirect to home
if ($result->num_rows == 0) {
header("Location: home.php");
}
while ($order = $result->fetch_assoc()) {
$fetch_art = "SELECT * FROM art WHERE id = {$order['piece_id']}";
$piece_result = $mysqli->query($fetch_art);
$art = $piece_result->fetch_assoc();
$art_price = number_format($art['price'], 2);
// get the total cart price by adding all the individual art prices
$cart_price = $cart_price + $art['price'];
?>
<!-- Start of order -->
<div class='row'>
<div class='col-lg-12 col-md-8 col-sm-12 px-2'>
<div class='card card-short mb-5'>
<div class='row'>
<div class='col-lg-3 col-md-8 col-sm-12'>
<img src='<?= $art['img_path'] ?>' style='max-height: 20vh !important;' alt='<?= $art['title'] ?>' class='p-4'>
</div>
<div class='col-lg-9 col-md-4 col-sm-12 ps-3 py-3'>
<div class='card-body'>
<div class='row'>
<div class='col-5 col-md-5 col-sm-12'>
<a href='art-piece-details.php?id=<?= $art['id'] ?>' target='_blank' class='text-dark'>
<h2 class='card-title'><?= $art['title'] ?></h2>
</a>
</div>
<div class='col-lg-6 col-md-6 col-sm-12'>
<h3 class='card-text'><?= $art['artist_name'] ?></>
</div>
<div class='row pt-4'>
<div class='col-4'>
<span class='card-text fs-5 pt-3'>Kshs. <?= $art_price ?></span>
</div>
<div class='col-4'>
<span class='card-text fs-5 pt-3'><?= date('d M Y, g:i A', strtotime($order['created_at'])); ?></span>
</div>
<div class='col-4'>
<!-- implement delete art order button -->
<form action='process-delete-art-order.php' method='POST'>
<input type='hidden' name='art_id' value='<?= $art['id'] ?>'>
<input type='hidden' name='user_id' value='<?= $user['id'] ?>'>
<button type='submit' class='btn btn-sm btn-imperial mb-2'>Delete</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- show the total cart price -->
<div class='card card-short mb-6'>
<center>
<div class='row'>
<div class='col-lg-3 col-md-3 col-sm-12 ps-3 py-2'>
<h1>Total Price</h1>
</div>
<div class='col-lg-9 col-md-4 col-sm-12 ps-3 py-2'>
<div class='card-body'>
<span class='card-text fs-2 pt-3'>Kshs. <?= number_format($cart_price, 2) ?></span>
</div>
</div>
</div>
</center>
</div>
</div>
</div>
</div>
<div class='col-lg-4 col-md-4 col-sm-12 px-2'>
<div class='card card-checkout p-2'>
<center>
<h2>Checkout</h2>
</center>
<p class='px-4'>
There is an option - more preferred where you can pay on piece collection
</p>
<a href='piece-collection.php?id=<?= $_GET['id'] ?>' class='btn btn-imperial btn-checkout'>Pay on collection</a>
<!-- Paypal Implementation -->
<div id='paypal-button-container' class='p-4'></div>
</div>
</div>
</div>
</main>
<!-- Paypal Scripts addtion -->
<script src='https://www.paypal.com/sdk/js?client-id=AQ1dYNCw-E-XfDrHWhe1BZ5-90Y1e4c0Ut7C7lTH_LPT33dXt0ma70l75mWT1QEdbAOZHacxMlbNzSyk'></script>
<script src='js/payments.js'></script>
<!-- End of main -->
</body>
</html>