forked from hammadshahir/PHP-MySQL-ecommerce-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
219 lines (194 loc) · 8.39 KB
/
cart.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
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
208
209
210
211
212
213
214
215
216
217
218
219
<?php require_once('header.php'); ?>
<?php
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$banner_cart = $row['banner_cart'];
}
?>
<?php
$error_message = '';
if(isset($_POST['form1'])) {
$i = 0;
$statement = $pdo->prepare("SELECT * FROM tbl_product");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$i++;
$table_product_id[$i] = $row['p_id'];
$table_quantity[$i] = $row['p_qty'];
}
$i=0;
foreach($_POST['product_id'] as $val) {
$i++;
$arr1[$i] = $val;
}
$i=0;
foreach($_POST['quantity'] as $val) {
$i++;
$arr2[$i] = $val;
}
$i=0;
foreach($_POST['product_name'] as $val) {
$i++;
$arr3[$i] = $val;
}
$allow_update = 1;
for($i=1;$i<=count($arr1);$i++) {
for($j=1;$j<=count($table_product_id);$j++) {
if($arr1[$i] == $table_product_id[$j]) {
$temp_index = $j;
break;
}
}
if($table_quantity[$temp_index] < $arr2[$i]) {
$allow_update = 0;
$error_message .= '"'.$arr2[$i].'" items are not available for "'.$arr3[$i].'"\n';
} else {
$_SESSION['cart_p_qty'][$i] = $arr2[$i];
}
}
$error_message .= '\nOther items quantity are updated successfully!';
?>
<?php if($allow_update == 0): ?>
<script>alert('<?php echo $error_message; ?>');</script>
<?php else: ?>
<script>alert('All Items Quantity Update is Successful!');</script>
<?php endif; ?>
<?php
}
?>
<div class="page-banner" style="background-image: url(assets/uploads/<?php echo $banner_cart; ?>)">
<div class="overlay"></div>
<div class="page-banner-inner">
<h1><?php echo LANG_VALUE_18; ?></h1>
</div>
</div>
<div class="page">
<div class="container">
<div class="row">
<div class="col-md-12">
<?php if(!isset($_SESSION['cart_p_id'])): ?>
<?php echo 'Cart is empty'; ?>
<?php else: ?>
<form action="" method="post">
<?php $csrf->echoInputField(); ?>
<div class="cart">
<table class="table table-responsive">
<tr>
<th><?php echo LANG_VALUE_7; ?></th>
<th><?php echo LANG_VALUE_8; ?></th>
<th><?php echo LANG_VALUE_47; ?></th>
<th><?php echo LANG_VALUE_157; ?></th>
<th><?php echo LANG_VALUE_158; ?></th>
<th><?php echo LANG_VALUE_159; ?></th>
<th><?php echo LANG_VALUE_55; ?></th>
<th class="text-right"><?php echo LANG_VALUE_82; ?></th>
<th class="text-center" style="width: 100px;"><?php echo LANG_VALUE_83; ?></th>
</tr>
<?php
$table_total_price = 0;
$i=0;
foreach($_SESSION['cart_p_id'] as $key => $value)
{
$i++;
$arr_cart_p_id[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_size_id'] as $key => $value)
{
$i++;
$arr_cart_size_id[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_size_name'] as $key => $value)
{
$i++;
$arr_cart_size_name[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_color_id'] as $key => $value)
{
$i++;
$arr_cart_color_id[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_color_name'] as $key => $value)
{
$i++;
$arr_cart_color_name[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_p_qty'] as $key => $value)
{
$i++;
$arr_cart_p_qty[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_p_current_price'] as $key => $value)
{
$i++;
$arr_cart_p_current_price[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_p_name'] as $key => $value)
{
$i++;
$arr_cart_p_name[$i] = $value;
}
$i=0;
foreach($_SESSION['cart_p_featured_photo'] as $key => $value)
{
$i++;
$arr_cart_p_featured_photo[$i] = $value;
}
?>
<?php for($i=1;$i<=count($arr_cart_p_id);$i++): ?>
<tr>
<td><?php echo $i; ?></td>
<td>
<img src="assets/uploads/<?php echo $arr_cart_p_featured_photo[$i]; ?>" alt="">
</td>
<td><?php echo $arr_cart_p_name[$i]; ?></td>
<td><?php echo $arr_cart_size_name[$i]; ?></td>
<td><?php echo $arr_cart_color_name[$i]; ?></td>
<td><?php echo LANG_VALUE_1; ?><?php echo $arr_cart_p_current_price[$i]; ?></td>
<td>
<input type="hidden" name="product_id[]" value="<?php echo $arr_cart_p_id[$i]; ?>">
<input type="hidden" name="product_name[]" value="<?php echo $arr_cart_p_name[$i]; ?>">
<input type="number" class="input-text qty text" step="1" min="1" max="" name="quantity[]" value="<?php echo $arr_cart_p_qty[$i]; ?>" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric">
</td>
<td class="text-right">
<?php
$row_total_price = $arr_cart_p_current_price[$i]*$arr_cart_p_qty[$i];
$table_total_price = $table_total_price + $row_total_price;
?>
<?php echo LANG_VALUE_1; ?><?php echo $row_total_price; ?>
</td>
<td class="text-center">
<a onclick="return confirmDelete();" href="cart-item-delete.php?id=<?php echo $arr_cart_p_id[$i]; ?>&size=<?php echo $arr_cart_size_id[$i]; ?>&color=<?php echo $arr_cart_color_id[$i]; ?>" class="trash"><i class="fa fa-trash"></i></a>
</td>
</tr>
<?php endfor; ?>
<tr>
<th colspan="7" class="total-text">Total</th>
<th class="total-amount"><?php echo LANG_VALUE_1; ?><?php echo $table_total_price; ?></th>
<th></th>
</tr>
</table>
</div>
<div class="cart-buttons">
<ul>
<li><input type="submit" value="<?php echo LANG_VALUE_20; ?>" class="btn btn-primary" name="form1"></li>
<li><a href="index.php" class="btn btn-primary"><?php echo LANG_VALUE_85; ?></a></li>
<li><a href="checkout.php" class="btn btn-primary"><?php echo LANG_VALUE_23; ?></a></li>
</ul>
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>