forked from 14Muhammad/eco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
170 lines (167 loc) · 8.06 KB
/
cart.php
File metadata and controls
170 lines (167 loc) · 8.06 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
<!DOCTYPE html>
<?php
session_start();
require "functions/functions.php";
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Online Shop</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
</head>
<body>
<div class="main_wrapper">
<div class="header_wrapper">
<a href="index.php"><img id="logo" src="images/logo.jpg"></a>
<img id="banner" src="images/banner.gif">
</div>
<div class="menubar">
<ul id="menu">
<li><a href="index.php">Home</a></li>
<li><a href="all_products.php">All Products</a></li>
<li><a href="my_account.php">My Account</a></li>
<li><a href="#">Sign Up</a></li>
<li><a href="cart.php">Cart</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
<div id="form">
<form method="get" action="results.php">
<input type="text" name="user_query" placeholder="Search products">
<input type="submit" name="search" value="Search">
</form>
</div>
</div>
<div class="content_wrapper">
<div id="sidebar">
<div class="sidebar_title">Categories </div>
<ul class="cats">
<?php getCats(); ?>
</ul>
<div class="sidebar_title">Brands </div>
<ul class="cats">
<?php getBrands(); ?>
</ul>
</div>
<div id="content_area">
<?php
global $con;
$ip = getIp();
if(isset($_POST['update_cart'])){
/*Way 1 to do */
//foreach (array_combine($_POST['product_id'], $_POST['qty']) as $pro_id => $qty) {
/*Way 2 to do */
for($i =0; $i< sizeof($_POST['product_id']); $i++){
$pro_id = $_POST['product_id'][$i];
$qty = $_POST['qty'][$i];
if($qty > 0) {
$update_qty = "update cart set qty='$qty' where p_id='$pro_id' AND ip_add='$ip'";
$run_qty = mysqli_query($con, $update_qty);
}
}
if(isset($_POST['remove'])) {
foreach ($_POST['remove'] as $remove_id) {
$del_pro = "delete from cart where p_id='$remove_id' AND ip_add='$ip'";
$run_del = mysqli_query($con, $del_pro);
}
}
header('location: '.$_SERVER['PHP_SELF']);
}
if(isset($_POST['continue'])){
header('location: index.php');
}
?>
<div class="shopping_cart">
<?php cart(); ?>
<span style="float: right;
font-size: 18px; padding: 5px;line-height: 40px;">
<?php
if(!isset($_SESSION['customer_email']))
echo "Welcome guest!";
else
echo "Welcome ".$_SESSION['customer_email'];
?>
<b style="color: yellow">
Shopping Cart - </b>
Total Items: <?php total_items(); ?>
Total Price: <?php total_price(); ?>
<a style="color: yellow" href="index.php">Back to Shop</a>
<?php
if(!isset($_SESSION['customer_email'])){
echo "<a style='color: orange;' href='checkout.php'>Login</a>";
}
else{
echo "<a style='color: orange;' href='logout.php'>Logout</a>";
}
?>
</span>
</div>
<div class="products_box">
<br>
<form action="" method="post" enctype="multipart/form-data">
<table align="center" width="700px" bgcolor="#87ceeb">
<tr align="center">
<th> Remove </th>
<th> Product(s) </th>
<th> Quantity </th>
<th> Unit Price </th>
<th> Items Total </th>
</tr>
<?php
$ip = getIp();
$total = 0;
$sel_price = "select * from cart where ip_add = '$ip'";
$run_price = mysqli_query($con,$sel_price);
while($cart_row = mysqli_fetch_array($run_price)){
$pro_id = $cart_row['p_id'];
$pro_qty = $cart_row['qty'];
$pro_price = "select * from products where pro_id = '$pro_id'";
$run_pro_price = mysqli_query($con, $pro_price);
while ($pro_row = mysqli_fetch_array($run_pro_price)){
$pro_title = $pro_row['pro_title'];
$pro_image = $pro_row['pro_image'];
$pro_price = $pro_row['pro_price'];
$pro_price_all_items = $pro_price * $pro_qty;
$total += $pro_price_all_items;
?>
<tr align="center">
<td><input type="checkbox" name="remove[]"
value="<?php echo $pro_id; ?>"></td>
<td><?php echo $pro_title; ?> <br>
<img src="admin/product_images/<?php echo $pro_image; ?>"
width="60" height="60">
</td>
<td><input size="2" name="qty[]" value="<?php echo $pro_qty;?>">
<input name="product_id[]" type="hidden" value="<?php echo $pro_id;?>">
</td>
<td><?php echo "Rs " . $pro_price . "/-"; ?></td>
<td><?php echo "Rs " . $pro_price_all_items . "/-"; ?></td>
</tr>
<?php
}
}
?>
<tr align="right">
<td colspan="4"><b>Sub Total:</b></td>
<td><?php echo "Rs ".$total."/-"; ?></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="update_cart" value="Update Cart"></td>
<td><input type="submit" name="continue" value="Continue Shopping"></td>
<td><button>
<a style="text-decoration: none;
color: black;" href="checkout.php">
Checkout</a>
</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div id="footer">
<h2> © 2018 by Muhammad Ali Makhdoom</h2>
</div>
</div>
</body>
</html>