-
Notifications
You must be signed in to change notification settings - Fork 6
/
site-cart.php
81 lines (46 loc) · 1.21 KB
/
site-cart.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
<?php
use Hcode\Page;
use Hcode\Model\Cart;
use Hcode\Model\Product;
$app->get("/cart", function(){
$cart = Cart::getFromSession();
$page = new Page();
$page->setTpl("cart", [
'cart'=>$cart->getValues(),
'products'=>$cart->getProducts(),
'error'=>Cart::getMsgError()
]);
});
$app->get("/cart/:idproduct/add", function($idproduct){
$product = new Product();
$product->get((int)$idproduct);
$cart = Cart::getFromSession();
$qtd = (isset($_GET['qtd'])) ? (int)$_GET['qtd'] : 1;
for ($i = 0; $i < $qtd; $i++) {
$cart->addProduct($product);
}
header("Location: /cart");
exit;
});
$app->get("/cart/:idproduct/minus", function($idproduct){
$product = new Product();
$product->get((int)$idproduct);
$cart = Cart::getFromSession();
$cart->removeProduct($product);
header("Location: /cart");
exit;
});
$app->get("/cart/:idproduct/remove", function($idproduct){
$product = new Product();
$product->get((int)$idproduct);
$cart = Cart::getFromSession();
$cart->removeProduct($product, true);
header("Location: /cart");
exit;
});
$app->post("/cart/freight", function(){
$cart = Cart::getFromSession();
$cart->setFreight($_POST['zipcode']);
header("Location: /cart");
exit;
});