-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
156 lines (148 loc) · 6.92 KB
/
Copy pathindex.php
File metadata and controls
156 lines (148 loc) · 6.92 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Homepage - Product Listing
*/
$pageTitle = 'Home';
require_once 'classes/Product.php';
$productModel = new Product();
$categories = $productModel->getCategories();
$selectedCategory = isset($_GET['category']) ? (int)$_GET['category'] : null;
$perPage = 12;
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$offset = ($page - 1) * $perPage;
$totalProducts = $productModel->getCount($selectedCategory);
$totalPages = max(1, (int)ceil($totalProducts / $perPage));
$products = $productModel->getAll($selectedCategory, $perPage, $offset);
$featuredProducts = $productModel->getFeatured(4);
require_once 'includes/header.php';
?>
<!-- Hero Section -->
<section class="hero">
<div class="hero-content">
<h1>Discover <span>Premium</span> Products</h1>
<p>Shop the latest trends in electronics, fashion, home essentials and more — all at unbeatable prices.</p>
<a href="#products" class="hero-cta">
<i class="fas fa-shopping-bag"></i> Start Shopping
</a>
</div>
</section>
<!-- Featured Products -->
<?php if (!$selectedCategory && !empty($featuredProducts)): ?>
<section class="section">
<div class="section-header">
<h2>⭐ Featured Products</h2>
</div>
<div class="product-grid">
<?php foreach ($featuredProducts as $p): ?>
<div class="product-card">
<div class="product-card-img">
<a href="product.php?id=<?= $p['id'] ?>">
<img src="<?= htmlspecialchars($p['image'] ?: 'assets/images/placeholder.png') ?>" alt="<?= htmlspecialchars($p['name']) ?>">
</a>
<span class="product-badge badge-featured">Featured</span>
<?php if ($isLoggedIn): ?>
<button class="product-card-wishlist btn-wishlist-toggle" data-id="<?= $p['id'] ?>" title="Add to Wishlist">
<i class="far fa-heart"></i>
</button>
<?php endif; ?>
<button class="product-card-quick btn-add-to-cart" data-id="<?= $p['id'] ?>" title="Add to Cart">
<i class="fas fa-cart-plus"></i>
</button>
</div>
<div class="product-card-body">
<div class="product-card-cat"><?= htmlspecialchars($p['category_name']) ?></div>
<h3 class="product-card-title"><a href="product.php?id=<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></a></h3>
<div class="product-card-price"><?= CURRENCY . number_format($p['price'], 2) ?></div>
<div class="product-card-rating">
<?php
$r = round($p['avg_rating']);
for ($i = 1; $i <= 5; $i++) {
echo '<i class="' . ($i <= $r ? 'fas' : 'far') . ' fa-star"></i>';
}
?>
<span>(<?= $p['review_count'] ?>)</span>
</div>
<div class="product-card-stock <?= $p['stock'] <= 0 ? 'out' : '' ?>">
<?= $p['stock'] > 0 ? $p['stock'] . ' in stock' : 'Out of stock' ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<!-- All Products -->
<section class="section" id="products">
<div class="section-header">
<h2>All Products</h2>
<div class="category-tabs">
<button class="cat-tab <?= !$selectedCategory ? 'active' : '' ?>" data-category="">All</button>
<?php foreach ($categories as $cat): ?>
<button class="cat-tab <?= $selectedCategory === (int)$cat['id'] ? 'active' : '' ?>" data-category="<?= $cat['id'] ?>">
<?= htmlspecialchars($cat['name']) ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php if (empty($products)): ?>
<div class="cart-empty">
<i class="fas fa-box-open"></i>
<h2>No products found</h2>
<p>Check back later or try a different category.</p>
</div>
<?php else: ?>
<div class="product-grid">
<?php foreach ($products as $p): ?>
<div class="product-card">
<div class="product-card-img">
<a href="product.php?id=<?= $p['id'] ?>">
<img src="<?= htmlspecialchars($p['image'] ?: 'assets/images/placeholder.png') ?>" alt="<?= htmlspecialchars($p['name']) ?>">
</a>
<?php if ($p['featured']): ?>
<span class="product-badge badge-featured">Featured</span>
<?php endif; ?>
<?php if ($isLoggedIn): ?>
<button class="product-card-wishlist btn-wishlist-toggle" data-id="<?= $p['id'] ?>" title="Add to Wishlist">
<i class="far fa-heart"></i>
</button>
<?php endif; ?>
<button class="product-card-quick btn-add-to-cart" data-id="<?= $p['id'] ?>" title="Add to Cart">
<i class="fas fa-cart-plus"></i>
</button>
</div>
<div class="product-card-body">
<div class="product-card-cat"><?= htmlspecialchars($p['category_name']) ?></div>
<h3 class="product-card-title"><a href="product.php?id=<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></a></h3>
<div class="product-card-price"><?= CURRENCY . number_format($p['price'], 2) ?></div>
<div class="product-card-rating">
<?php
$r = round($p['avg_rating']);
for ($i = 1; $i <= 5; $i++) {
echo '<i class="' . ($i <= $r ? 'fas' : 'far') . ' fa-star"></i>';
}
?>
<span>(<?= $p['review_count'] ?>)</span>
</div>
<div class="product-card-stock <?= $p['stock'] <= 0 ? 'out' : '' ?>">
<?= $p['stock'] > 0 ? $p['stock'] . ' in stock' : 'Out of stock' ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if ($totalPages > 1): ?>
<div class="pagination">
<?php if ($page > 1): ?>
<a href="?page=<?= $page - 1 ?><?= $selectedCategory ? '&category=' . $selectedCategory : '' ?>" class="pagination-link"><i class="fas fa-chevron-left"></i> Prev</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<a href="?page=<?= $i ?><?= $selectedCategory ? '&category=' . $selectedCategory : '' ?>" class="pagination-link <?= $i === $page ? 'active' : '' ?>"><?= $i ?></a>
<?php endfor; ?>
<?php if ($page < $totalPages): ?>
<a href="?page=<?= $page + 1 ?><?= $selectedCategory ? '&category=' . $selectedCategory : '' ?>" class="pagination-link">Next <i class="fas fa-chevron-right"></i></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</section>
<?php require_once 'includes/footer.php'; ?>