D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
siliguritoys.com
/
Filename :
my_cart.php
back
Copy
<?php session_start(); include 'config.php'; if (!isset($_SESSION['user_id'])) { echo "<script>alert('You need to login first to see your cart.'); window.location.href='login.php';</script>"; exit(); } $user_id = $_SESSION['user_id']; $cart_query = "SELECT c.product_id, p.name, p.price, p.image_1, c.quantity FROM cart c JOIN slgtoys_products p ON c.product_id = p.id WHERE c.user_id = $user_id"; $result = mysqli_query($conn, $cart_query); $products = []; while ($row = mysqli_fetch_assoc($result)) { $products[] = $row; } $grand_total = array_sum(array_map(function ($product) { return $product['price'] * $product['quantity']; }, $products)); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" /> <title>Shopping Cart</title> <?php require 'style.php' ?> <script src="https://cdn.tailwindcss.com"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet" /> </head> <body class="bg-gradient-to-r from-blue-50 to-gray-100 min-h-screen"> <?php require 'header.php' ?> <main class="container mx-auto px-4 py-8"> <h1 class="text-5xl font-extrabold mb-8 text-center text-blue-700">🛒 My Cart</h1> <div class="flex flex-col lg:flex-row gap-8"> <div class="w-full lg:w-2/3 bg-white p-6 shadow-2xl rounded-2xl transition hover:shadow-lg"> <?php if (!empty($products)) { ?> <?php foreach ($products as $product) { ?> <div class="flex items-center border-b pb-4 mb-4 hover:bg-gray-50 transition ease-in-out duration-200 rounded-lg shadow-sm"> <img alt="<?php echo $product['name']; ?>" class="w-28 h-36 object-cover rounded-lg mr-6 shadow-md transform hover:scale-105 transition" src="slgadmintoys/<?php echo $product['image_1']; ?>" /> <div class="flex-1"> <h2 class="text-2xl font-semibold text-gray-800 hover:text-blue-500 transition duration-150">✨ <?php echo $product['name']; ?></h2> <p class="text-sm text-gray-600">Price: ₹<?php echo number_format($product['price'], 2); ?></p> <p class="text-sm text-green-600">✔️ In Stock</p> </div> <div class="text-right"> <p class="text-lg font-bold text-gray-800">₹<?php echo number_format($product['price'] * $product['quantity'], 2); ?></p> <input type="number" class="border border-gray-300 rounded-lg p-2 mt-2 quantity w-20 text-center focus:ring-2 focus:ring-blue-500 focus:outline-none transition" data-product-id="<?php echo $product['product_id']; ?>" value="<?php echo $product['quantity']; ?>" min="1" /> </div> </div> <div class="flex justify-between text-gray-600 mb-6"> <a href="#" class="remove-btn text-red-500 hover:underline transition duration-150" data-product-id="<?php echo $product['product_id']; ?>"><i class="fas fa-trash-alt mr-1"></i> Remove</a> </div> <?php } ?> <?php } else { ?> <p class="text-gray-600 text-center">Your cart is empty! 😔</p> <?php } ?> </div> <div class="w-full lg:w-1/3 bg-white p-6 shadow-2xl rounded-2xl transition hover:shadow-lg"> <div class="mb-6"> <label class="block text-gray-600 mb-2 text-sm font-medium" for="promo-code">🎁 Enter Promo Code</label> <div class="flex"> <input class="border border-gray-300 rounded-l-lg p-2 flex-1 text-sm focus:ring-2 focus:ring-blue-500 focus:outline-none" id="promo-code" placeholder="Promo Code" type="text" /> <button class="bg-gradient-to-r from-green-400 to-blue-500 text-white text-sm rounded-r-lg px-4 hover:from-green-500 hover:to-blue-600 transition">Apply</button> </div> </div> <div class="border-t pt-4"> <div class="flex justify-between text-gray-600 mb-3"> <p>Subtotal</p> <p>₹<?php echo number_format($grand_total, 2); ?></p> </div> <div class="flex justify-between text-gray-600 mb-3"> <p>Shipping</p> <p>Free 🚚</p> </div> <div class="flex justify-between text-gray-600 mb-3"> <p>Tax</p> <p>TBD</p> </div> <div class="flex justify-between text-lg font-bold mb-4"> <p>Total</p> <p>₹<?php echo number_format($grand_total, 2); ?></p> </div> <button class="bg-yellow-400 text-black font-bold py-3 px-6 rounded-lg w-full hover:bg-yellow-500 transition duration-150 shadow-lg transform hover:scale-105" onclick="window.location.href='checkout.php';">Proceed to Checkout ➡️</button> </div> </div> </div> </main> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $(".remove-btn").click(function() { var productId = $(this).data("product-id"); $.ajax({ url: "cart_handler.php", method: "POST", data: { product_id: productId, action: "remove" }, success: function(response) { location.reload(); } }); }); $(".quantity").change(function() { var productId = $(this).data("product-id"); var quantity = $(this).val(); $.ajax({ url: "cart_handler.php", method: "POST", data: { product_id: productId, action: "update", quantity: quantity }, success: function(response) { location.reload(); } }); }); }); </script> </body> </html>