This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
executable file
·175 lines (152 loc) · 7.69 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
<?php
include('boilerplate.php');
?>
<?php if ($total != 0) {
$total = 0;
$itemqty = 0;
echo '<section class="borderless-table carousel-info">
<div class="container">
<div class="row">
<div class="col-lg-12">';
?>
<?php if (isset($_SESSION['alertMsg'])) : ?>
<div class="col-md-6 mx-auto text-center">
<div class="alert alert-success">
<?php echo $_SESSION['alertMsg']; ?>
</div>
</div>
<?php endif; ?>
<?php unset($_SESSION['alertMsg']); ?>
<?php echo '
<div class="cart-table">
<table>
<thead>
<tr>
<th>Product</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th></th>
</tr>
</thead>
<tbody>';
foreach ($_SESSION['cart'] as $variant_id => $quantity) {
$find_pro_id = mysqli_query($connect, "SELECT * FROM variant WHERE variant_id='$variant_id'");
$pro_data = mysqli_fetch_assoc($find_pro_id);
$product_id = $pro_data['product_id'];
$result = "SELECT name,code, qty, MRP, cost, file FROM product WHERE id = $product_id";
$run = mysqli_query($connect, $result);
if ($run) {
while ($obj = mysqli_fetch_object($run)) {
$code = $obj->code;
$price = $obj->cost * $quantity;
$total = $total + $price;
$itemqty = $itemqty + $quantity;
$color = $pro_data['color'];
$size = $pro_data['size'];
$result_c = mysqli_query($connect, "SELECT * FROM attribute where attr_id='$color'");
$row_c = mysqli_fetch_assoc($result_c);
$attr = $row_c['attr_id'];
$value_c = $row_c['value'];
$result_s = mysqli_query($connect, "SELECT * FROM attribute where attr_id='$size'");
$row_s = mysqli_fetch_assoc($result_s);
$attr = $row_s['attr_id'];
$value_s = $row_s['value'];
echo '<tr>
<td class="cart-pic first-row"><a href="product.php?id=' . $product_id . '" ><img width="150" height="150" src="uploads/' . $obj->file . '" alt="product image"></a></td>
<td class="cart-title first-row">
<p><span style="font-size:1.1em;" class="badge badge-light">' . $obj->name . '</span></p>';
if ($value_c == 'white') {
echo'<span class="badge" style="color:black; background-color:' .$value_c .';">' . $value_s .'</span>';
} else {
echo'<span class="badge" style="color:white; background-color:' .$value_c .';">' . $value_s .'</span>';
}
echo'</td>
<td class="total-price first-row">₹ ' . $obj->cost . '
<strong style="text-decoration: line-through; color:grey; font-size:.8em;">
₹ ' . $obj->MRP . '</strong></td>
<td class="qua-col">
<div class="quantity">
<div class="pro-qty">
<a class="dec qtybtn" href="updateCart.php?action=remove&id=' . $variant_id . '">-</a>
<input type="text" value="' . $quantity . '">
<a class="inc qtybtn" href="updateCart.php?action=add&id=' . $variant_id . '">+</a>
</div>
</div>
</td>';
$selling_price = $obj->cost * $quantity;
$savings = ($obj->MRP - $obj->cost) * $quantity;
$selling_MRP = $obj->MRP * $quantity;
echo '<td class="total-price first-row">₹ ' . $selling_price . '
<strong style="text-decoration: line-through; color:grey; font-size:.8em;"> ₹ ' . $selling_MRP . '</strong></td>
<td class="close-td first-row"><a style="color:grey" href="updateCart.php?action=del&id=' . $variant_id . '"<i class="far fa-trash-alt"></i></a></td>';
}
}
}
echo '
</tr>
</tbody>
</table>
</div>
<div class="row">
<div class="cart-buttons">
<a href="shop.php" class="primary-btn continue-shop">Continue shopping</a>
<a href="delCart.php" class="primary-btn up-cart">Empty cart</a>
</div>';
if (isset($_SESSION['cart'])) {
$total = 0;
$itemqty = 0;
$saving = 0;
$MRP = 0;
foreach ($_SESSION['cart'] as $variant_id => $quantity) {
$find_pro_id = mysqli_query($connect, "SELECT * FROM variant WHERE variant_id='$variant_id'");
$pro_data = mysqli_fetch_assoc($find_pro_id);
$product_id = $pro_data['product_id'];
$result = "SELECT name, qty, MRP, cost,file FROM product WHERE id = $product_id";
$run = mysqli_query($connect, $result);
if ($run) {
while ($obj = mysqli_fetch_object($run)) {
$price = $obj->cost * $quantity;
$MRP += $obj->MRP * $quantity;
$total += $price;
$itemqty += $quantity;
$saving = $MRP - $total;
}
}
}
echo '<div class="col-lg-4 offset-lg-4">
<div class="proceed-checkout">
<ul>
<li class="subtotal">Quantity <span>' . $itemqty . '</span></li>
<li class="subtotal">Cost<span>₹ ' . $MRP . '</span></li>
<li class="subtotal">Savings <span>₹ ' . $saving . '</span></li>
<li class="cart-total">Total <span>₹ ' . $total . '</span></li>
</ul>
<a href="checkout.php" class="proceed-btn">CHECK OUT</a>
</div>
</div>';
}
} else {
unset($_SESSION['alertMsg']);
echo '
<div class="container">
<div class="row my-5">
<div class="col-md-12 text-center">
<span class="icon-exclamation-triangle display-1 text-danger"></span>
<h2 class="display-3 text-black">Your cart is empty !</h2>
<p class="display-5 mb-5">You can check our bestseller section</p>
<p><a href="index.php" class="btn btn-sm btn-info">Continue Shopping</a></p>
</div>
</div>
</div>';
}
?>
</div>
</div>
</div>
</div>
</section>
<?php include('footer.php'); ?>
</body>
</html>