-
Notifications
You must be signed in to change notification settings - Fork 21
/
cart.php
327 lines (262 loc) · 13.5 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
<?php
define('Access', TRUE);
//SESSION START
include "./AdditionalPHP/startSession.php";
//DATABASE CONNECTION cakeshop
include_once 'connection.php';
?>
<?php
//Remove button
//The remove button loads the same page but carries some additional info in url
//cart.php?action=delete&product_id=<?php echo ...
//checks if url contains action=delete
if(filter_input(INPUT_GET, 'action') == 'delete'){
//loops through all products in shopping cart session array until id matches url
foreach($_SESSION['shopping_cart'] as $key => $product){
//checks if product_id in url (when remove button clicked) matches the one
//in the shopping cart session array
if($product['id'] == filter_input(INPUT_GET, 'product_id')){
//remove product from shopping cart session array
unset($_SESSION['shopping_cart'][$key]);
}//end if
}//end foreach
//reset session array keys so they match with $product_ids numeric array
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
//DELETE ROW FROM CARTITEM TABLE
$Q_delete_cartitem = 'DELETE FROM cartitem WHERE productID = '.filter_input(INPUT_GET, 'product_id');
$run_delete_cartitem = mysqli_query($conn, $Q_delete_cartitem);
}//end if
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MALAKO | Details</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--========== PHP CONNECTION TO DATABASE: MALAKO ==========-->
<?php
include_once 'numOfItemsInCart.php';
?>
<!--========== CSS FILES ==========-->
<link rel="stylesheet" type="text/css" href="Common.css">
<link rel="stylesheet" type="text/css" href="Sanjana.css">
<link href="jquery.nice-number.css" rel="stylesheet">
<!--========== JQUERY CDN ==========-->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="jquery.nice-number.js"> </script>
<script type="text/javascript">
$(function(){
$('input[type="number"]').niceNumber();
});
</script>
<!--========== BOOTSTRAP ==========-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<!-- Bootstrap Core CSS -->
<!-- <link rel="stylesheet" href="./bootstrap/css/bootstrap.css"> -->
<!-- <link rel='stylesheet' type='text/css' href='style.php' /> -->
<!-- Font Awesome -->
<script src="https://kit.fontawesome.com/0e16635bd7.js" crossorigin="anonymous"></script>
<!-- Animate CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<!--========== BOXICONS ==========-->
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
</head>
<body>
<!--========== PHP QUERIES ==========-->
<?php
$Q_fetch_featured = "SELECT * FROM products INNER JOIN product_type ON products.productID = product_type.productID WHERE product_type.typeID = 2"; //selects featured products
$Q_fetch_new = "SELECT * FROM products INNER JOIN product_type ON products.productID = product_type.productID WHERE product_type.typeID = 1"; //selects new products
$Q_fetch_product_details = "SELECT * FROM products INNER JOIN product_type ON products.productID = product_type.productID WHERE product_type.typeID = 2"; //selects product with id =1
$Q_fetch__all_products = "SELECT * FROM products";
?>
<!--========== HEADER ==========-->
<?php $page = 'cart'?>
<!--Start Navigation Bar-->
<?php include './Includes/MobileNavBar.php';?>
<!--End Navigation Bar-->
<!--Start Navigation Bar @media 1200px-->
<?php include './Includes/PcNavBar.php';?>
<!--End Navigation Bar @media 1200px-->
<!--========== CART STRUCTURE ==========-->
<div class="row mx-auto">
<!-- Cart items -->
<div class="col-lg">
<!-- title -->
<div class="row-md title-cart">
<!-- <h1>M Y   C A R T</h1> -->
<h1 text-center>MY CART  </h1>
<i class='bx bxs-cart-download bx-tada-hover'></i>
</div>
<!-- header of order details -->
<div class="cart_title_bar mx-1 ">
<div class="cart-title-1">
<h2 class="section-title hide-wave"> </h2>
</div>
<div class="cart-title-2">
<h4 class="section-all my-0 py-0 hide-wave">Item Details</h4>
</div>
<div class="cart-title-3">
<h4 class="section-all my-0 py-0 hide-wave">Quantity</h4>
</div>
<div class="cart-title-4">
<h4 class="section-all my-0 py-0 hide-wave">Total Price (Rs)</h4>
</div>
<div class="cart-title-5">
<h4 class="section-all my-0 py-0 hide-wave">Remove</h4>
</div>
</div>
<!-- Loop through session shopping cart -->
<?php
//if shopping cart not empty
if(!empty($_SESSION['shopping_cart'])){
//create total variable
$total = 0;
$_SESSION['total_quantity'] = 0;
//loop through each item in shopping cart
foreach($_SESSION['shopping_cart'] as $key => $product){
?>
<!-- Receipt item card -->
<div class="receipt-card mt-2 mb-3 mx-1 py-3">
<!-- product image -->
<?php
$result_product = mysqli_query($conn, $Q_fetch__all_products);
$check = mysqli_num_rows($result_product);
if($check>0){ //checks if $result empty in database
//loops through all items in products table in database
while($product_row = mysqli_fetch_assoc($result_product)){
//compare if id in database in current loop is equal to
//id in current session shopping cart foreach loop
if($product_row['productID'] == $product['id']){
?>
<!-- prints image from database of corresponding id -->
<div class="cart_img">
<img src="<?php echo $product_row['p_img']; ?>" class="img-fluid">
</div>
<?php
}//end if
}//end while
}//end if check
?>
<!-- <div class="cart_img">
<img src="Assets\images\products\Cake_2.jpg" class="img-fluid">
</div> -->
<!-- product details -->
<div class="">
<!-- product name -->
<div class="product-name">
<div class="product-name-det">
<h6><?php echo $product['name'];?></h6>
<h6>Rs <?php echo number_format($product['price'], 2);?> / unit</h6>
</div>
</div>
</div>
<!-- quantity -->
<div class="quantity-value">
<h6><?php echo $product['quantity'];?></h6>
</div>
<!-- product total price -->
<div class="tot-price-per-item ">
<h6>Rs <?php echo number_format($product['quantity'] * $product['price'], 2); ?></h6>
</div>
<!-- Remove -->
<div class="remove-button">
<!-- product['id'] is fetching id from session shopping cart array -->
<a href="cart.php?action=delete&product_id=<?php echo $product['id'];?>">
<button type="button" class="btn btn-primary btn-lg my-4 button rem-but"><i class='bx bx-x rem-but-x' style='color:#ffffff; font-size: 1.3rem ;'></i></button>
</a>
</div>
</div>
<?php
//CALCULATING TOTAL PRICE
$total = $total + ($product['quantity'] * $product['price']);
//CREATE SESSION FOR TOTAL PRICE
$_SESSION['total_price'] = $total;
}//end foreach
?>
</div>
<!-- Receipt -->
<div class="col-md container receipt-area mx-auto">
<!-- Summary -->
<div class="row summary-area">
<h1 class="subtitle">SUMMARY</h1>
</div>
<div class="row container receipt-data mx-auto pt-3">
<!-- subtotal -->
<div class="row container subtotal-area my-1">
<div class="col">
<h4 class="subtitle title-checkout">SUBTOTAL: </h4>
</div>
<div class="col">
<h4 class="subtitle">Rs <?php echo number_format($total, 2); ?></h4>
</div>
</div>
<!-- delivery -->
<div class="row container delivery-area my-1">
<div class="col">
<h4 class="subtitle title-checkout">DELIVERY: </h4>
</div>
<div class="col">
<h4 class="subtitle">Rs 0.00</h4>
</div>
</div>
<!-- total -->
<div class="row container total-area my-1 pt-2">
<div class="col">
<h4 class="subtitle title-checkout">TOTAL: </h4>
</div>
<div class="col">
<h4 class="subtitle">Rs <?php echo number_format($total, 2); ?></h4>
</div>
</div>
<!-- checkout -->
<!-- show checkout if shopping cart array not empty -->
<?php
//check if shopping cart not empty
if(isset($_SESSION['shopping_cart']));{
//check if shopping cart contains more than 0 products
if(count($_SESSION['shopping_cart'])>0){
?>
<div class="row checkout-area">
<a href="checkout.php">
<button type="button" class="btn btn-primary btn-lg my-4 button">Checkout</button>
</a>
</div>
<?php
}//end count if
if(count($_SESSION['shopping_cart']) == 0) {
echo('<h1 class="subtitle">Your cart is empty!</h1>');
}
}//end isset if
if(!isset($_SESSION['shopping_cart'])) {
echo('<h1 class="subtitle">Your cart is empty!</h1>');
}
?>
</div>
</div>
<?php
}//end if at start
//Displays msg if cart is emty
if(isset($_SESSION['shopping_cart'])) {
if(count($_SESSION['shopping_cart']) == 0) {
echo('<h1 class="text-center my-3">Your cart is empty!</h1>');
echo('<div class="text-center py-3"><img src="Assets\images\cart\sad.png" class="img-fluid" style="max-width:17%;"></div>');
echo('<div class="text-center py-3"><a href="products.php" class="button button__round">SHOP NOW</a></div>');
}//end if session shopping cart == 0
}//end if isset
else { //if shopping cart is not set
echo('<h1 class="text-center my-3">Your cart is empty!</h1>');
echo('<div class="text-center py-3"><img src="Assets\images\cart\sad.png" class="img-fluid" style="max-width:17%;"></div>');
echo('<div class="text-center py-3"><a href="products.php" class="button button__round">SHOP NOW</a></div>');
}
?>
</div>
<!--Start Footer-->
<?php include './Includes/Footer.php';?>
<!--End Footer-->
<!-- Start Bottom Nav -->
<?php include './Includes/MobileBottomNav.php';?>
<!-- End Bottom Nav -->
<!-- <script src="Javascript\main.js?<?php //echo filemtime('Javascript\main.js'); ?>" ></script> -->
</body>
</html>