-
Notifications
You must be signed in to change notification settings - Fork 13
/
order.php
172 lines (104 loc) · 3.7 KB
/
order.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
<?php
include("includes/db.php");
include("functions/functions.php");
//retrieving customer id that was passed from payment page
if(isset($_GET['c_id'])){
$customer_id=$_GET['c_id']; //local variable to save a customer id
$c_email ="select * from customers WHERE customer_id='$customer_id'";
//sending email
$run_email=mysqli_query($con,$c_email);
$row_customer=mysqli_fetch_array($run_email);
$customer_email=$row_customer['customer_email'];
$customer_name=$row_customer['customer_name'];
}
//getting products information/no. of items from cart
$ip_add = getRealIpAddress();
$total =0;
$select_price = "select * from cart where ip_add = '$ip_add'";
$run_price = mysqli_query($db, $select_price);
$status='Pending';//initial status of a product
$invoice_no = mt_rand();//generate random number
$count_pro=mysqli_num_rows($run_price); //total products
$i=0;
$message="
<html>
<body>
<p>
Hello <b style='color:blue;'> $customer_name, </b> <br>
Please find your order summary bellow. Please login to your account and make a payment for any pending orders. </p>
<table width='600' align='center' bgcolor='FFCC99' border='2'>
<tr> <h2> Your Order Summary.<br>
Invoice Number: $invoice_no </br></h2></tr>
<tr>
<th> Product Name </b> </th>
<th> Quantity </b> </th>
<th> Total Price </b> </th>
</tr>
";
while($record=mysqli_fetch_array($run_price))
{
$product_id = $record['p_id'];
$prod_price = "select * from products where product_id = '$product_id'";
$run_product_price = mysqli_query($db, $prod_price);
while($p_price=mysqli_fetch_array($run_product_price))
{
$product_name=$p_price['product_title'];
$product_price = array($p_price['product_price']); //get product price from table column in DB
$value = array_sum($product_price); // sum all the values
$total += $value;
$i++;
}
$message.="
<tr>
<td> $product_name </td>";
//end of while
//getting quantity form the cart
$get_cart ="Select * from cart WHERE ip_add = '$ip_add'";
$run_cart=mysqli_query($con,$get_cart);
$get_qty= mysqli_fetch_array($run_cart);
$qty=$get_qty['qty']; //saving qty from database to local variable
if($qty==0)
{
//change the variable
$qty=1;
$sub_total =$total;
}
else
{
$qty=$qty;
$sub_total=$total*$qty;
}
//if($run_order)
//{
echo "<script>window.open('customer/my_account.php','_self')</script>";
$empty_cart="delete from cart where ip_add='$ip_add'"; //empty the cart once the order has been submitted
$run_empty=mysqli_query($con,$empty_cart);
$insert_to_pending_order="insert into pending_orders(customer_id,invoice_no,product_id,qty,order_status) values('$customer_id','$invoice_no','$product_id','$qty','$status')";
$run_pending_order=mysqli_query($con,$insert_to_pending_order);
$message.="<td> $qty </td>
<td> #$value </td>
</tr>";
}
$message.="
<tr>
<td> YOUR SUBTOTAL IS #$sub_total </td>
</tr></table>
<h3> Thank you for your order </h3>
</body>
</html>
";
//SENDING INVOICE TO CUSTOMER
//}
$insert_order="insert into customer_orders(customer_id,due_amount,invoice_no,total_products,order_date,order_status) values('$customer_id','$sub_total','$invoice_no','$count_pro',NOW(),'$status')";
$run_order = mysqli_query($con,$insert_order);
echo "<script>alert('Order details sent!! $message') </script>";
$subject = 'Your Order Details';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: echo $customer_email'. "\r\n";
$headers .= 'From: [email protected]';
// Mail it
mail($customer_email, $subject, $message, $headers);
?>