-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_handler.php
44 lines (31 loc) · 929 Bytes
/
order_handler.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
<?php
include 'database.php';
include 'checkoutClass.php';
include 'user.php';
session_start();
if(!isset($_SESSION['checkoutInfo']) || !$_SESSION['logged_in']){
header('Location:index.php');
}
else{
$dao = new Database();
$keys = $_SESSION['checkoutInfo']->getParts();
foreach($keys as $key){
if(!$dao->inCart( $key, $_SESSION['user']->getAccountID())) {
header('Location:cart.php');
exit;
}
}
}
$dao = new Database();
$oID = uniqid();
$dao->addOrder($oID, $_SESSION['checkoutInfo']->getTotal(), $_SESSION['user']->getAccountID());
$keys = $_SESSION['checkoutInfo']->getParts();
$array = $_SESSION['checkoutInfo']->getArray();
foreach($keys as $key){
$dao->addOrderManifest($oID, $key, $array[$key]);
$dao->updateStock($key, $array[$key]);
}
$_SESSION['checkoutInfo'] = NULL;
$dao->deleteCart($_SESSION['user']->getAccountID());
header('Location: viewOrders.php');
?>