forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.php
253 lines (223 loc) · 9.31 KB
/
payment.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
<?php
session_start();
// including database connection
include('database.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Payment</title>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo1.svg">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script
src="https://kit.fontawesome.com/db79afedbd.js"
crossorigin="anonymous"
></script>
<script src="jquery.js"></script>
<script src="main.js"></script>
</head>
<body>
<!-- including header -->
<?php
include 'header.php';
?>
<!------------------------------------------------- main body----------------------------------------------------------->
<div class="container d-lg-flex">
<div class="col-md-8 mb-4">
<div class="card mb-4">
<div class="card-header py-3">
<h5 class="mb-0">Order details</h5>
</div>
<div class="card-body">
<div class="container">
<table class="table">
<!-- table head -->
<thead class="text-center">
<tr>
<th scope="col"> Product image </th>
<th scope="col">Product Name</th>
<th scope="col">Product Price</th>
<th scope="col">Quantity</th>
</tr>
</thead>
<!-- table body -->
<tbody class="text-center">
<?php
$gtotal = 0;
if(isset($_POST['continue'])){
$caddress=$_POST['address'].", ".$_POST['state'].", ".$_POST['country']." -".$_POST['zip'];
$_SESSION['address']=$caddress;
}
else
{
$caddress=$_SESSION['address'];
}
// if cart is not empty then we will show all the products in cart
foreach($_SESSION['cart'] as $key => $value)
{
// fetching product details from database
$product_id=$value['product_id'];
$product_quantity=$value['Quantity'];
$sql="SELECT * FROM product WHERE product_id = '$product_id'";
$result=mysqli_query($conn,$sql);
// checking if product is available in database or not
while($row=mysqli_fetch_assoc($result))
{
// storing product details in variables
$p_name=$row['product_name'];
$p_price=$row['product_price'];
$p_image=$row['product_img'];
} // end of while loop
// displaying product details in table
echo"
<tr>
<td><img src='app/$p_image' width='80px' height='60px'></td>
<td>$p_name</td>
<td>$p_price<input type='hidden' class='iprice' value='$p_price'></td>
<td>$product_quantity Pcs
</td>
</tr>
";
$total = $p_price*$value['Quantity'];
$gtotal = $gtotal + $total;
} // end of foreach loop
?>
</tbody>
</table>
</div>
<form>
<!-- 2 column grid layout with text inputs for the first and last names -->
<div class="row mb-2">
<!-- Text input -->
<div class="form-outline mb-4">
<label class="form-label h6" for="form7Example4">Shipping Address</label>
<input type="text" id="form7Example4" disabled class="form-control" value="<?=$caddress?>" />
</div>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-4 ms-lg-4 mb-4">
<div class="card mb-4">
<div class="card-header py-3">
<h5 class="mb-0">Summary</h5>
</div>
<div class="card-body">
<!-- List group -->
<ul class="list-group list-group-flush">
<!-- Subtotal -->
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 pb-2">
Subtotal
<span id="gtotal">₹ <?=$gtotal?></span>
</li>
<?php
// if coupon code is applied then we will show discount amount
if(isset($_POST['apply_coupon']))
{
// fetching coupon details from database
$coupon_code=$_POST['coupon_code'];
$sql="SELECT * FROM Coupon WHERE code='$coupon_code'";
$result=mysqli_query($conn,$sql);
$row_count = mysqli_num_rows($result);
// checking if coupon code is valid or not
if($row_count==0)
{
echo"
<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Sorry!</strong> Coupon code is invalid.
<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button>
</div>
";
}
// checking if coupon code is expired or not
else
{
$row=mysqli_fetch_assoc($result);
$exp_date=$row['exp_date'];
$discount=$row['discount'];
$today=date('Y-m-d');
// checking if coupon code is expired or not
if($today>$exp_date)
{
echo"
<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Sorry!</strong> Coupon code is expired.
<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button>
</div>
";
}
// if coupon code is valid then we will show discount amount
else
{
$gtotal=$gtotal-($gtotal*$discount/100);
echo"
<div>
<p>Coupon Code: <strong class='text-success'>$coupon_code </strong>Applied</p>
<p>Discount: <strong>$discount% </strong></p>
</div>
<div class='alert alert-success alert-dismissible fade show' role='alert'>
<strong>Congratulations!</strong>You have got $discount% discount.
<button type='button' class=': GET10 Applied
btn-close' data-bs-dismiss='alert' aria-label='Close'></button>
</div>
<script>
gtotal.innerHTML='₹$gtotal';
</script>
";
}
}
}
?>
<!-- apply coupon code -->
<li class="list-group-item d-flex justify-content-center">
<form method="POST">
<!-- apply coupon code -->
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Coupon Code" aria-label="Coupon Code" aria-describedby="button-addon2" name="coupon_code">
<button class="btn btn-outline-secondary" type="submit" id="button-addon2" name="apply_coupon">Apply</button>
</div>
</form>
</li>
<!-- payment method -->
<li class="list-group-item">
<div class="form-check">
<input class="form-check-input" type="radio" value="COD" id="flexRadioDefault2" checked>
<label class="form-check-label" for="flexRadioDefault2">
Cash On Delivery
</label>
</div>
</li>
<!-- total amount -->
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 mb-3">
<div>
<strong>Total amount</strong>
</div>
<span id="gtotal">₹<?=$gtotal?></span>
</li>
</ul>
<!-- Purchase button -->
<form action="purchase.php" method="POST">
<input type="hidden" name="discount" value="<?=$discount?>">
<button type="submit" name="purchase" class="btn btn-primary btn-lg btn-block">
Place Order
</button>
</form>
</div>
</div>
</div>
</div>
<!-----------------------------------------------------footer ---------------------------------->
<?php
include 'footer.php';
?>
</body>