-
Notifications
You must be signed in to change notification settings - Fork 2
/
pannier.php
354 lines (310 loc) · 10.7 KB
/
pannier.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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?php
# On se connecte à notre base de donnée
$connection = mysqli_connect('localhost', 'root', '', 'boutique');
# Si la connexion n'a pas aboutie, on affiche une erreur
if (!$connection) {
die("Une erreur est survenue lors de la liason avec la base de donnée. Veuillez réessayer plus tard!");
}
# Selection de tous les paniers dans la bd
$sql = "SELECT * FROM panier INNER JOIN article WHERE article.id = panier.id_article";
$query = mysqli_query($connection, $sql);
if ($query) {
$paniers = mysqli_fetch_all($query, MYSQLI_ASSOC);
#var_dump($paniers);
} else {
echo "<script>Une erreur est survenue lors de la récupération des données</script>";
}
# Selection du nombre de paniers dans la bd
$nb_sql = "SELECT COUNT(*) AS total FROM panier";
$nb_query = mysqli_query($connection, $nb_sql);
if ($nb_query) {
$nb_panier = mysqli_fetch_assoc($nb_query);
$nb_panier = $nb_panier['total'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script defer src="https://kit.fontawesome.com/1f88d87af5.js" crossorigin="anonymous"></script>
<title>MON PANIER RAPIDE</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
position: relative;
}
header {
display: flex;
padding: 20px;
justify-content: space-evenly;
position: absolute;
width: 100%;
z-index: 100;
top: 0;
align-items: center;
}
header a {
text-decoration: none;
color: #fff;
text-shadow: 0px 0px 2px #000000;
padding: 5px;
}
header a:hover {
border: 2px solid #fff;
}
ul {
list-style: none;
display: flex;
width: 60%;
justify-content: space-evenly;
max-width: 500px;
align-items: center;
}
.helper {
display: flex;
align-items: center;
position: relative;
gap: 2em;
width: 50%;
text-align: center;
justify-content: space-around;
}
.helper .number {
background-color: red;
border-radius: 100%;
font-weight: bold;
padding: 5px;
}
.sticky {
position: sticky;
backdrop-filter: blur(5px);
box-shadow: 0px 0px 10px 2px #58585830;
}
main {
flex-grow: 1;
display: flex;
flex-direction: column;
gap: 2em;
}
.banner {
max-height: 400px;
overflow: hidden;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.banner h3 {
position: absolute;
padding: 10px;
border: 2px solid #fff;
color: #fff;
text-shadow: 0px 0px 2px #000000;
}
.banner img {
width: 100%;
object-fit: cover;
}
.content {
padding: 10px;
display: flex;
flex-direction: column;
gap: 2em;
}
.content h2 {
text-align: center;
}
.articles {
width: 100%;
max-width: 700px;
margin: 0 auto;
gap: 1.5em;
display: flex;
flex-direction: column;
overflow-x: scroll;
}
.imgBox {
width: 100px;
height: 100px;
background-color: #000000;
}
.imgBox img {
width: 100%;
height: 100%;
object-fit: cover;
}
table {
width: 100%;
text-align: center;
border-collapse: collapse;
}
table tr {
border-bottom: 1px solid;
}
table thead tr th {
max-width: 100px;
text-transform: capitalize;
}
table tbody tr td.img {
padding: 2px;
display: flex;
justify-content: center;
}
input[type="number"] {
width: 70px;
text-align: center;
}
.bilan {
background-color: #8d8b8b30;
padding: 10px;
color: #444;
}
.bilan,
.detailBox {
display: flex;
flex-direction: column;
gap: 1em;
width: 100%;
max-width: 500px;
}
.detailBox {
gap: 0.5em;
}
.details {
display: flex;
justify-content: space-between;
}
.details p:last-child {
font-weight: bold;
}
.last {
font-size: 1.5em;
}
.more {
text-decoration: none;
color: #fff;
background-color: rgba(5, 149, 72, 0.841);
padding: 5px;
border-radius: 5px;
}
</style>
</head>
<body>
<header id="header">
<div class="brand">
<a href="./">PanierRapide.com</a>
</div>
<ul class="nav">
<li><a href="./article.php">Ajouter article</a></li>
<li class="helper">
<a href="./pannier.php"><span class="number"><?php echo $nb_panier ?? 0; ?></span>Pannier</a>
</li>
</ul>
</header>
<main>
<section class="banner">
<h3>Mon Pannier Rapide</h3>
<img src="https://images.unsplash.com/photo-1601330862030-1e08c703ac04?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8N3x8cGFuaWVyfGVufDB8fDB8fHww&auto=format&fit=crop&w=800&q=60" alt="">
</section>
<div class="content">
<h2>Mon Pannier</h2>
<div class="articles">
<table>
<thead>
<tr>
<th>titre</th>
<th>image</th>
<th>quantité</th>
<th>prix unitaire</th>
<th>total</th>
<th>action</th>
</tr>
</thead>
<tbody>
<?php if (!empty($paniers)) : ?>
<?php foreach ($paniers as $panier) : ?>
<tr>
<td>Tomate</td>
<td class="img">
<div class="imgBox">
<img src="<?php echo $panier['image']; ?>" alt="">
</div>
</td>
<td><input type="number" value="<?php echo $panier['quantite']; ?>" id="article<?php echo $panier['id']; ?>" min="1"></td>
<td><?php echo number_format($panier['prix'], 2, '.'); ?></td>
<td><?php echo number_format(($panier['prix'] * $panier['quantite']), 2, '.'); ?></td>
<td><i class="fas fa-check" style="color: blue; margin: 0.5em;" onclick="updateCart(event, <?php echo $panier['id']; ?>)"></i><i class="fas fa-trash" style="color: red; margin: 0.5em;" onclick="deleteCart(event, <?php echo $panier['id']; ?>)"></i></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="6">Aucun article dans le panier</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<div class="bilan">
<h4>Details facture</h4>
<?php if (!empty($paniers)) : ?>
<?php $total = 0; ?>
<div class="detailBox">
<?php foreach ($paniers as $panier) : ?>
<?php $total += $panier['prix'] * $panier['quantite']; ?>
<div class="details">
<p><?php echo $panier['nom']; ?></p>
<p><?php echo $panier['quantite'] . ' x ' . number_format($panier['prix'], 2, '.'); ?></p>
<p><?php echo number_format(($panier['prix'] * $panier['quantite']), 2, '.'); ?> FCFA</p>
</div>
<?php endforeach; ?>
<div class="details last">
<p>Total</p>
<p><?php echo number_format($total, 2, '.'); ?> FCFA</p>
</div>
<div class="details">
<a href="" class="more">Commander</a>
</div>
</div>
<?php else : ?>
<p>Aucune facture</p>
<?php endif; ?>
</div>
</div>
</div>
</main>
</body>
<script>
document.addEventListener('scroll', () => {
if (window.scrollY >= 10) {
document.querySelector('#header').classList.add('sticky')
} else {
document.querySelector('#header').classList.remove('sticky')
}
})
function updateCart(event, articleId) {
event.preventDefault(); // Empêche le comportement par défaut du lien
// Récupère la valeur de l'élément <input> en utilisant l'identifiant unique
var inputElement = document.getElementById("article" + articleId);
var quantite = inputElement.value;
let url = "./modifier_qte.php?article_id=" + articleId + "&qte=" + quantite;
window.location.href = url;
}
function deleteCart(event, articleId) {
event.preventDefault(); // Empêche le comportement par défaut du lien
// Récupère la valeur de l'élément <input> en utilisant l'identifiant unique
var inputElement = document.getElementById("article" + articleId);
if (confirm('Voulez vous réellement supprimer cet article du panier?')) {
let url = "./delete.php?article_id=" + articleId;
window.location.href = url;
}
}
</script>
</html>