-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout_action.php
46 lines (37 loc) · 989 Bytes
/
checkout_action.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
<?php
include_once "datatabase/query.php";
include_once "session.php";
$userId = $_POST['userId'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$address = $_POST['address'];
updateData('users',$userId,[
'name' => $name,
'phone' => $phone,
'address' => $address
]);
$result = insertData('orders',[
'order_no' => time(),
'user_id' => $userId
]);
$orderId = $result['id'];
$cart = getSessionData('cart');
$total = 0;
foreach ($cart as $key => $value) {
insertData('order_product',[
'order_id' => $orderId,
'product_id' => $key,
'qty' => $value['qty']
]);
$total += $value['price'] * $value['qty'];
}
updateData('orders',$orderId,[
'total' => $total+50
]);
deleteSession('cart');
if (checkSessionIsSet('success')) {
$success = getSessionData('success');
array_push($success, "Your Order Is Placed!!");
addToSession('success',$success);
}
header('location: order_single.php?order_no='.$result['order_no']);