-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwishlist.php
149 lines (118 loc) · 5.38 KB
/
wishlist.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
<?php
include 'components/connection.php';
session_start();
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
} else {
$user_id = '';
}
if (isset($_POST['layout'])) {
session_destroy();
header("location:login.php");
}
// adding products in cart
if (isset($_POST['add_to_cart'])) {
$id = unique_id();
$product_id = $_POST['product_id'];
$qty = 1;
$qty = filter_var($qty, FILTER_SANITIZE_STRING);
$varify_cart = $conn->prepare("SELECT * FROM `cart` WHERE user_id = ? AND product_id =? ");
$varify_cart->execute([$user_id, $product_id]);
$max_cart_items = $conn->prepare("SELECT * FROM `cart`WHERE user_id = ?");
$max_cart_items->execute([$user_id]);
if ($varify_wishlist->rowCount() > 0) {
$warning_msg[] = 'product already exist in your wishlist';
} else if ($max_cart_items->rowCount() > 20) {
$warning_msg[] = 'cart is full!';
} else {
$select_price = $conn->prepare("SELECT * FROM `products` WHERE id=? LIMIT 1");
$select_price->execute([$product_id]);
$fetch_price = $select_price->fetch(PDO::FETCH_ASSOC);
$insert_cart = $conn->prepare("INSERT INTO `cart` (id, user_id, product_id,price,qty) VALUES(?,?,?,?,?)");
$insert_cart->execute([$id, $user_id, $product_id, $fetch_price['price'], $qty]);
$success_msg[] = 'product added to cart successfully';
}
}
// delete item from wishlist
if (isset($_POST['delete_item'])) {
$wishlist_id = $_POST['wishlist_id'];
$wishlist_id = filter_var($wishlist_id, FILTER_SANITIZE_STRING);
$varify_delete_items = $conn->prepare("SELECT * FROM `wishlist` WHERE if=?");
$varify_delete_items->execute([$wishlist_id]);
if ($varify_delete_items->rowCount() > 0) {
$delete_wishlist_id = $conn->prepare("DELETE FROM `wishlist` WHERE id=?");
$delete_wishlist_id->execute([$wishlist_id]);
$success_msg[] = 'item deleted from wishlist successfully';
} else {
$warning_msg[] = 'wishlist item already deleted';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<link rel="stylesheet" href="style.css">
<title>MyWebsite - wishlist </title>
</head>
<body>
<?php include './components/header.php'; ?>
<div class="main">
<div class="banner">
<h1>my wishlist</h1>
</div>
<div class="title2">
<a href="home.php">home</a><span>/ wishlist</span>
</div>
<section class="products">
<h1 class="title">products add in wishlist</h1>
<div class="box-container">
<?php
$grand_total = 0;
$select_wishlist = $conn->prepare("SELECT * FROM `wishlist` WHERE `user_id` =?");
$select_wishlist->execute([$user_id]);
if ($select_wishlist->rowCount() > 0) {
while ($fetch_wishlist = $select_wishlist->fetch(PDO::FETCH_ASSOC)) {
echo $user_id;
$select_products = $conn->prepare("SELECT * FROM `products` WHERE id=? ");
$select_products->execute([$fetch_wishlist['product_id']]);
if ($select_products->rowCount() > 0) {
$ftch_products = $select_products->fetch(PDO::FETCH_ASSOC);
?>
<form action="" method="post" class="box">
<input type="hidden" name="wishlist_id" value="<?= $fetch_wishlist['id'] ?>">
<img src="image/<?= $ftch_products['image']; ?>" alt="">
<div class="button">
<button type="submit" name="add_to_cart"><i class="bx bx-cart"></i> </button>
<a href="view_page.php?pid=<?php echo $ftch_products['id']; ?>" class="bx bxs-show"></a>
<button type="submit" name="delete_item" onclick="return confirm('delete this item')"><i class="bx bx-x"></i> </button>
</div>
<h3 class="name">
<?= $ftch_products['name'] ?>
</h3>
<input type="hidden" name="product_id" value="<?= $ftch_products['id']; ?>">
<div class="flex">
<p class="price">price $<?= $ftch_products['price'] ?> /-</p>
</div>
<a href="checkout.php?get_id=<?= $ftch_products['id']; ?>" class="btn">buy now</a>
</form>
<?php
$grand_total += $fetch_wishlist['price'];
}
}
} else {
echo '
<p class="empty">no products added yet!</p>';
}
?>
</div>
</section>
<?php include 'components/footer.php'; ?>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script src="script.js"></script>
<?php include './components/alert.php'; ?>
</body>
</html>