-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
166 lines (130 loc) · 5.96 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
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
<?php
session_start();
include_once "includes/config.php";
//supprimer les produits
//si la variable del existe
if(isset($_GET['del'])){
$id_del = $_GET['del'] ;
//suppression
unset($_SESSION['panier'][$id_del]);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EShop</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="Free HTML Templates" name="keywords">
<meta content="Free HTML Templates" name="description">
<!-- Favicon -->
<link href="img/favicon.ico" rel="icon">
<!-- Google Web Fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
<!-- Libraries Stylesheet -->
<link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
<!-- Customized Bootstrap Stylesheet -->
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<!-- Topbar Start -->
<?php
include 'includes/topBar.php';
?>
<!-- Topbar End -->
<!-- Navbar Start -->
<?php
include 'includes/navbar1.php';
?>
<!-- Navbar End -->
<!-- Page Header Start -->
<div class="container-fluid bg-secondary mb-5">
<div class="d-flex flex-column align-items-center justify-content-center" style="min-height: 300px">
<h1 class="font-weight-semi-bold text-uppercase mb-3">PANIER</h1>
</div>
</div>
<!-- Page Header End -->
<!-- Cart Start -->
<div class="container-fluid pt-5">
<div class="row px-xl-5">
<div class="col-lg-8 table-responsive mb-5">
<table class="table table-bordered text-center mb-0">
<thead class="bg-secondary text-dark">
<tr>
<th>Articles</th>
<th>Prix</th>
<th>Quantité</th>
<th>Total</th>
<th>Enlever</th>
</tr>
</thead>
<tbody class="align-middle">
<?php
$total = 0 ;
// liste des produits
//récupérer les clés du tableau session
$ids = array_keys($_SESSION['panier']);
//s'il n'y a aucune clé dans le tableau
if(empty($ids)){
echo "Votre panier est vide";
}else {
//si oui
$products = $db->query( "SELECT `article`.`id`, `article`.`designation`, `article`.`image`, `article`.`prix`, `article`.`prixB`, `article`.`stock`, `article`.`description`, `article`.`categorie`, `article`.`site`,categorie.categorie,site.nom FROM `article`,categorie,site WHERE categorie.id=article.categorie AND site.id=article.site AND article.id IN (".implode(',', $ids).")");
//lise des produit avec une boucle foreach
foreach($products as $product):
//calculer le total ( prix unitaire * quantité)
//et aditionner chaque résutats a chaque tour de boucle
$total = $total + $product['prix'] * $_SESSION['panier'][$product['id']] ;
?>
<tr>
<td class="align-middle"><img src="upload/<?=$product['image']?>" alt="" style="width: 50px;"> <?=$product['designation']?></td>
<td class="align-middle">$<?=$product['prix']?></td>
<td class="align-middle"><?=$_SESSION['panier'][$product['id']] // Quantité?></td>
<td class="align-middle">$<?=$_SESSION['panier'][$product['id']]* $product['prix']// Quantité?></td>
<td class="align-middle"><a href="cart.php?del=<?=$product['id']?>" class="btn btn-sm btn-primary"><i class="fa fa-times"></i></a></td>
</tr>
<?php endforeach ;} ?>
</tbody>
</table>
</div>
<div class="col-lg-4">
<div class="card border-secondary mb-5">
<div class="card-header bg-secondary border-0">
<h4 class="font-weight-semi-bold m-0">Resumé du panier</h4>
</div>
<div class="card-body">
</div>
<div class="card-footer border-secondary bg-transparent">
<div class="d-flex justify-content-between mt-2">
<h5 class="font-weight-bold">Total</h5>
<h5 class="font-weight-bold">$<?=$total?></h5>
</div>
<a href="confirm.php" class="btn btn-block btn-primary my-3 py-3">Confirmer</a>
</div>
</div>
</div>
</div>
</div>
<!-- Cart End -->
<!-- Footer Start -->
<?php
include 'includes/footer.php';
?>
<!-- Footer End -->
<!-- Back to Top -->
<a href="#" class="btn btn-primary back-to-top"><i class="fa fa-angle-double-up"></i></a>
<!-- JavaScript Libraries -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
<script src="lib/easing/easing.min.js"></script>
<script src="lib/owlcarousel/owl.carousel.min.js"></script>
<!-- Contact Javascript File -->
<script src="mail/jqBootstrapValidation.min.js"></script>
<script src="mail/contact.js"></script>
<!-- Template Javascript -->
<script src="js/main.js"></script>
</body>
</html>