-
Notifications
You must be signed in to change notification settings - Fork 0
/
site-checkout.php
120 lines (92 loc) · 2.83 KB
/
site-checkout.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
<?php
use \Hcode\Page;
use \Hcode\Model\Products;
use \Hcode\Model\User;
use \Hcode\Model\Category;
use \Hcode\Model\Cart;
use \Hcode\Model\Address;
use \Hcode\Model\Order;
use \Hcode\Model\OrderStatus;
$app->get("/checkout", function(){
User::verifyLogin(false);
$address = new Address();
$cart = Cart::getFromSession();
if (isset($_GET["zipcode"])) {
$_GET["zipcode"] = $cart->getdeszipcode();
}
if (isset($_GET["zipcode"])) {
$address->loadFromCEP($_GET["zipcode"]);
$cart->setdeszipcode($_GET["zipcode"]);
$cart->save();
$cart->getCalculateTotal();
}
if (!$address->getdesaddress()) $address->setdesaddress('');
if (!$address->getdesnumber()) $address->setdesnumber('');
if (!$address->getdescomplement()) $address->setdescomplement('');
if (!$address->getdesdistrict()) $address->setdesdistrict('');
if (!$address->getdescity()) $address->setdescity('');
if (!$address->getdesstate()) $address->setdesstate('');
if (!$address->getdescountry()) $address->setdescountry('');
if (!$address->getdeszipcode()) $address->setdeszipcode('');
$page= new Page();
$page->setTpl("checkout", [
"cart"=>$cart->getValues(),
"address"=>$address->getValues(),
"products"=>$cart->getProducts(),
"error"=>Address::getError()
]);
});
$app->post("/checkout", function(){
User::verifyLogin(false);
if (!isset($_POST["zipcode"]) || $_POST["zipcode"] === "") {
Address::seError("Informe o CEP");
header("Location: /checkout");
exit;
}
/*
if (!isset($_POST["desadress"]) || $_POST["desadress"] === "") {
Address::setError("Informe o endereço");
header("Location: /checkout");
exit;
}*/
if (!isset($_POST["desdistrict"]) || $_POST["desdistrict"] === "") {
Address::setError("Informe o bairro");
header("Location: /checkout");
exit;
}
if (!isset($_POST["descity"]) || $_POST["descity"] === "") {
Address::setError("Informe a cidade");
header("Location: /checkout");
exit;
}
if (!isset($_POST["desstate"]) || $_POST["desstate"] === "") {
Address::setError("Informe o estado");
header("Location: /checkout");
exit;
}
if (!isset($_POST["descountry"]) || $_POST["descountry"] === "") {
Cart::setError("Informe o país");
header("Location: /checkout");
exit;
}
$user = User::getFromSession();
$address = new Address();
$_POST["deszipcode"] = $_POST["zipcode"];
$_POST["idperson"] = $user->getidperson();
$address->setData($_POST);
$address->save();
$cart = Cart::getFromSession();
$cart->getCalculateTotal();
$order = new Order();
$order->setData([
"idcart"=>$cart->getidcart(),
"idaddress"=>$address->getidaddress(),
"iduser"=>$user->getiduser(),
"idstatus"=>OrderStatus::EM_ABERTO,
"vltotal"=>$cart->getvltotal()
]);
$order->save();
header("Location: /order/".$order->getidorder());
exit;
});
?>