-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcategory.php
95 lines (79 loc) · 2.92 KB
/
category.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
<?php
//Gọi cấu hình, thư viện được sử dụng
include 'libs/config.php';
include 'libs/functions.php';
//Khai báo các class sử dụng
use libs\classes\DBAccess;
use libs\classes\FlashMessage;
use libs\classes\DBPagination;
use libs\classes\HttpException;
use libs\classes\Validator;
$oDBAccess = new DBAccess();
$slug = '';
if(isset($_GET['slug'])) {
$slug = $_GET['slug'];
}
$category = $oDBAccess->findOneBySlug('category', $slug);
if(null === $category) {
throw new HttpException('Danh mục này không tồn tại', 500);
}
$where = "WHERE category_id={$category->id}";
//Lấy ra tổng số bản ghi
$totalRecord = intval($oDBAccess->scalarBySQL("SELECT COUNT(*) FROM product ".$where));
//Tạo ra đối tượng phân trang
$oDBPagination = new DBPagination($totalRecord, 16);
//Lấy ra danh sách các bản ghi
$list = $oDBAccess->findAllBySql("SELECT * FROM product $where ORDER BY created_at DESC {$oDBPagination->getLimit()}");
$breadcrumbList = array(
array(
'url' => 'category.php?slug='.$category->slug,
'title' => $category->title,
)
);
?>
<?php include 'libs/includes/frontend/header.inc.php'; ?>
<section id="bodyPage" class="clearfix">
<section id="leftPage">
<nav id="leftMenu"><?= renderFrontendLeftMenu($oDBAccess) ?></nav><!-- /#topMenu -->
</section><!-- /#leftPage -->
<section id="rightPage">
<?= renderBreadcrumb($breadcrumbList) ?>
<div class="category">
<div class="title-box clearfix">
<h2><?= $category->title ?></h2>
</div><!-- /.title-box -->
<div class="clearfix">
<?php if(!empty($list)): ?>
<?php foreach ($list as $item): ?>
<div class="product-item">
<div class="thumbs">
<a href="product.php?slug=<?= $item->slug ?>" title="<?= $item->title ?>">
<?php if($item->thumbnail !='' && file_exists(UPLOAD_DIR.$item->thumbnail)): ?>
<img src="<?= UPLOAD_DIR.'thumbs/'.$item->thumbnail ?>"/>
<?php endif; ?>
</a>
</div>
<p class="title"><a href="product.php?slug=<?= $item->slug ?>" title="<?= $item->title ?>"><?= $item->title ?></a></p>
<p class="price">
<?php if($item->price != 0): ?>
<?= vietnameseMoneyFormat($item->price, 'VND') ?>
<?php else: ?>
Liên hệ để biết giá
<?php endif; ?>
</p>
<button class="btn-add-cart" data-id="<?= $item->id ?>">Mua sản phẩm</button>
</div><!-- /.product-item -->
<?php endforeach; ?>
<?php else: ?>
<p>Danh mục không có sản phẩm.</p>
<?php endif; ?>
</div>
</div><!-- /.category -->
<?php if($oDBPagination->getMaxPage() > 1): ?>
<div class="pagination-link">
<?= $oDBPagination->renderPagination('category.php') ?>
</div>
<?php endif; ?>
</section><!-- /#rightPage -->
</section><!-- /#bodyPage -->
<?php include 'libs/includes/frontend/footer.inc.php'; ?>