-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkout.php
227 lines (209 loc) · 13.5 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
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
<?php
include ("header.php");
$cartArr=getUserFullCart();
if(count($cartArr)>0){
}else{
redirect(FRONT_SITE_PATH.'shop.php');
}
if(isset($_SESSION['FOOD_USER_ID'])){
$is_show='';
$box_id='';
$final_show='show';
$final_box_id='payment-2';
}else{
$is_show='show';
$box_id='payment-1';
$final_show='';
$final_box_id='';
}
$userArr=getUserDetailsByid();
if(isset($_POST['place_order'])){
$checkout_name=get_safe_value($_POST['checkout_name']);
$checkout_email=get_safe_value($_POST['checkout_email']);
$checkout_phone=get_safe_value($_POST['checkout_phone']);
$checkout_zip=get_safe_value($_POST['checkout_zip']);
$checkout_address=get_safe_value($_POST['checkout_address']);
$payment_type=get_safe_value($_POST['payment_type']);
if(isset($_SESSION['COUPON_CODE']) && isset($_SESSION['FINAL_PRICE'])){
$coupon_code=get_safe_value($_SESSION['COUPON_CODE']);
$final_price=get_safe_value($_SESSION['FINAL_PRICE']);
}else{
$coupon_code='';
$final_price=$totalPrice;
}
$added_on=date('Y-m-d h:i:s');
// This query is for Order Master Table. When user place an order it will take the user_id from Session. Naame, phone, email will will be getting from getUserDetailsByid() function. User will input their zip and address in the checkout page. The totalPrice is calculated in header.php.
$sql="insert into order_master(user_id,name,email,phone,address,zipcode,total_price,order_status,payment_status,added_on,payment_type,coupon_code,final_price) values('".$_SESSION['FOOD_USER_ID']."','$checkout_name','$checkout_email','$checkout_phone','$checkout_address','$checkout_zip','$totalPrice','1','pending','$added_on','$payment_type','$coupon_code','$final_price')";
mysqli_query($con,$sql);
// ID from order_master table
$insert_id=mysqli_insert_id($con);
$_SESSION['ORDER_ID']=$insert_id;
foreach($cartArr as $key=>$val){
// After placing the order their will be data for order_detail. order_id = the record inserted right now from order master table Primary id. dish_details_id getting from $key, price= .$val['price'] and qty= .$val['qty']
mysqli_query($con,"insert into order_detail(order_id,dish_details_id,price,qty) values('$insert_id','$key','".$val['price']."','".$val['qty']."')");
}
emptyCart();
$getUserDetailsBy=getUserDetailsByid();
redirect(FRONT_SITE_PATH.'success.php');
}
?>
<div class="checkout-area pb-80 pt-100">
<div class="container">
<div class="row">
<div class="col-lg-9">
<div class="checkout-wrapper">
<div id="faq" class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><span>1.</span> <a data-toggle="collapse" data-parent="#faq" href="#payment-1">Checkout method</a></h5>
</div>
<div id="<?php echo $box_id?>" class="panel-collapse collapse <?php echo $is_show?>">
<div class="panel-body">
<div class="row">
<div class="col-lg-12">
<div class="checkout-login">
<div class="title-wrap">
<h4 class="cart-bottom-title section-bg-white">LOGIN</h4>
</div>
<p> </p>
<form method="post" id="frmLogin">
<div class="login-form">
<label>Email Address * </label>
<input name="user_email" placeholder="Email" required>
</div>
<div class="login-form">
<label>Password *</label>
<input type="password" name="user_password" placeholder="Password" required>
<input type="hidden" name="type" value="login"/>
<input type="hidden" name="is_checkout" value="yes" id="is_checkout"/>
</div>
<div class="checkout-login-btn">
<button type="submit" id="login_submit" class="my_btn">Login</button>
<a href="<?php echo FRONT_SITE_PATH?>login_register.php" style="background-color: #e02c2b;color:#fff;">Register Now</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><span>2.</span> <a data-toggle="collapse" data-parent="#faq" href="#payment-2">Other information</a></h5>
</div>
<div id="<?php echo $final_box_id?>" class="panel-collapse collapse <?php echo $final_show?>">
<div class="panel-body">
<form method="post">
<div class="billing-information-wrapper">
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="billing-info">
<label>First Name</label>
<input type="text" name="checkout_name" required value="<?php echo $userArr['name']?>">
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="billing-info">
<label>Email Address</label>
<input type="email" name="checkout_email" required value="<?php echo $userArr['email']?>">
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="billing-info">
<label>Phone</label>
<input type="text" name="checkout_phone" required value="<?php echo $userArr['phone']?>">
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="billing-info">
<label>Zip/Postal Code</label>
<input type="text" name="checkout_zip" required>
</div>
</div>
<div class="col-lg-12 col-md-12">
<div class="billing-info">
<label>Address</label>
<input type="text" name="checkout_address" required>
</div>
</div>
<div class="col-lg-3 col-md-12">
<div class="billing-info">
<label>Coupon Code</label>
<input type="text" name="coupon_code" id="coupon_code">
</div>
<div id="coupon_code_msg"></div>
</div>
<div class="col-lg-5 col-md-12">
<div class="billing-back-btn">
<div class="billing-btn">
<button type="button" name="place_order" onclick="apply_coupon()">Apply Coupon</button>
</div>
</div>
</div>
</div>
<div class="ship-wrapper">
<div class="single-ship">
<input type="radio" name="payment_type" value="cod" checked="checked">
<label>Cash on Delivery(COD)</label>
</div>
<!--<div class="single-ship">
<input type="radio" name="address" value="dadress">
<label>Ship to different address</label>
</div>-->
</div>
<div class="billing-back-btn">
<div class="billing-btn">
<button type="submit" name="place_order">Place Your Order</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="checkout-progress">
<div class="shopping-cart-content-box">
<h4 class="checkout_title">Cart Details</h4>
<ul>
<?php foreach($cartArr as $key=>$list){ ?>
<li class="single-shopping-cart">
<div class="shopping-cart-img">
<a href="#"><img alt="" src="<?php echo SITE_DISH_IMAGE.$list['image']?>"></a>
</div>
<div class="shopping-cart-title">
<h4><a href="#">Phantom Remote </a></h4>
<h6>Qty: <?php echo $list['qty']?></h6>
<span><?php echo
// Calculate Price
$list['qty']*$list['price'];?> BDT</span>
</div>
</li>
<?php } ?>
</ul>
<div class="shopping-cart-total">
<h4>Total : <span class="shop-total"><?php echo $totalPrice?> BDT</span></h4>
</div>
<div class="shopping-cart-total coupon_price_box">
<h4>Coupon Code : <span class="shop-total coupon_code_str"></span></h4>
</div>
<div class="shopping-cart-total coupon_price_box">
<h4>Final Price : <span class="shop-total final_price"></span></h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
if(isset($_SESSION['COUPON_CODE'])){
unset($_SESSION['COUPON_CODE']);
unset($_SESSION['FINAL_PRICE']);
}
include("footer.php");
?>