Repository navigation
Expand file tree
/
Copy pathproduct.php
More file actions
207 lines (179 loc) · 7.05 KB
/
Copy pathproduct.php
File metadata and controls
207 lines (179 loc) · 7.05 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
require_once 'classes/Product.php';
$productObj = new Product();
$product = $productObj->getProductById($_GET['id']);
$images = json_decode($product['images'], true);
// Fetch recommended products by category
$recommendedProducts = $productObj->getRecommendedProductsByCategory($product['category'], $product['id']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($product['name']); ?></title>
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
<style>
body {
background-color: #f4f4f4;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 0;
margin: 0;
}
.main-image img {
width: 100%;
height: auto;
border-radius: 12px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.main-image img:hover {
transform: scale(1.1);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.thumbnail img {
width: 90px;
height: 90px;
object-fit: cover;
cursor: pointer;
border: 2px solid transparent;
margin: 5px;
border-radius: 8px;
transition: transform 0.3s ease, border-color 0.3s ease;
}
.thumbnail img:hover {
transform: scale(1.1);
}
.thumbnail img.active {
border-color: #007bff;
}
h1 {
font-size: 2.5rem;
font-weight: bold;
color: #333;
}
.stock {
font-size: 1.2rem;
font-weight: bold;
margin: 10px 0;
}
.stock.in-stock {
color: green;
}
.stock.out-of-stock {
color: red;
}
.recommendations {
margin-top: 40px;
}
.recommendations h3 {
font-size: 1.8rem;
margin-bottom: 20px;
text-align: center;
color: #555;
}
.recommendations .card {
border: none;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
border-radius: 12px;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.recommendations .card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.recommendations .card img {
height: 200px;
object-fit: cover;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
.btn {
font-size: 1rem;
padding: 10px 20px;
border-radius: 8px;
transition: background-color 0.3s ease, color 0.3s ease;
}
.btn:hover {
background-color: #0056b3;
color: #fff;
}
</style>
</head>
<body>
<?php include 'includes/header.php'; ?>
<div class="container">
<div class="row">
<div class="col-lg-6">
<!-- Main Image -->
<div class="main-image mb-3">
<img id="mainImage" src="uploads/<?php echo htmlspecialchars($images[0] ?? 'default.jpg'); ?>" alt="Product Image">
</div>
<!-- Thumbnails -->
<div class="thumbnail d-flex flex-wrap">
<?php foreach ($images as $index => $image) : ?>
<img
src="uploads/<?php echo htmlspecialchars($image); ?>"
alt="Thumbnail <?php echo $index + 1; ?>"
class="<?php echo $index === 0 ? 'active' : ''; ?>"
data-large="uploads/<?php echo htmlspecialchars($image); ?>">
<?php endforeach; ?>
</div>
</div>
<div class="col-lg-6">
<h1><?php echo htmlspecialchars($product['name']); ?></h1>
<p><?php echo nl2br(htmlspecialchars($product['description'])); ?></p>
<h4 class="text-success">$<?php echo htmlspecialchars($product['price']); ?></h4>
<p class="stock <?php echo $product['stock'] > 0 ? 'in-stock' : 'out-of-stock'; ?>">
<?php echo $product['stock'] > 0 ? "In Stock: {$product['stock']}" : "Out of Stock"; ?>
</p>
<a href="cart.php?action=add&id=<?php echo htmlspecialchars($product['id']); ?>"
class="btn btn-primary <?php echo $product['stock'] > 0 ? '' : 'disabled'; ?>">
Add to Cart
</a>
</div>
</div>
<!-- Recommendations -->
<div class="recommendations">
<h3>You May Also Like</h3>
<div class="row">
<?php foreach ($recommendedProducts as $recommended) : ?>
<div class="col-md-3">
<div class="card">
<?php
$images = json_decode($product['images'], true);
$firstImage = $images[0] ?? 'default.jpg';
?>
<img src="uploads/<?php echo htmlspecialchars($firstImage); ?>" class="card-img-top" alt="Product Image">
<div class="card-body">
<h5 class="card-title text-truncate"> <?php echo htmlspecialchars($recommended['name']); ?> </h5>
<p class="card-text">৳<?php echo htmlspecialchars($recommended['price']); ?></p>
<a href="product.php?id=<?php echo htmlspecialchars($recommended['id']); ?>" class="btn btn-primary">View</a>
<a href="cart.php?action=add&id=<?php echo htmlspecialchars($product['id']); ?>" class="btn btn-success">Add to Cart</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
<script>
// JavaScript to handle thumbnail click and update the main image
document.querySelectorAll('.thumbnail img').forEach((thumbnail) => {
thumbnail.addEventListener('click', function () {
// Remove active class from all thumbnails
document.querySelectorAll('.thumbnail img').forEach((img) => {
img.classList.remove('active');
});
// Add active class to the clicked thumbnail
this.classList.add('active');
// Update the main image
const mainImage = document.getElementById('mainImage');
mainImage.src = this.getAttribute('data-large');
});
});
</script>
</body>
</html>