-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwishlist.php
More file actions
265 lines (219 loc) · 11.6 KB
/
wishlist.php
File metadata and controls
265 lines (219 loc) · 11.6 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
include("config/session.php");
$conn = $pdo->open();
if(!isset($_SESSION['user'])) {
$_SESSION['error'] = "Sorry, you have to login to view wishlist";
header('location: index.php');
}
$user_id = $_SESSION['user']['user_id'];
$stmt = $conn->prepare("SELECT * FROM wishlist LEFT JOIN products ON products.prd_id = wishlist.prd_id WHERE user_id= :user_id");
$stmt->execute([':user_id' => $user_id]);
$wishlist = $stmt->fetchAll();
include('config/fetch.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Favicons -->
<link rel="icon" href="images/favicon-32x32.png" sizes="32x32">
<link rel="icon" href="images/favicon-192x192.png" sizes="192x192">
<link rel="apple-touch-icon" href="images/favicon-180x180.png">
<!-- HEADER & FOOTER CSS -->
<link rel="stylesheet" href="styles/header-and-footer.css?v=<?php echo time(); ?>"/>
<!-- PAGE CSS -->
<link rel="stylesheet" href="styles/wishlist.css?v=<?php echo time(); ?>"/>
<!-- FONT AWESOME ICONS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<title>Wishlist - Doppell</title>
</head>
<body>
<?php include('includes/header.php'); ?>
<main>
<div id="callout" class="container">
<p class="callout-box">
<span class="callout-icon"></span>
<span class="callout-message first"></span>
</p>
</div>
<section class="title">
<div class="inner-col container">
<h1>wishlist</h1>
</div>
</section>
<section class="wishlist-main">
<div class="container">
<form action="">
<div class="wishlist-title">
<h2>My wishlist</h2>
</div>
<?php if(count($wishlist) > 0): ?>
<table class="hide-on-mobile">
<thead>
<tr>
<th class="product-name" colspan="3">Product Name</th>
<th class="product-price">Unit Price</th>
<th class="product-stock">Stock Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($wishlist as $product): ?>
<tr class="hoc">
<td class="product-remove">
<a href="" class="wishlist-delete" data-id="<?php echo $product['wishlist_id']; ?>">×</a>
</td>
<td class="product-thumbnail">
<a href="product-details.php?prname=<?php echo $product['prd_slug']; ?>"><img src="images/<?php echo $product['prd_image']; ?>"></a>
</td>
<td class="product-name">
<a href="product-details.php?prname=<?php echo $product['prd_slug']; ?>"><?php echo $product['prd_name']; ?></a>
</td>
<td class="product-price">
<span><?php echo '₦' . number_format($product['prd_price'], 2); ?></span>
</td>
<td class="product-stock">
<span>In stock</span>
</td>
<td class="add-to-cart">
<form>
<button type="submit" class="cart-add">add to cart</button>
<input type="hidden" id="product_id" name="product_id" value="<?php echo $product['prd_id']; ?>">
<input type="hidden" id="product_name" name="product_name" value="<?php echo $product['prd_name']; ?>">
</form>
</td>
<td class='loading-overlay d-none'>
<i class='fas fa-spinner fa-spin'></i>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="mobile-wishlist">
<?php foreach($wishlist as $product): ?>
<div class="product hoc">
<div class="product-thumbnail">
<a href="product-details.php?prname=<?php echo $product['prd_slug']; ?>"><img src="images/<?php echo $product['prd_image']; ?>"></a>
</div>
<div class="product-info">
<div class="product-name-box">
<div class="product-name">
<a href="product-details.php?prname=<?php echo $product['prd_slug']; ?>"><?php echo $product['prd_name']; ?></a>
</div>
</div>
<div class="product-price-box">
<div class="product-price-text">
<p>Price:</p>
</div>
<div class="product-price">
<span><?php echo '₦' . number_format($product['prd_price'], 2); ?></span>
</div>
</div>
<div class="product-stock-box">
<div class="product-stock-text">
<p>Stock:</p>
</div>
<div class="product-price">
<span>In stock</span>
</div>
</div>
<div class="add-to-cart-box">
<div class="add-to-cart">
<form>
<button type="submit" class="cart-add">add to cart</button>
<input type="hidden" id="product_id" name="product_id" value="<?php echo $product['prd_id']; ?>">
<input type="hidden" id="product_name" name="product_name" value="<?php echo $product['prd_name']; ?>">
</form>
</div>
<div class="product-remove">
<button class="wishlist-delete" data-id="<?php echo $product['wishlist_id']; ?>">remove</button>
</div>
</div>
</div>
<div class='loading-overlay d-none'>
<i class='fas fa-spinner fa-spin'></i>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="no-wishlist">
<p>You have no items in wishlist</p>
</div>
<?php endif; ?>
</form>
<div class="social-icons">
<a href="" class="whatsapp"><div><i class="fab fa-whatsapp"></i></div></a>
<a href="" class="facebook"><div><i class="fab fa-facebook-f"></i></div></a>
<a href="" class="twitter"><div><i class="fab fa-twitter"></i></div></a>
<a href="" class="pinterest"><div><i class="fab fa-pinterest"></i></div></a>
</div>
</div>
</section>
</main>
<?php include('includes/footer.php'); ?>
<script>
$(function(){
$(document).on('click', '.wishlist-delete', function(e){
e.preventDefault();
let overlay = $(this).parents('.hoc').find('.loading-overlay');
overlay.removeClass('d-none');
let id = $(this).data('id');
$.ajax({
type: 'POST',
url: 'wishlist_delete.php',
data: {
id : id
},
dataType: 'json',
success: function(response){
if(!response.error){
document.location.reload(true);
}
overlay.removeClass('d-none');
}
});
});
});
$(function(){
$(document).on('click', '.cart-add', function(e){
e.preventDefault();
let button = $(this).parent().find('button');
button.html('<i class="fas fa-spinner fa-spin"></i>');
let product_id = $(this).parent().find("#product_id").val();
let product_name = $(this).parent().find("#product_name").val();
let quantity = 1;
$.ajax({
type: 'POST',
url: 'cart_add.php',
data: {
"product_id": product_id,
"product_name": product_name,
"quantity": quantity
},
success: function(response){
response = JSON.parse(response);
button.html('ADD TO CART');
$('#callout').show();
$('.callout-message.first').html(response.message);
if(response.error){
$('#callout').removeClass('callout-success').addClass('callout-danger');
$('.callout-icon').html('<i class="fas fa-x"></i>');
}
else{
$('#callout').removeClass('callout-danger').addClass('callout-success');
$('.callout-icon').html('<i class="fas fa-check"></i>');
getCart();
getTotal();
}
$("#product-main").css("padding", "0");
goToTop();
}
});
});
});
</script>
</body>
</html>