-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsite.php
66 lines (44 loc) · 1.17 KB
/
site.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
<?php
use \Hcode\Page;
use \Hcode\Model\Product;
use \Hcode\Model\Category;
use \Hcode\Model\Cart;
use \Hcode\Model\Address;
use \Hcode\Model\User;
use \Hcode\Model\Order;
use \Hcode\Model\OrderStatus;
$app->get('/', function() {
$products = Product::listAll();
$page = new Page();
$page->setTpl("index", [
'products'=>Product::checkList($products)
]);
});
$app->get("/categories/:idcategory", function($idcategory){
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$category = new Category();
$category->get((int)$idcategory);
$pagination = $category->getProductsPage($page);
$pages = [];
for ($i=1; $i <= $pagination['pages']; $i++) {
array_push($pages, [
'link'=>'/categories/'.$category->getidcategory().'?page='.$i,
'page'=>$i
]);
}
$page = new Page();
$page->setTpl("category", [
'category'=>$category->getValues(),
'products'=>$pagination["data"],
'pages'=>$pages
]);
});
$app->get("/products/:desurl", function($desurl){
$product = new Product();
$product->getFromURL($desurl);
$page = new Page();
$page->setTpl("product-detail", [
'product'=>$product->getValues(),
'categories'=>$product->getCategories()
]);
});