forked from sajjadsaleem341/Plant-Nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
161 lines (146 loc) · 7.08 KB
/
checkout.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
<?php
include "header.php";
// $msg='';
if(isset($_SESSION['USER_LOGIN']) && $_SESSION['USER_LOGIN']!=''){
}
else {
echo "<script>window.location.href='Index.php'</script>";
die();
}
if(!isset($_SESSION['cart']) || count($_SESSION['cart'])==0){
// echo $msg;
echo "<script>window.location.href='shop.php'</script>";
}
$cart_total=0;
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$price=$productArr[0]['Price'];
$qty=$val['qty'];
$cart_total=$cart_total+($price*$qty);
}
if(isset($_POST['submit'])){
$user_id=$_SESSION['USER_ID'];
$address=get_safe_value($con,$_POST['address']);
$email=get_safe_value($con,$_POST['email']);
$mobile=get_safe_value($con,$_POST['mobile']);
$city=get_safe_value($con,$_POST['city']);
$area=get_safe_value($con,$_POST['area']);
$pincode=get_safe_value($con,$_POST['pincode']);
$comment=get_safe_value($con,$_POST['comment']);
$total_price=$cart_total;
$order_status='1';
$date=date('y-m-d h:m:s');
$tracking_id= "#".rand(1111111,9999999);
mysqli_query($con,"insert into orders (Tracking_Id,User_Id,Email,Mobile,Address,City,Area,Pincode,Comment,Total_Price,Order_Status,Date) values('$tracking_id','$user_id','$email','$mobile','$address','$city','$area','$pincode','$comment','$total_price','$order_status','$date')");
$order_id=mysqli_insert_id($con);
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$price=$productArr[0]['Price'];
$qty=$val['qty'];
mysqli_query($con,"insert into orders_detail (Order_Id,Product_Id,Qty,Price) values('$order_id','$key','$qty','$price')");
}
unset($_SESSION['cart']);
echo "<script>window.location.href='thankyou.php'</script>";
}
?>
<!-- ##### Breadcrumb Area Start ##### -->
<div class="breadcrumb-area">
<!-- Top Breadcrumb Area -->
<div class="top-breadcrumb-area bg-img bg-overlay d-flex align-items-center justify-content-center" style="background-image: url(img/bg-img/24.jpg);">
<h2>Checkout</h2>
</div>
<div class="container">
<div class="row">
<div class="col-12">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#"><i class="fa fa-home"></i> Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Checkout</li>
</ol>
</nav>
</div>
</div>
</div>
</div>
<!-- ##### Breadcrumb Area End ##### -->
<!-- ##### Checkout Area Start ##### -->
<div class="checkout_area mb-100">
<div class="container">
<div class="row justify-content-between">
<div class="col-12 col-lg-7">
<div class="checkout_details_area clearfix">
<h5>Billing Details</h5>
<form action="" method="post">
<div class="row">
<div class="col-12 mb-4">
<label for="email_address">Email Address *</label>
<input type="email" class="form-control" id="email_address" name="email" value="" required>
</div>
<div class="col-12 mb-4">
<label for="phone_number">Phone Number *</label>
<input type="number" class="form-control" id="phone_number" name="mobile" min="0" value="" required>
</div>
<div class="col-12 mb-4">
<label for="company">Address *</label>
<input type="text" class="form-control" id="address" name="address" value="" required>
</div>
<div class="col-md-4 mb-4">
<label for="city">Town/City *</label>
<input type="text" class="form-control" id="city" name="city" value="" required>
</div>
<div class="col-md-4 mb-4">
<label for="state">Area *</label>
<input type="text" class="form-control" id="state" name="area" value="" required>
</div>
<div class="col-md-4 mb-4">
<label for="postcode">Postcode/Zip</label>
<input type="text" class="form-control" id="postcode" name="pincode" value="" required>
</div>
<div class="col-md-12 mb-4">
<label for="order-notes">Order Notes</label>
<textarea class="form-control" id="order-notes" name="comment" cols="30" rows="10" placeholder="Notes about your order, e.g. special notes for delivery."></textarea>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-4">
<div class="checkout-content">
<h5 class="title--">Your Order</h5>
<div class="products">
<div class="products-data">
<h5>Products:</h5>
<?php
$cart_total=0;
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$price=$productArr[0]['Price'];
$qty=$val['qty'];
$cart_total=$cart_total+($price*$qty);}
?>
</div>
</div>
<div class="subtotal d-flex justify-content-between align-items-center">
<h5>Subtotal</h5>
<h5>$<?= $cart_total ?></h5>
</div>
<div class="shipping d-flex justify-content-between align-items-center">
<h5>Shipping</h5>
<h5>$<?= round($cart_total*2/100) ?></h5>
</div>
<div class="order-total d-flex justify-content-between align-items-center">
<h5>Order Total</h5>
<h5>$<?= round($cart_total*2/100+$cart_total) ?></h5>
</div>
<div class="checkout-btn mt-30">
<input type="submit" name="submit" class="btn alazea-btn w-100" value="Place Order">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- ##### Checkout Area End ##### -->
<?php
include 'footer.php';
?>