-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcart.php
380 lines (322 loc) · 17.2 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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
session_start();
$pageName = 'Votre Panier';
include_once 'assets/mainHead.php';
include_once 'autoload.php';
include_once 'isAuthentificated.php';
$display = "cart";
$total = array();
$wishProductRep = new WishProductRepository();
$productRep = new ProductRepository();
$cartRep = new CartRepository();
$userRep = new UserRepository();
$user = $userRep->findOneBy(array('username' => $_SESSION['user']));
$cartElements = $cartRep->findBy(array('userId' => $_SESSION['user']));
if (isset($_POST['removeWished'])) {
$display = "wishlist";
$removedId = $_POST['productRemoved'];
$wishProductRep->deleteTwo('productId', $removedId, 'userId', $_SESSION['user']);
}
if (isset($_POST['removeProduct'])) {
$removedId = $_POST['productRemoved'];
$cartRep->deleteTwo('productId', $removedId, 'userId', $_SESSION['user']);
header('location:cart.php');
}
if (isset($_POST['PayDelivery'])) {
$method = $_POST['method'];
$date = $_POST['date'];
$adress = $_POST['adress'];
$phone = $_POST['phone'];
$amount = $_POST['total'];
$cmdRep = new CommandRepository();
$cmdRep->addCommand(array($_SESSION['user'], date('Y-m-d'), 'submitted', $amount, $adress, $phone, date('Y-m-d', strtotime(date('Y-m-d') . ' + 2 days')), $method));
$cartRep->delete(array('userId' => $_SESSION['user']));
header('location:cart.php');
$display = "order";
}
?>
<link rel="stylesheet" href="css/cart.css">
</head>
<body>
<?php include_once 'navbarCo.php' ?>
<div style="margin-bottom:100px" class="wrapp">
<div class="navbarCart">
<div id="cart" class="navbarCartElementWrapper <?php if ($display == 'cart') {
echo 'active';
} ?>">
<div class="navbarCartElement ">
<i class="fas fa-shopping-cart "></i>
<h5>Panier</h5>
</div>
<div class="arrow-right"></div>
</div>
<div id="catalogue" class="navbarCartElementWrapper">
<a href="shopping.php" class="navbarCartElement">
<i class="fas fa-book-open"></i>
<h5>Catalogue</h5>
</a>
<div class="arrow-right"></div>
</div>
<div id="wishlist" class="navbarCartElementWrapper <?php if ($display == 'wishlist') {
echo 'active';
} ?>">
<div class="navbarCartElement">
<i class="fas fa-heart"></i>
<h5>Wishlist</h5>
</div>
<div class="arrow-right"></div>
</div>
<div id="order" class="navbarCartElementWrapper <?php if ($display == 'order') {
echo 'active';
} ?>">
<div class="navbarCartElement">
<i class="fas fa-shipping-fast"></i>
<h5>Orders</h5>
</div>
<div class="arrow-right"></div>
</div>
</div>
<div class="cart" style="display:<?php if ($display == 'cart') {
echo 'block';
} else {
echo 'none';
} ?>">
<?php if (!$cartElements) { ?>
<div class="panierVide">
<div class="load">
<i class="fas fa-shopping-cart "></i>
<i class="fas fa-shopping-cart "></i>
<i class="fas fa-shopping-cart "></i>
<i class="fas fa-shopping-cart "></i>
</div>
<div>
<h2 id="visiterCatalogue">Votre panier est vide ... Revenez au catalogue et remplissez le !</h2>
</div>
</div>
<?php } else { ?>
<div class="cartElements">
<?php
foreach ($cartElements as $cartElement) {
$productElement = $productRep->findOneBy(array('id' => $cartElement['productId']))
?>
<div class="cartElementWrapper">
<div class="cartElement">
<div class="info">
<h6>12345 -</h6>
<h4><?= $productElement['name'] ?></h4>
<div class="details">
<h6>Prix : <?= $productElement['price'] ?> Dt</h6>
<h6>Quantité : <?= $cartElement['quantity'] ?></h6>
<?php $totalProduct = intval($productElement['price'], 10) * intval($cartElement['quantity'], 10);
array_push($total, $totalProduct);
?>
<h6>Total : <?= $totalProduct ?> Dt</h6>
</div>
</div>
<div class="gestion">
<span>
<a href="product.php?view=<?= $productElement['id'] ?>">
<i class="fas fa-eye"></i>
</a>
</span>
<span>
<form action="cart.php" method="post">
<input type="hidden" name="productRemoved" value="<?= $productElement['id'] ?>">
<button type="submit" name="removeProduct" class="btn btn2">
<i class="removeElement fas fa-times-circle"></i>
</button>
</form>
</span>
</div>
</div>
<div class="details">
<h6>Prix : <?= $productElement['price'] ?> Dt</h6>
<h6>Quantité : <?= $cartElement['quantity'] ?></h6>
<h6>Total : <?= $totalProduct ?> Dt</h6>
</div>
</div>
<?php
}
?>
<div class="total">
<img src="images/totalCart.jpg" alt="">
<span>Total:</span>
<span><?php echo array_sum($total) ?> Dt</span>
</div>
<div class="tel">
<img src="images/telCart.png" alt="">
<span>Telephone: </span>
<input type="text" id="num" value="<?php if (isset($user['phoneNumber'])) {
echo $user['phoneNumber'];
} ?>">
</div>
<div class="adresse">
<img src="images/adresseCart.png" alt="">
<span>Adresse: </span>
<span id="locAddress"><?php if (isset($user['address'])) {
echo $user['address'];
} ?> </span>
<button id="changeLocation" class="btn btn3"><?php if (isset($user['address'])) {
echo "Changer Adresse";
} else {
echo "Ajouter Adresse";
} ?></button>
</div>
<div class="confirm">
<input id="confirmCart" type="submit" value="Valider mes achats">
</div>
</div>
<div class=" locationPopUp">
<h1 class="closeLocationPopUp"> ×</h1>
<span>Veuillez choisir une adresse </span>
<div id="mapAddress">
</div>
<button class="btn btn3 " id="mybutton1">Confirmer</button>
</div>
<div class="paymentPopUp ">
<h1 class="closePaymentPopUp"> ×</h1>
<div class="payElements">
<?php
foreach ($cartElements as $cartElement) {
$productElement = $productRep->findOneBy(array('id' => $cartElement['productId']))
?>
<div class="payElement">
<div class="infoElement">
<h4><?= $productElement['name'] ?></h4>
</div>
<div class="detailsElement">
<h6>Prix : <?= $productElement['price'] ?> Dt</h6>
<h6>Quantité : <?= $cartElement['quantity'] ?></h6>
<?php $totalProduct = intval($productElement['price'], 10) * intval($cartElement['quantity'], 10);
?>
<h6>Total : <?= $totalProduct ?> Dt</h6>
</div>
</div>
<?php } ?>
</div>
<form method="post">
<div class="paymentInfo">
<div class="paymentTotal">
<img src="images/totalCart.jpg" alt="">
<span>Total:</span>
<span> <?php echo array_sum($total) ?> Dt</span>
<input name="total" value="<?php echo array_sum($total) ?>" type="hidden">
</div>
<div class="paymentAdress">
<img src="images/adresseCart.png" alt="">
<span>Adresse: </span>
<span id="popupAdresse"><?php if (isset($user['address'])) {
echo $user['address'];
} ?></span>
<input name="adress" id="adresseInput" value="<?php if (isset($user['address'])) {
echo $user['address'];
} ?>" type="hidden">
</div>
<div class="paymentTel">
<img src="images/telCart.png" alt="">
<span>Téléphone: </span>
<span id="popupNum"><?php if (isset($user['phoneNumber'])) {
echo $user['phoneNumber'];
} ?> </span>
<input id="numInput" name="phone" value="<?php if (isset($user['phoneNumber'])) {
echo $user['phoneNumber'];
} ?>" type="hidden">
</div>
<div class="paymentDelivery">
<img src="images/deliveryCart.png" alt="">
<span>La livraison sera dans 48 heures :</span>
<span> <?php echo date('Y-m-d', strtotime(date('Y-m-d') . ' + 2 days')); ?> </span>
<input name="date" value="<?php echo date('Y-m-d', strtotime(date('Y-m-d') . ' + 2 days')); ?>" type="hidden">
</div>
<input name="method" type="hidden" value="livraison">
</div>
<input class="pay" name="PayDelivery" type="submit" value="Payer à la livraison">
</form>
<div class="payment">
<form action="checkout-charge.php" method="post">
<input type="hidden" name="amount" value="<?php echo array_sum($total) ?>">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_51J1SzJE3gsjF0BrLVeytp4haD9b0CDM5IbkhmTDnCVDYrNekt7CXbwdjdgheujajglAOcMr4Y0lMX3j08b2RbXv400PpkHkqjz" data-currency="inr" data-locale="auto">
</script>
</form>
</div>
</div>
<?php } ?>
<div id="overlayCart" class=""></div>
<div class="sendPost"></div>
</div>
<div class="wishlist" style="display:<?php if ($display == 'wishlist') {
echo 'block';
} else {
echo 'none';
} ?>">
<?php
$wishes = $wishProductRep->findBy(array('userId' => $_SESSION['user']));
foreach ($wishes as $wish) {
$wishedProduct = $productRep->findOneBy(array('id' => $wish['productId']));
?>
<div class="cartElements" style="padding: 0 !important;">
<div class="cartElementWrapper">
<div class="cartElement" >
<div class="info">
<h4><?= $wishedProduct['name'] ?></h4>
<div class="details">
<h6>Prix : <?= $wishedProduct['price'] ?></h6>
</div>
</div>
<div class="gestion">
<span>
<a href="product.php?view=<?= $wishedProduct['id'] ?>"><i class="fas fa-eye"></i></a>
</span>
<span>
<form action="cart.php" method="post">
<input type="hidden" name="productRemoved" value="<?= $wishedProduct['id'] ?>">
<button type="submit" name="removeWished" class="btn btn2">
<i class="removeElement fas fa-times-circle"></i>
</button>
</form>
</span>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<div class="order" style="display:<?php if ($display == 'order') {
echo 'block';
} else {
echo 'none';
} ?>">
<?php $cmdRep = new CommandRepository();
$orders = $cmdRep->findBy(array('userId' => $_SESSION['user']));
foreach ($orders as $order) {
?>
<div class="cartElementWrapper">
<div class="cartElement">
<div class="info">
<h6>Commande -</h6>
<div class="details">
<h6>Total : <?= $order['total'] ?> Dt</h6>
<h6>Date Commande : <?= $order['date'] ?></h6>
<h6>Date Livraison : <?= $order['deliveryDate'] ?></h6>
<h6>Etat Commande : <?= $order['status'] ?></h6>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php include_once 'assets/scripts.php' ?>
<?php include_once 'footer.php' ?>
<script src="js/testnav.js"></script>
<script src="js/cart.js"></script>
<!--script pour map-->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCQpw0VdM_Cpj50OfKTRMJbP1SK7wzYcAE&callback=initMap&libraries=places" type="text/javascript"></script>
<script src="js/cart.js"></script>
<script src="testnav.js"></script>
</body>
</html>