-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckoutProcess.php
More file actions
50 lines (33 loc) · 1.59 KB
/
checkoutProcess.php
File metadata and controls
50 lines (33 loc) · 1.59 KB
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
<?php
include "connection.php";
session_start();
$user = $_SESSION["u"];
if (isset($_POST["payment"])) {
$payment = json_decode($_POST["payment"], true);
$date = new DateTime();
$date->setTimezone(new DateTimeZone("Asia/Colombo"));
$time = $date->format("Y-m-d H-i-s");
Database::iud("INSERT INTO `order_history`(`order_id`,`order_date`,`amount`,`user_email`)
VALUES('" . $payment["order_id"] . "','" . $time . "','" . $payment["amount"] . "','" . $user["email"] . "')");
$orderHistoryId = Database::$connection->insert_id;
error_log("Order History ID (checkout): " . $orderHistoryId);
$rs = Database::search("SELECT * FROM `cart` WHERE `user_email`='" . $user["email"] . "'");
$num = $rs->num_rows;
for ($i = 0; $i < $num; $i++) {
//Order Items Insert
$d = $rs->fetch_assoc();
Database::iud("INSERT INTO `order_item`(`order_item_qty`,`order_history_order_h_id`,`stock_stock_id`)
VALUES('" . $d["cart_qty"] . "','" . $orderHistoryId . "','" . $d["stock_stock_id"] . "')");
$rs2 = Database::search("SELECT * FROM `stock` WHERE `stock_id`='" . $d["stock_stock_id"] . "'");
$d2 = $rs2->fetch_assoc();
$newQty = $d2["qty"] - $d["cart_qty"];
Database::iud("UPDATE `stock` SET `qty`='" . $newQty . "' WHERE `stock_id`='" . $d["stock_stock_id"] . "'");
}
Database::iud("DELETE FROM `cart` WHERE `user_email`='" . $user["email"] . "'");
// echo("success");
$order = array();
$order["resp"] = "success";
$order["order_id"] = $orderHistoryId;
echo json_encode($order);
}
?>