Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified checkout/checkout.css
100644 → 100755
Empty file.
Empty file modified checkout/checkout.js
100644 → 100755
Empty file.
Empty file modified checkout/checkout.php
100644 → 100755
Empty file.
Empty file modified checkout/order-confirmation.css
100644 → 100755
Empty file.
Empty file modified checkout/order-confirmation.php
100644 → 100755
Empty file.
Empty file modified checkout/process-order.php
100644 → 100755
Empty file.
Empty file modified checkout/verify-coupon.php
100644 → 100755
Empty file.
Empty file modified dashboard/assets/img/superadmin.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cb6a8787658watch.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbe19cb23c8ES1G527M0045.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbe1a33deb2ES1G527M0045.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbe1aa500f7ES1G527M0045.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbe1b14116dES1G527M0045.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbfe6755747D1-ATBU06-1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbfe79b85dcD1-ATBU05-1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cbfe985df25D1-ARBU02-1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified dashboard/assets/productImages/67cc02d2e82bcVEZCA02241.png
100644 → 100755
Empty file modified dashboard/assets/productImages/placeholder.jpg
100644 → 100755
Empty file modified dashboard/controllers/AuthController.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/courier.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/courierb.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/courierbi.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/courieri.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/helvetica.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/helveticab.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/helveticabi.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/helveticai.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/symbol.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/times.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/timesb.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/timesbi.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/timesi.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/font/zapfdingbats.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/fpdf.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/order_details_report.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/order_report.php
100644 → 100755
Empty file.
Empty file modified dashboard/services/orderReport/order_report_csv.php
100644 → 100755
Empty file.
Empty file modified dashboard/views/admin/settings.php
100644 → 100755
Empty file.
Empty file modified dashboard/views/layouts/components/logoheader.php
100644 → 100755
Empty file.
Empty file modified dashboard/views/layouts/components/logout.php
100644 → 100755
Empty file.
Empty file modified dashboard/views/layouts/components/navbar.php
100644 → 100755
Empty file.
Empty file modified dashboard/views/layouts/components/sidebar.php
100644 → 100755
Empty file.
Empty file modified public/assets/css/category.css
100644 → 100755
Empty file.
Empty file modified public/assets/images/back3.webp
100644 → 100755
Empty file.
Empty file modified public/assets/js/category.js
100644 → 100755
Empty file.
Empty file modified public/assets/js/product.js
100644 → 100755
Empty file.
Empty file modified public/config/cart_con.php
100644 → 100755
Empty file.
Empty file modified public/controllers/cart.php
100644 → 100755
Empty file.
Empty file modified public/models/Home.php
100644 → 100755
Empty file.
Empty file modified public/views/category.php
100644 → 100755
Empty file.
Empty file modified public/views/components/featured.php
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions public/views/components/navbar.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -29,6 +29,11 @@
>Contact Us</a
>
</li>
<li>
<a href="http://localhost/watch_store/public/views/wishlist/">
wishlist
</a>
</li>
</div>

<div class="right-items">
Empty file modified public/views/components/newArrival.php
100644 → 100755
Empty file.
Empty file modified public/views/logout.php
100644 → 100755
Empty file.
Empty file modified public/views/profile_page/pro_edit.php
100644 → 100755
Empty file.
5 changes: 2 additions & 3 deletions public/views/profile_page/profile.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -58,9 +58,8 @@
</div>
<div class="user_name"><h1><?php echo htmlspecialchars($user['name']); ?></h1></div>
<div>
<div class="edit_btn"><a href="./pro_edit.php" style="text-decoration: none; color: white;">Edit Profile</a></div>
<div class="edit_btn"><a href="/watch_store/public" style="text-decoration: none; color: white;">Home page</a></div>
<div class="edit_btn"><a href="../logout.php" style="text-decoration: none; color: white;"> logout </a></div>
<div class="edit_btn"><a href="./pro_edit.php" style="text-decoration: none; color: white;">Edit Profile <i class="fa-solid fa-pen-to-square " style="margin-left: .5rem;"></i></a></div>
<div class="edit_btn logg"><a href="../logout.php" style="text-decoration: none; color: white;">LogOut <i class="fa-solid fa-arrow-right-from-bracket" style="margin-left: .5rem;"></i> </a></div>
</div>
</div>
<div class="content-container">
Empty file modified public/views/profile_page/style_cloud.css
100644 → 100755
Empty file.
Empty file modified public/views/search.php
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions public/views/wishlist/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "watch_store";

$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
33 changes: 33 additions & 0 deletions public/views/wishlist/controllers/WishlistController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
include './models/Wishlist.php';

class WishlistController {

private $wishlistModel;

public function __construct($conn) {
$this->wishlistModel = new Wishlist($conn);
}

public function addProductToWishlist($user_id, $product_id) {
if ($this->wishlistModel->addToWishlist($user_id, $product_id)) {
return true;
} else {
return false;
}
}

public function showWishlist($user_id) {
$wishlistItems = $this->wishlistModel->getWishlist($user_id);
return $wishlistItems;
}

public function removeFromWishlist($user_id, $product_id) {
if ($this->wishlistModel->removeFromWishlist($user_id, $product_id)) {
return true;
} else {
return false;
}
}
}
?>
54 changes: 54 additions & 0 deletions public/views/wishlist/controllers/add_selected_to_cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
session_start();
include './config.php';

// For debugging
error_log("add_selected_to_cart.php accessed");
error_log("POST data: " . print_r($_POST, true));

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['select']) && is_array($_POST['select'])) {
$user_id = $_SESSION['user_id'] ?? 0;

if ($user_id === 0) {
$_SESSION['message'] = "Please log in to add items to your cart.";
header("Location: login.php");
exit();
}

$products = $_POST['select'];
$success = 0;

error_log("Adding " . count($products) . " selected products to cart for user ID: $user_id");

foreach ($products as $product_id) {
// Sanitize the input
$product_id = (int)$product_id;

// Add to cart query
$query = "INSERT INTO cart_items (user_id, product_id, quantity) VALUES (?, ?, 1)
ON DUPLICATE KEY UPDATE quantity = quantity + 1";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $user_id, $product_id);

if ($stmt->execute()) {
$success++;
error_log("Successfully added product ID: $product_id to cart");
} else {
error_log("Failed to add product ID: $product_id to cart: " . $conn->error);
}
}

if ($success > 0) {
$_SESSION['message'] = "$success item(s) added to your cart.";
} else {
$_SESSION['message'] = "Failed to add items to cart.";
}

header("Location: wishlist.php"); // Redirect back to wishlist page instead of cart
exit();
} else {
$_SESSION['message'] = "No items selected or invalid request.";
error_log("Invalid request to add_selected_to_cart.php");
header("Location: wishlist.php");
exit();
}
49 changes: 49 additions & 0 deletions public/views/wishlist/controllers/add_to_cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
session_start();
include './config.php';

// For debugging
error_log("add_to_cart.php accessed");
error_log("POST data: " . print_r($_POST, true));

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['product_id'])) {
$user_id = $_SESSION['user_id'] ?? 0;

if ($user_id === 0) {
$_SESSION['message'] = "Please log in to add items to your cart.";
header("Location: login.php");
exit();
}

$product_id = (int)$_POST['product_id'];
$quantity = isset($_POST['quantity']) ? (int)$_POST['quantity'] : 1;

// Make sure quantity is at least 1
if ($quantity < 1) {
$quantity = 1;
}

error_log("Adding product ID: $product_id, Quantity: $quantity to cart for user ID: $user_id");

// Add to cart query with ON DUPLICATE KEY UPDATE to handle if the product is already in cart
$query = "INSERT INTO cart_items (user_id, product_id, quantity) VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE quantity = quantity + ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("iiii", $user_id, $product_id, $quantity, $quantity);

if ($stmt->execute()) {
$_SESSION['message'] = "Product added to your cart!";
error_log("Product successfully added to cart");
} else {
$_SESSION['message'] = "Failed to add product to cart: " . $conn->error;
error_log("Failed to add product to cart: " . $conn->error);
}

header("Location: wishlist.php"); // Redirect back to wishlist page instead of cart
exit();
} else {
$_SESSION['message'] = "Invalid request";
error_log("Invalid request to add_to_cart.php");
header("Location: wishlist.php");
exit();
}
41 changes: 41 additions & 0 deletions public/views/wishlist/controllers/remove_from_wishlist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
session_start();
include './config.php';

// For debugging
error_log("remove_from_wishlist.php accessed");
error_log("POST data: " . print_r($_POST, true));

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['product_id'])) {
$user_id = $_SESSION['user_id'] ?? 0;

if ($user_id === 0) {
$_SESSION['message'] = "Please log in to manage your wishlist.";
header("Location: login.php");
exit();
}

$product_id = (int)$_POST['product_id'];
error_log("Removing product ID: $product_id from wishlist for user ID: $user_id");

// Delete from wishlist
$query = "DELETE FROM wishlist WHERE user_id = ? AND product_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $user_id, $product_id);

if ($stmt->execute()) {
$_SESSION['message'] = "Item removed from your wishlist.";
error_log("Item successfully removed from wishlist");
} else {
$_SESSION['message'] = "Failed to remove item from wishlist: " . $conn->error;
error_log("Failed to remove item from wishlist: " . $conn->error);
}

header("Location: wishlist.php");
exit();
} else {
$_SESSION['message'] = "Invalid request";
error_log("Invalid request to remove_from_wishlist.php");
header("Location: wishlist.php");
exit();
}
331 changes: 331 additions & 0 deletions public/views/wishlist/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
<?php
include './config.php';
include './controllers/WishlistController.php';

// Use session to get current user
session_start();
if(isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
} else {
// Redirect to login page if not logged in
header("Location: login.php");
exit();
}

$wishlistController = new WishlistController($conn);
$wishlistItems = $wishlistController->showWishlist($user_id);

// For debugging
if(isset($_SESSION['message'])) {
$message = $_SESSION['message'];
unset($_SESSION['message']); // Clear the message after displaying
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Wishlist</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">

<style>
body {
background-color: #F2F2F2;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.wishlist-container {
width: 90%;
margin: 0 auto;
padding: 20px;
background-color: #FFFFFF;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.wishlist-header {
display: flex;
flex-direction: column;
align-items: center;
padding-bottom: 20px;
border-bottom: 1px solid #DDD;
margin-bottom: 20px;
}
.wishlist-header h1 {
margin: 0;
position: relative;
padding-top: 30px;
}
.wishlist-header h1::before {
content: "\f004";
font-family: "Font Awesome 5 Free";
font-size: 20px;
color: #FF0000;
position: absolute;
top: -16px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
}
.wishlist-header .actions {
display: flex;
justify-content: flex-end;
width: 100%;
margin-top: 15px;
}
.wishlist-header .actions button {
padding: 9px 10px;
background-color: #403431;
color: #FFFFFF;
border: none;
cursor: pointer;
border-radius: 4px;
margin-left: 10px;
}
.wishlist-header .actions button:hover {
background-color: #6c757d;
}

/* Card Layout Styles */
.wishlist-cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.wishlist-card {
border: 1px solid #DDD;
border-radius: 8px;
padding: 15px;
background-color: #ffffff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
position: relative;
}
.wishlist-card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.product-image-container {
width: 100%;
height: 180px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
margin-bottom: 15px;
border-radius: 4px;
}
.product-image {
max-width: 100%;
max-height: 180px;
object-fit: contain;
}
.product-info h3 {
margin: 0 0 10px 0;
font-size: 16px;
height: 40px;
overflow: hidden;
}
.product-price {
font-weight: bold;
font-size: 18px;
margin: 10px 0;
color: #403431;
}
.original-price {
text-decoration: line-through;
color: #999;
font-size: 14px;
margin-right: 5px;
}
.product-actions {
display: flex;
justify-content: space-between;
margin-top: 15px;
}
.btn {
padding: 8px 12px;
background-color: #403431;
color: #FFFFFF;
border: none;
cursor: pointer;
border-radius: 4px;
flex: 1;
text-align: center;
margin: 0 5px;
font-size: 13px;
}
.btn:hover {
background-color: #6c757d;
}
.btn-remove {
background-color: #d9534f;
}
.btn-remove:hover {
background-color: #c9302c;
}
.btn-add-to-cart {
background-color: #5cb85c;
}
.btn-add-to-cart:hover {
background-color: #4cae4c;
}
.select-checkbox {
position: absolute;
top: 10px;
right: 10px;
transform: scale(1.3);
}
.empty-wishlist {
text-align: center;
padding: 30px;
color: #6c757d;
font-size: 18px;
}
.message {
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
text-align: center;
background-color: #d4edda;
color: #155724;
}
</style>
</head>
<body>
<div class="wishlist-container">
<?php if(isset($message)): ?>
<div class="message"><?= $message ?></div>
<?php endif; ?>

<div class="wishlist-header">
<h1>Wishlist</h1>
<?php if ($wishlistItems && $wishlistItems->num_rows > 0): ?>
<div class="actions">
<button id="add-selected" onclick="addSelectedToCart()">
<i class="fas fa-cart-plus"></i> Add Selected to Cart
</button>
<button onclick="addAllToCart()">
<i class="fas fa-cart-plus"></i> Add All to Cart
</button>
</div>
<?php endif; ?>
</div>

<?php if ($wishlistItems && $wishlistItems->num_rows > 0): ?>
<form id="wishlistForm" method="post">
<div class="wishlist-cards">
<?php while ($row = $wishlistItems->fetch_assoc()): ?>
<div class="wishlist-card">
<input type="checkbox" name="select[]" value="<?= $row['id']; ?>" class="select-checkbox">
<div class="product-image-container">
<img src="<?= $row['image']; ?>" alt="<?= $row['name']; ?>" class="product-image">
</div>
<div class="product-info">
<h3><?= $row['name']; ?></h3>
<div class="product-price">
<?php if(isset($row['original_price']) && $row['original_price'] > $row['price']): ?>
<span class="original-price"><?= $row['original_price']; ?> USD</span>
<?php endif; ?>
<?= $row['price']; ?> USD
</div>
<div class="stock-status">
<span class="in-stock"><i class="fas fa-check-circle"></i> In Stock</span>
</div>
<div class="product-actions">
<button type="button" onclick="removeFromWishlist(<?= $row['id']; ?>)" class="btn btn-remove">
<i class="fas fa-trash"></i> Remove
</button>
<button type="button" onclick="addToCart(<?= $row['id']; ?>)" class="btn btn-add-to-cart">
<i class="fas fa-cart-plus"></i> Add to Cart
</button>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</form>
<?php else: ?>
<div class="empty-wishlist">
<i class="fas fa-heart-broken" style="font-size: 48px; color: #d9534f; margin-bottom: 20px;"></i>
<p>Your wishlist is empty.</p>
<button class="btn" onclick="location.href='../public/views/category.php'">
<i class="fas fa-shopping-bag"></i> Continue Shopping
</button>
</div>
<?php endif; ?>
</div>

<script>
// For debugging
function showAlert(message) {
alert(message);
}

function removeFromWishlist(productId) {
if(confirm('Are you sure you want to remove this item from your wishlist?')) {
console.log("Removing product ID: " + productId);

let form = document.createElement('form');
form.method = 'POST';
form.action = 'remove_from_wishlist.php';

let input = document.createElement('input');
input.type = 'hidden';
input.name = 'product_id';
input.value = productId;

form.appendChild(input);
document.body.appendChild(form);
form.submit();
}
}

function addToCart(productId) {
console.log("Adding to cart product ID: " + productId);

let form = document.createElement('form');
form.method = 'POST';
form.action = 'add_to_cart.php';

let input = document.createElement('input');
input.type = 'hidden';
input.name = 'product_id';
input.value = productId;

form.appendChild(input);
document.body.appendChild(form);
form.submit();
}

function addSelectedToCart() {
const selectedProducts = document.querySelectorAll('.select-checkbox:checked');
if(selectedProducts.length === 0) {
alert('Please select at least one product.');
return;
}

let form = document.getElementById('wishlistForm');
form.action = 'add_selected_to_cart.php';
form.submit();
}

function addAllToCart() {
// Select all checkboxes
const allCheckboxes = document.querySelectorAll('.select-checkbox');
allCheckboxes.forEach(checkbox => {
checkbox.checked = true;
});

// Submit the form
let form = document.getElementById('wishlistForm');
form.action = 'add_selected_to_cart.php';
form.submit();
}
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions public/views/wishlist/models/Wishlist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
class Wishlist {

private $conn;

public function __construct($conn) {
$this->conn = $conn;
}

public function addToWishlist($user_id, $product_id) {
// Check if item already exists in wishlist
$checkQuery = "SELECT * FROM wishlist WHERE user_id = ? AND product_id = ?";
$checkStmt = $this->conn->prepare($checkQuery);
$checkStmt->bind_param("ii", $user_id, $product_id);
$checkStmt->execute();
$result = $checkStmt->get_result();

if ($result->num_rows > 0) {
return true; // Item already in wishlist
}

// Add new item to wishlist
$query = "INSERT INTO wishlist (user_id, product_id) VALUES (?, ?)";
$stmt = $this->conn->prepare($query);
$stmt->bind_param("ii", $user_id, $product_id);
return $stmt->execute();
}

public function getWishlist($user_id) {
// Modify query to ensure we get the product_id as 'id'
$query = "SELECT p.id, p.name, p.price, p.image, p.stock, w.product_id
FROM wishlist w
INNER JOIN products p ON w.product_id = p.id
WHERE w.user_id = ?";
$stmt = $this->conn->prepare($query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
return $stmt->get_result();
}

public function removeFromWishlist($user_id, $product_id) {
$query = "DELETE FROM wishlist WHERE user_id = ? AND product_id = ?";
$stmt = $this->conn->prepare($query);
$stmt->bind_param("ii", $user_id, $product_id);
return $stmt->execute();
}
}
26 changes: 26 additions & 0 deletions public/views/wishlist/views/wishlist_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Wishlist</title>
</head>
<body>
<h1>Your Wishlist</h1>

<?php if ($wishlistItems->num_rows > 0): ?>
<ul>
<?php while ($row = $wishlistItems->fetch_assoc()): ?>
<li>
<img src="<?= $row['image']; ?>" alt="<?= $row['name']; ?>" width="100">
<p><?= $row['name']; ?></p>
<p><?= $row['price']; ?> USD</p>
<a href="product_details.php?id=<?= $row['id']; ?>">View Details</a>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>Your wishlist is empty.</p>
<?php endif; ?>
</body>
</html>
Empty file modified tuqa/wishlist/controllers/add_selected_to_cart.php
100644 → 100755
Empty file.
Empty file modified tuqa/wishlist/controllers/add_to_cart.php
100644 → 100755
Empty file.
Empty file modified tuqa/wishlist/controllers/remove_from_wishlist.php
100644 → 100755
Empty file.