-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_cart.php
264 lines (193 loc) · 7.45 KB
/
my_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
<?php require_once'inc/header.php' ?>
<?php
require_once'inc/nav.php';
if(isset($_POST['submit'])){
if(!empty($_SESSION['cart'])){
foreach($_POST['quantity'] as $key => $val){
if($val==0){
unset($_SESSION['cart'][$key]);
}else{
$_SESSION['cart'][$key]['quantity']=$val;
}
}
echo "<script>alert('Your Cart hasbeen Updated');</script>";
}
}
if(isset($_POST['remove_code']))
{
if(!empty($_SESSION['cart'])){
foreach($_POST['remove_code'] as $key){
unset($_SESSION['cart'][$key]);
}
echo "<script>alert('Your Cart has been Updated');</script>";
}
}
if(isset($_POST['ordersubmit']))
{
$str = str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
$quantity=$_POST['quantity'];
$total_price = $_POST['total_price'];
$pdd=$_SESSION['pid'];
$value=array_combine($pdd,$quantity);
foreach($value as $qty=> $val34){
mysqli_query( $con , "INSERT into orders (userId, code , productId,quantity , Total_price , paymentMethod , orderStatus ) values('".$_SESSION['id']."', '$str' ,'$qty' ,'$val34' , '$total_price' , 'deli' , '0' )");
//unset($_SESSION['cart']);
header('location:information.php');
}
}
?>
<!-- ============================================== HEADER : END ============================================== -->
<div class="breadcrumb">
<div class="container">
<div class="breadcrumb-inner">
<ul class="list-inline list-unstyled">
<li><a href="#">Home</a></li>
<li class='active'>Shopping Cart</li>
</ul>
</div><!-- /.breadcrumb-inner -->
</div><!-- /.container -->
</div><!-- /.breadcrumb -->
<div class="body-content outer-top-xs">
<div class="container">
<div class="row ">
<div class="shopping-cart">
<div class="shopping-cart-table ">
<div class="table-responsive">
<form method="post" name="cart" >
<?php
if(!empty($_SESSION['cart'])){
?>
<table class="table">
<thead>
<tr>
<th class="cart-description item">Image</th>
<th class="cart-product-name item">Product Name</th>
<th class="cart-qty item">Quantity</th>
<th class="cart-sub-total item">Price</th>
<th class="cart-total last-item">Total</th>
<th class="cart-total last-item">function</th>
</tr>
</thead><!-- /thead -->
<tbody>
<?php
$pdtid=array();
$sql = "SELECT * FROM products WHERE id IN(";
foreach($_SESSION['cart'] as $id => $value)
{
$sql .=$id. ",";
}
$sql=substr($sql,0,-1) . ") ORDER BY id ASC";
$query = mysqli_query($con,$sql);
$totalprice=0;
$totalqunty=0;
if(!empty($query))
{
while($row = mysqli_fetch_array($query))
{
$quantity=$_SESSION['cart'][$row['id']]['quantity'];
$subtotal= $_SESSION['cart'][$row['id']]['quantity']*$row['price'];
$totalprice += $subtotal;
$_SESSION['qnty']=$totalqunty+=$quantity;
array_push($pdtid,$row['id']);
//print_r($_SESSION['pid'])=$pdtid;exit;
?>
<tr>
<td class="cart-image">
<a class="entry-thumbnail" href="detail.html">
<img src="admin/img/products/<?php echo $row['img1'];?>" alt="">
</a>
</td>
<td class="cart-product-name-info">
<h4 class='cart-product-description'><a href="detail.php?id=<?php echo $row['id'] ?>"><?php echo $row['name'];
?></a></h4>
<div class="cart-product-info">
<span class="product-color">Code:<span><?php echo $row['code'];?></span></span>
</div>
</td>
<td class="cart-product-quantity">
<div class="quant-input">
<div class="arrows">
<div class="arrow plus gradient"><span class="ir"><i class="icon fa fa-sort-asc"></i></span></div>
<div class="arrow minus gradient"><span class="ir"><i class="icon fa fa-sort-desc"></i></span></div>
</div>
<input type="text" value="<?php echo $_SESSION['cart'][$row['id']]['quantity']; ?>" name="quantity[<?php echo $row['id']; ?>]">
</div>
</td>
<td class="cart-product-sub-total"><span class="cart-sub-total-price"><?php echo " ".$row['price']; ?>.Ks</span></td>
<td class="cart-product-grand-total"><span class="cart-grand-total-price"><?php echo ($_SESSION['cart'][$row['id']]['quantity']*$row['price']); ?>.Ks</span></td>
<td>
<input type="submit" name="submit" value="Update" class="btn btn-upper btn-primary pull-right outer-right-xs">
<input type="hidden" value="" class="btn btn-upper btn-primary pull-right outer-right-xs">
<i class="fa fa" ><input type="submit" value="<?php echo htmlentities($row['id']);?>" name="remove_code[]" class="btn btn-upper btn-danger pull-right outer-right-xs"></i></td>
</tr>
<?php } }
$_SESSION['pid']=$pdtid;
?>
</tbody><!-- /tbody -->
</table>
<!-- /table -->
</div>
</div><!-- /.shopping-cart-table -->
<div class="col-md-4 col-sm-12 estimate-ship-tax">
<table class="table">
<thead>
<tr>
<th>
<span class="estimate-title">Enter your Informations</span>
<p>Enter your destination to get shipping and tax.</p>
</th>
</tr>
<tr>
<th>
<p>Enter your destination to get shipping and tax Enter your destination to get shipping and tax. Enter your destination to get shipping and tax Enter your destination to get shipping and tax </p>
</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody><!-- /thead -->
</table>
</div><!-- /.estimate-ship-tax -->
<div class="col-md-4 col-sm-12 estimate-ship-tax">
</div><!-- /.estimate-ship-tax -->
<div class="col-md-4 col-sm-12 cart-shopping-total">
<table class="table">
<thead>
<tr>
<th>
<div class="cart-grand-total">
<input name="total_price" type="hidden" value="<?php echo $_SESSION['tp']="$totalprice"; ?>" >
Grand Total<span class="inner-left-md"><?php echo $_SESSION['tp']="$totalprice". ".KS"; ?></span>
</div>
</th>
</tr>
</thead><!-- /thead -->
<tbody>
<tr>
<td>
<div class="cart-checkout-btn pull-right">
<button name="ordersubmit" class="btn btn-primary checkout-btn">PROCCED TO CHEKOUT</button>
</div>
</td>
</tr>
</tbody><!-- /tbody -->
</table>
<?php } else {
echo "Your shopping Cart is empty";
}?>
</div> </div>
</div>
</form>
<!-- /table -->
</div><!-- /.cart-shopping-total --> </div><!-- /.shopping-cart -->
</div> <!-- /.row -->
<!-- ============================================== BRANDS CAROUSEL ============================================== -->
<!-- ============================================== BRANDS CAROUSEL : END ============================================== --> </div><!-- /.container -->
</div><!-- /.body-content -->
<!-- ============================================================= FOOTER ============================================================= -->
<!-- ============================================== INFO BOXES ============================================== -->
<?php require_once'inc/footer_bar.php' ?>
<!-- /.info-boxes -->
<!-- ============================================== INFO BOXES : END ============================================== -->
<?php require_once'inc/footer.php' ?>