This repository was archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaceOrder.php
executable file
·108 lines (95 loc) · 4.57 KB
/
placeOrder.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
<?php
session_start();
require_once('essentials/config.php');
include "dbConfig.php";
$customer = $_SESSION['email'];
$customer_id = $_SESSION['id'];
$shipping = $_SESSION['shipping'];
$sql = "SELECT * FROM shipping WHERE shipping_id = $shipping";
$run = mysqli_query($connect, $sql);
$row = mysqli_fetch_assoc($run);
$store_id = $row['store_id'];
$full_name = $row['full_name'];
$email_address = $row['email'];
$street_address = $row['street_address'];
$city = $row['city'];
$state = $row['state'];
$phone = $row['phone'];
$pincode = $row['pincode'];
$sendEmail = new sendEmail;
$time_now = date('Y-m-d H:i:s');
if (isset($_SESSION['cart'])) {
$total = 0;
$itemqty = 0;
$query = $connect->query("INSERT INTO orders(customer_id,email,full_name, store_id, phone, street_address, state, city, pincode,status,total_amt,total_qty,payment_type,created_date,modified_date)
VALUES('$customer_id','$email_address','$full_name','$store_id','$phone','$street_address','$state','$city','$pincode',1,0,0,'COD',NOW(),NOW())");
$order_id = mysqli_insert_id($connect);
foreach ($_SESSION['cart'] as $variant_id => $quantity) {
$find_pro_id = mysqli_query($connect, "SELECT * FROM variant WHERE variant_id='$variant_id'");
$pro_data = mysqli_fetch_assoc($find_pro_id);
$product_id = $pro_data['product_id'];
$result = $connect->query("SELECT * FROM product WHERE id = " . $product_id);
if ($result) {
if ($obj = $result->fetch_object()) {
$cost = $obj->cost * $quantity;
$total += $cost;
$itemqty += $quantity;
$query2 = $connect->query("INSERT INTO order_detail (order_id,product_id, variant_id, customer_id, product_name, price, units, total, customer)
VALUES('$order_id','$obj->id','$variant_id','$customer_id','$obj->name', '$obj->cost', '$quantity', '$cost', '$customer')");
if ($query2) {
$newqty = $obj->qty - $quantity;
if ($connect->query("UPDATE product SET qty = " . $newqty . " WHERE id = " . $product_id)) {
$connect->query("UPDATE variant SET qty = " . $newqty . " WHERE variant_id = " . $variant_id);
}
}
if ($connect->query("UPDATE orders SET total_amt = " . $total . ",total_qty =" . $itemqty . " WHERE order_id = " . $order_id)) {
}
}
}
}
}
$url = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/myOrder.php?id=" . $order_id;
$url2 = "https://" . $_SERVER['SERVER_NAME'] . "/aanav/contact.php";
$subject = 'New Order successfully placed';
$body = '<p style="color:#66FCF1; font-size: 32px;" > Hi ' . $full_name . '</p><p
style="color:grey; font-size: 16px;" > Your order worth <span style="color:green;" > ₹ ' . $total . '</span> was placed successfully at
<span style="color:green;"> ' . $time_now . '</span>.<br> Merchant may contact you in 2 to 3 working days.Happy Shopping</p>
<p><a style="background-color: #66FCF1;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;"
href="' . $url . '">View Order Details</a></p><p style="color:grey; font-size: 10px;" > Ordered by mistake ? <a style="color:red; font-family:bolder; font-size: 10px;text-decoration: none;" href="' . $url2 . '"> Contact Admin </a></p>';
$sendEmail->send($full_name, $customer, $subject, $body);
$admin_name = "Admin";
$admin_email = "[email protected]";
$subject = "A new order was placed";
$body = '<p style="color:#66FCF1; font-size: 32px;" > Hi ' . $admin_name . '</p><p
style="color:grey; font-size: 16px;" >A new order worth <span style="color:green;" > ₹ ' .
$total . '</span> was placed by ' . $full_name . ' at <span style="color:green;"> ' . $time_now . ' </p>
<p><a style="background-color: #66FCF1;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;"
href="' . $url . '"> Approve Order </a></p><p style="color:grey; font-size: 10px;" > Out of stock ? <a style="color:red; font-family:bolder; font-size: 10px;text-decoration: none;" href="' . $url . '"> Cancel Order </a></p>';
$sendEmail->send($admin_name, $admin_email, $subject, $body);
unset($_SESSION['shipping']);
unset($_SESSION['cart']);
echo '<script>
location.href="orderConfirmation.php?id='.$order_id.'"
</script>';