-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtw_product_page.php
More file actions
164 lines (144 loc) · 6.72 KB
/
Copy pathrtw_product_page.php
File metadata and controls
164 lines (144 loc) · 6.72 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
<?php
$title = 'مشاهده محصول';
require_once 'includes/header.php';
?>
<?php
require_once 'db/db_connection.php';
if (isset($_GET['id'])) {
$product_id = intval($_GET['id']); // Ensure ID is an integer
// Fetch product information
$stmt = $db_connect->prepare("SELECT * FROM rtw_products WHERE id = ?");
$stmt->bind_param("i", $product_id);
$stmt->execute();
$product = $stmt->get_result()->fetch_assoc();
// Fetch color, size, and stock information
$stmt1 = $db_connect->prepare("SELECT * FROM color_size WHERE product_id = ?");
$stmt1->bind_param("i", $product_id);
$stmt1->execute();
$color_size_result = $stmt1->get_result();
} else {
echo "<p>محصول یافت نشد.</p>";
exit;
}
?>
<!-- Display -->
<section class="more-info">
<?php if ($product): ?>
<div class="main-details">
<!-- Product Text Details -->
<div class="text">
<h1><?php echo htmlspecialchars($product['نام']); ?></h1>
<!-- Colors -->
<?php if ($color_size_result->num_rows > 0): ?>
<p>رنگ:</p>
<div class="choice">
<?php while ($row = $color_size_result->fetch_assoc()): ?>
<button class="more-btn color-btn" data-color="<?php echo htmlspecialchars($row['رنگ']); ?>">
<?php echo htmlspecialchars($row['رنگ']); ?>
</button>
<?php endwhile; ?>
</div>
<?php else: ?>
<p>اطلاعاتی برای رنگ در دسترس نیست.</p>
<?php endif; ?>
<!-- Sizes -->
<?php if ($color_size_result->num_rows > 0): ?>
<p>اندازه:</p>
<div class="choice">
<?php
// Reset result set pointer to reuse
$color_size_result->data_seek(0);
while ($row = $color_size_result->fetch_assoc()): ?>
<button class="more-btn size-btn" data-size="<?php echo htmlspecialchars($row['سایز']); ?>">
<?php echo htmlspecialchars($row['سایز']); ?>
</button>
<?php endwhile; ?>
</div>
<?php else: ?>
<p>اطلاعاتی برای اندازه در دسترس نیست.</p>
<?php endif; ?>
<p><?php echo number_format($product['قیمت']); ?> تومان</p>
<!-- Add to Cart -->
<form method="POST" action="cart.php">
<input type="hidden" name="product_id" value="<?php echo $product['id']; ?>">
<input type="hidden" name="product_img" value="<?php echo $product['تصویر1']; ?>">
<input type="hidden" name="product_name" value="<?php echo htmlspecialchars($product['نام']); ?>">
<input type="hidden" name="product_price" value="<?php echo $product['قیمت']; ?>">
<input type="hidden" name="product_color" id="selected_color" value="">
<input type="hidden" name="product_size" id="selected_size" value="">
<button class="secondary-btn" type="submit" name="add_to_cart">افزودن به سبد خرید</button>
</form>
</div>
<!-- Product Images -->
<div class="imgs">
<img src="images/rtw/<?php echo $product['تصویر1']; ?>" alt="<?php echo htmlspecialchars($product['نام']); ?>" id="mainImg">
<div class="small-img-group">
<?php for ($i = 1; $i <= 4; $i++): ?>
<?php if (!empty($product['تصویر' . $i])): ?>
<img src="images/rtw/<?php echo $product['تصویر' . $i]; ?>" class="small-img">
<?php endif; ?>
<?php endfor; ?>
</div>
</div>
</div>
<!-- Product Details Table -->
<div class="details-table">
<h3>اطلاعات بیشتر</h3>
<table>
<?php
$details = [
'جنس پارچه' => $product['جنس_پارچه'],
'قد' => $product['قد'],
'آستین' => $product['آستین'],
'نحوه بسته شدن' => $product['نحوه_بسته_شدن'],
'مدل یقه جلو و پشت' => $product['یقه_جلو_پشت'],
'کاپدوزی' => $product['کاپ'],
'فنردوزی' => $product['فنردوزی'],
'آستردوزی' => $product['آستردوزی'],
'دنباله' => $product['دنباله'],
'نحوه شستشو' => $product['شستشو']
];
foreach ($details as $key => $value):
if (!empty($value)): ?>
<tr>
<td class="detail-key"><?php echo $key; ?></td>
<td class="detail-value"><?php echo $value; ?></td>
</tr>
<?php endif;
endforeach; ?>
</table>
</div>
<?php else: ?>
<p>محصول یافت نشد.</p>
<?php endif; ?>
</section>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Update selected color or size
document.querySelectorAll('.color-btn, .size-btn').forEach(button => {
button.addEventListener('click', function () {
const isColor = this.classList.contains('color-btn');
const choiceContainer = this.closest('.choice');
// Remove selected class from siblings
choiceContainer.querySelectorAll('button').forEach(btn => btn.classList.remove('selected'));
// Add selected class to clicked button
this.classList.add('selected');
// Update hidden input
if (isColor) {
document.getElementById('selected_color').value = this.dataset.color;
} else {
document.getElementById('selected_size').value = this.dataset.size;
}
});
});
// Image switcher
const mainImg = document.getElementById('mainImg');
const smallImgs = document.querySelectorAll('.small-img');
smallImgs.forEach(img => {
img.addEventListener('click', () => {
mainImg.src = img.src;
});
});
});
</script>
<?php require_once 'includes/footer.php'; ?>