-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout-product.php
47 lines (47 loc) · 1.73 KB
/
checkout-product.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
<?php
require_once('Model/BaseModel.php');
require_once('View/TemplateRenderer.php');
$model = new BaseModel();
$template = new TemplateRenderer();
foreach ($_GET as $key => $value) {
$x = explode("//", $key);
}
$userId = $x[0];
if ($userId == '{{_userId_}}') {
header('Location: ' . 'login.php');
} else {
if ($userId > 0) {
$productId = $x[1];
$decide = $x[2];
switch ($decide) {
case "DELETE":
$model->cartDeleteItem($userId, $productId);
break;
case "DOWN1":
if($model->verifyCartQuantity($userId, $productId)) {
$model->cartDeleteQuantityItem($userId, $productId);
} else {
$model->cartDeleteItem($userId, $productId);
}
break;
case "UP1":
$productStock = $model->getProductStock($productId);
$newQuantity = $model->getCartStock($userId, $productId);
if ($productStock[0]['quantity'] >= $newQuantity['quantity'] + 1) {
$model->cartAddQuantityItem($userId, $productId);
}
break;
case "INP":
$inpValue = $_GET[$x[0]."//".$x[1]."//".$x[2]];
if (is_numeric($inpValue) && $inpValue > 0 && $inpValue == round($inpValue)) {
$productStock = $model->getProductStock($productId);
if ($productStock[0]['quantity'] >= $inpValue) {
$model->cartSetQuantityItem($userId, $productId, $inpValue);
}
}
break;
}
}
echo $template->render('', "checkout");
}
?>