-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder-update.php
98 lines (67 loc) · 2.96 KB
/
order-update.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
<?php
//if (session_status() !== PHP_SESSION_ACTIVE) {session_start();}
session_start();
$user = $_SESSION['email'];
$shipping = $_SESSION['shipping'];
include('confs/config.php');
if(isset($_SESSION['cart'])) {
$total = 0;
$itemqty = 0;
$query = $mysqli->query("INSERT INTO orders(customer,shipping_id,status,total_amt,total_qty,payment_type,created_date,modified_date)
VALUES('$user','$shipping',2,0,0,'Cash',NOW(),NOW())");
$order_id = mysqli_insert_id($mysqli);
foreach($_SESSION['cart'] as $product_id => $quantity) {
$result = $mysqli->query("SELECT * FROM product WHERE id = ".$product_id);
if($result){
if($obj = $result->fetch_object()) {
$cost = $obj->price * $quantity; //work out the line cost
$total = $total + $cost; //add to the total cost
$itemqty = $itemqty+$quantity;
// $user = $_SESSION["username"];
// Tax code
$taxRate=5;
$tax=$total*$taxRate/100;
$finaltotal=$total+$tax;
$query2 = $mysqli->query("INSERT INTO order_items (order_id,product_id, product_name, price, units, total, customer)
VALUES('$order_id','$obj->id', '$obj->product_name', $obj->price, $quantity, $cost, '$user')");
if($query2){
$newqty = $obj->qty - $quantity;
if($mysqli->query("UPDATE product SET qty = ".$newqty." WHERE id = ".$product_id)){
}
}
if($mysqli->query("UPDATE orders SET total_amt = ".$finaltotal.",total_qty =".$itemqty." WHERE order_id = ".$order_id)){
}
//send mail script
/*$query = $mysqli->query("SELECT * from orders order by date desc");
if($query){
while ($obj = $query->fetch_object()){
$subject = "Your Order ID ".$obj->id;
$message = "<html><body>";
$message .= '<p><h4>Order ID ->'.$obj->id.'</h4></p>';
$message .= '<p><strong>Date of Purchase</strong>: '.$obj->date.'</p>';
$message .= '<p><strong>Product Code</strong>: '.$obj->product_code.'</p>';
$message .= '<p><strong>Product Name</strong>: '.$obj->product_name.'</p>';
$message .= '<p><strong>Price Per Unit</strong>: '.$obj->price.'</p>';
$message .= '<p><strong>Units Bought</strong>: '.$obj->units.'</p>';
$message .= '<p><strong>Total Cost</strong>: '.$obj->total.'</p>';
$message .= "</body></html>";
$headers = "From: support@techbarrack.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$sent = mail($user, $subject, $message, $headers) ;
if($sent){
$message = "";
}
else {
echo 'Failure';
}
}
}*/
}
}
}
}
unset($_SESSION['shipping']);
unset($_SESSION['cart']);
header("location:success.php");
?>