-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
21 lines (21 loc) · 897 Bytes
/
checkout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
require_once('Model/BaseModel.php');
require_once('View/TemplateRenderer.php');
$model = new BaseModel();
$template = new TemplateRenderer();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$userId = $_POST['pk'];
$userDetailId = $model->orderDetailInsert($_POST['firstName'], $_POST['lastName'], $_POST['email'], $_POST['phoneNumber'], $_POST['address'],
$_POST['city'], $_POST['additionalInfo']);
$products = $model->getUserCartByUserId($userId);
foreach ($products as $product) {
$model->orderInsert($userId, $product['productId'], $product['quantity'], 'aprobat', $userDetailId);
$model->updateStock($product['productId'], $product['quantity']);
$model->cartDeleteItem($userId, $product['productId']);
}
sleep(3);
header('Location: ' . 'my-order.php');
} else {
echo $template->render('', "checkout");
}
?>