-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_address_form.php
More file actions
205 lines (184 loc) · 8.92 KB
/
user_address_form.php
File metadata and controls
205 lines (184 loc) · 8.92 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
<?php
include("header.php");
if (!isset($_SESSION['username'])) {
echo "<script>
alert('Please Login First');
window.location.href='login.php';
</script>";
exit();
}
$user_id = $_SESSION['id'];
$call = showCart($user_id);
$savedAddresses = [];
$totalQuantity = 0;
$grandTotal = 0;
// Fetch saved addresses for the user along with name and mobile number from the registration table
$query = "SELECT ua.*, r.first_name, r.last_name, r.mobile_no AS user_mobile FROM user_address ua INNER JOIN registration r ON ua.user_id = r.id WHERE ua.user_id = '$user_id'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$savedAddresses[] = $row;
}
} else {
echo "<script>
window.location.href = 'add_new_address.php?uid=$user_id';
</script>";
exit();
}
// Query to fetch cart details
$cartQuery = "SELECT c.p_id, SUM(c.quantity) AS total_quantity, p.price FROM cart c INNER JOIN product p ON c.p_id = p.p_id WHERE c.u_id = '$user_id' GROUP BY c.p_id";
$cartResult = mysqli_query($conn, $cartQuery);
// if (mysqli_num_rows($cartResult) > 0) {
// while ($cartRow = mysqli_fetch_assoc($cartResult)) {
// $totalQuantity += $cartRow['total_quantity']; // Use the total quantity for each product
// $grandTotal += $cartRow['total_quantity'] * $cartRow['price']; // Calculate the total price
// }
// }
// Check if product details are passed in the URL for a single product purchase
if (isset($_REQUEST['product_id']) && isset($_REQUEST['quantity']) && isset($_REQUEST['price'])) {
$productIds = $_REQUEST['product_id'];
$quantities = $_REQUEST['quantity'];
$price = $_REQUEST['price']; // Ensure this is set before use
} else {
// If not set, default the price to 0 or calculate it based on cart
$productIds = [];
$quantities = [];
$price = 0;
// If cart is used, calculate the price based on cart data
$cartData = mysqli_query($conn, "SELECT cart.p_id, cart.quantity, product.price FROM cart join product on cart.p_id=product.p_id WHERE u_id = '$user_id'");
while ($row = mysqli_fetch_assoc($cartData)) {
$productIds[] = $row['p_id'];
$quantities[] = $row['quantity'];
$price += $row['quantity'] * $row['price']; // Summing up price for all cart items
}
}
?>
<style>
/* Your CSS code remains the same */
.custom-radio {
position: absolute;
opacity: 0;
cursor: pointer;
}
.custom-radio+.form-check-label {
position: relative;
display: inline-block;
padding-left: 60px;
cursor: pointer;
font-size: 16px;
line-height: 20px;
}
.custom-radio+.form-check-label::before {
content: '';
position: absolute;
top: 20px;
left: 0;
width: 40px;
height: 20px;
background-color: #ccc;
border-radius: 50px;
transition: background-color 0.3s, transform 0.3s;
}
.custom-radio+.form-check-label::after {
content: '';
position: absolute;
top: 22.5px;
left: 2px;
width: 15px;
height: 15px;
background-color: white;
border-radius: 50%;
transition: transform 0.3s;
}
.custom-radio:checked+.form-check-label::before {
background-color: #007bff;
}
.custom-radio:checked+.form-check-label::after {
transform: translateX(20px);
}
.categorybtn {
width: 155px;
background-color: #0171a4;
color: white;
padding: 10px;
outline: none;
border: none;
font-weight: 600;
border-radius: 4px;
}
.categorybtn:hover {
background-color: #039de4;
color: white;
}
</style>
<div class="right_side">
<div class="container-fluid">
<form action="payment_method.php" method="post" id="orderForm1">
<input type="hidden" name="product_id" value="<?php echo is_array($productIds)?implode(",", $productIds):$productIds; ?>" />
<input type="hidden" name="quantity" value="<?php echo is_array($quantities)?implode(",", $quantities):$quantities; ?>" />
<input type="hidden" name="price" value="<?php echo $price; ?>" />
<div class="row d-flex w-75" id="box">
<div class="col-md-12 d-flex">
<div class="col-md-8">
<div class="col-md-12" style="background-color: #f1f6ff; padding: 50px 30px 30px 30px;">
<?php if (empty($savedAddresses)) { ?>
<script>
window.location.href = "add_new_address.php?uid=<?php echo $_GET['uid']; ?>";
</script>
<?php } else { ?>
<h3 class="text-center login-heading mb-4" style="font-size: 30px;">Select Shipping Address</h3>
<div class="col-md-12" style="display: flex; justify-content: end;">
<a href="add_new_address.php?uid=<?php echo $user_id; ?>" style="margin-right: 40px;">
<button type="button" class="btn btn-sm categorybtn">
<span><i class="fa-solid fa-plus" style="color: #ffffff;"></i></span>Add New Address
</button>
</a>
</div>
<?php foreach ($savedAddresses as $address) { ?>
<div class="form-check form-switch" style="border: 1px solid #cedefa; padding: 30px 45px; background-color: #cedefa; border-radius: 12px; margin: 10px 37px; position: relative;">
<div class="col-md-12 d-flex">
<div class="col-md-10">
<input class="form-check-input custom-radio" type="radio" name="selected_address" value="<?php echo $address['address_id']; ?>" id="address<?php echo $address['address_id']; ?>" required>
<label class="form-check-label" for="address<?php echo $address['address_id']; ?>">
<?php
echo $address['first_name'] . " " . $address['last_name'] . "<br>" .
$address['address'] . "<br>" .
"Pin Code: " . $address['pin_code'] . "<br>" .
"Mobile: " . $address['mobile_no'];
?>
</label>
</div>
<div class="col-md-2" style="display: flex;justify-content: center;align-items: center;">
<a href="delete_address.php?address_id=<?php echo $address['address_id']; ?>&uid=<?php echo $user_id; ?>"><i class="fa-solid fa-lg fa-trash" style="color: #e80000;"></i></a>
</div>
</div>
</div>
<?php } ?>
<?php } ?>
</div>
</div>
<div class="col-md-4" style="display: flex;justify-content: center;align-items: center;margin-left: 40px;">
<div class="grandtotal_box col-md-12" style="margin: 0;">
<div class="col-md-12 summary_track">
<h6 class="p-0 m-0 summary">Price details</h6>
</div>
<div class="col-md-12 grandTotal_tray">
<h6>Number Of Products: <span id="totalQuantity"><?php echo is_array($quantities) ? array_sum($quantities) : $quantities; ?></span></h6>
<h6>Shipping: <span class="text-success">FREE</span></h6>
</div>
<div class="main_grand_total">
<h5 class="text-center">Grand Total: ₹ <span class="actual_price" id="grandTotal"><?php echo number_format($price, 2); ?></span></h5>
</div>
<div class="col-md-12 d-flex justify-content-center pt-2 pb-2">
<button class="btn btn-sm checkoutbtn" type="submit">
Proceed to Payment
</button>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<?php include("footer.php"); ?>