[e3d4e0a] | 1 | <?php
|
---|
| 2 | session_start();
|
---|
| 3 | if(!isset($_SESSION['user_ID'])) {
|
---|
| 4 | header("Location: ./Log In.php");
|
---|
| 5 | }
|
---|
| 6 | require "./connect.php";
|
---|
| 7 |
|
---|
| 8 | if(isset($_POST['submit']) && isset($_POST['product_id'])) {
|
---|
| 9 |
|
---|
| 10 | if($_POST['submit'] == 'Remove') {
|
---|
| 11 | $res = mysqli_query($conn, "DELETE FROM cart WHERE user_id = {$_SESSION['user_ID']} AND product_id = {$_POST['product_id']};");
|
---|
| 12 | }
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | function get_cart_products() {
|
---|
| 16 | global $conn;
|
---|
| 17 | $products = [];
|
---|
| 18 | $res = mysqli_query($conn, "SELECT cart.quantity, products.product_id, products.name, products.category, products.price, products.discount, products.image1 FROM products INNER JOIN cart ON
|
---|
| 19 | products.product_id = cart.product_id WHERE user_id = {$_SESSION['user_ID']};");
|
---|
| 20 |
|
---|
| 21 | foreach($res as $row) {
|
---|
| 22 | $products[] = $row;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | return $products;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | $product_list = get_cart_products();
|
---|
| 29 | $sub_total_price = 0.0;
|
---|
| 30 | $shipping_price = 2;
|
---|
| 31 | ?>
|
---|
| 32 |
|
---|
| 33 | <!DOCTYPE html>
|
---|
| 34 | <html lang="en">
|
---|
| 35 | <head>
|
---|
| 36 | <meta charset="UTF-8">
|
---|
| 37 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
---|
| 38 | <title>Cart</title>
|
---|
| 39 | <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
|
---|
| 40 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css">
|
---|
| 41 | <link rel="stylesheet" href="https://unpkg.com/boxicons@latest/css/boxicons.min.css">
|
---|
| 42 | <link rel="stylesheet" href="./CSS/Header.css">
|
---|
| 43 | <link rel="stylesheet" href="./CSS/Cart.css">
|
---|
| 44 | </head>
|
---|
| 45 | <body>
|
---|
| 46 | <?php include './components/Header.html' ?>
|
---|
| 47 |
|
---|
| 48 | <section>
|
---|
| 49 | <div class="pagination">
|
---|
| 50 | <p>Home > Shopping Cart</p>
|
---|
| 51 | </div>
|
---|
| 52 | <div class="container px-4 py-5 mx-auto">
|
---|
| 53 | <div class="row d-flex justify-content-center">
|
---|
| 54 | <div class="col-5">
|
---|
| 55 | <h4 class="heading">Shopping Cart</h4>
|
---|
| 56 | </div>
|
---|
| 57 | <div class="col-7">
|
---|
| 58 | <div class="row text-right">
|
---|
| 59 | <div class="col-4">
|
---|
| 60 | <h6 class="mt-2">Quantity</h6>
|
---|
| 61 | </div>
|
---|
| 62 | <div class="col-4">
|
---|
| 63 | <h6 class="mt-2">Price</h6>
|
---|
| 64 | </div>
|
---|
| 65 | </div>
|
---|
| 66 | </div>
|
---|
| 67 | </div>
|
---|
| 68 |
|
---|
| 69 | <?php
|
---|
| 70 | foreach($product_list as $product) { ?>
|
---|
| 71 | <div class="row d-flex justify-content-center border-top">
|
---|
| 72 | <div class="col-5">
|
---|
| 73 | <div class="row d-flex">
|
---|
| 74 | <div class="book">
|
---|
| 75 | <img src="<?php
|
---|
| 76 | if($product['image1'] != null) {
|
---|
| 77 | $first_image = basename(strrchr($product['image1'], '/'));
|
---|
| 78 | $first_image = str_replace(array("'"), '', $first_image);
|
---|
| 79 | echo "./UPLOADED_IMAGES/".$first_image;
|
---|
| 80 | }
|
---|
| 81 | ?>" class="book-img">
|
---|
| 82 | </div>
|
---|
| 83 | <div class="my-auto flex-column d-flex pad-left">
|
---|
| 84 | <h6 class="mob-text"><?php echo $product['name'] ?></h6>
|
---|
| 85 | <p class="mob-text"><?php echo $product['category'] ?></p>
|
---|
| 86 | </div>
|
---|
| 87 | </div>
|
---|
| 88 | </div>
|
---|
| 89 | <div class="my-auto col-7">
|
---|
| 90 | <div class="row text-right">
|
---|
| 91 | <div class="col-4">
|
---|
| 92 | <div class="row d-flex justify-content-end px-3">
|
---|
| 93 | <p class="mb-0" id="cnt1"><?php echo $product['quantity'] ?></p>
|
---|
| 94 | </div>
|
---|
| 95 | </div>
|
---|
| 96 | <div class="col-4">
|
---|
| 97 | <h6 class="mob-text">
|
---|
| 98 | <?php
|
---|
| 99 | $discountAmount = $product['price'] * ($product['discount'] / 100);
|
---|
| 100 | $price_amount = (($product['price'] - $discountAmount) * $product['quantity']);
|
---|
| 101 | $sub_total_price += $price_amount;
|
---|
| 102 | echo "$".$price_amount;
|
---|
| 103 | ?>
|
---|
| 104 | </h6>
|
---|
| 105 | </div>
|
---|
| 106 | <form action="./Cart.php" method="POST">
|
---|
| 107 | <input type="hidden" name="product_id" value="<?php echo $product['product_id'] ?>">
|
---|
| 108 | <input class="btn btn-sm btn-danger" type="submit" name="submit" value="Remove">
|
---|
| 109 | </form>
|
---|
| 110 | </div>
|
---|
| 111 | </div>
|
---|
| 112 | </div>
|
---|
| 113 | <?php
|
---|
| 114 | }
|
---|
| 115 | ?>
|
---|
| 116 |
|
---|
| 117 | <div class="row justify-content-center">
|
---|
| 118 | <div class="col-lg-12">
|
---|
| 119 | <div class="card">
|
---|
| 120 | <div class="row">
|
---|
| 121 | <div class="col-lg-3 radio-group">
|
---|
| 122 | <div class="row d-flex px-3 radio">
|
---|
| 123 | <img class="pay" src="https://i.imgur.com/WIAP9Ku.jpg">
|
---|
| 124 | <p class="my-auto">Credit Card</p>
|
---|
| 125 | </div>
|
---|
| 126 | <div class="row d-flex px-3 radio gray">
|
---|
| 127 | <img class="pay" src="https://i.imgur.com/OdxcctP.jpg">
|
---|
| 128 | <p class="my-auto">Debit Card</p>
|
---|
| 129 | </div>
|
---|
| 130 | </div>
|
---|
| 131 | <div class="col-lg-5">
|
---|
| 132 | <div class="row px-2">
|
---|
| 133 | <div class="form-group col-md-6">
|
---|
| 134 | <label class="form-control-label">Name on Card</label>
|
---|
| 135 | <input type="text" id="cname" name="cname" placeholder="John Doe">
|
---|
| 136 | </div>
|
---|
| 137 | <div class="form-group col-md-6">
|
---|
| 138 | <label class="form-control-label">Card Number</label>
|
---|
| 139 | <input type="text" id="cnum" name="cnum" placeholder="1111 2222 3333 4444" maxlength="19">
|
---|
| 140 | </div>
|
---|
| 141 | </div>
|
---|
| 142 | <div class="row px-2">
|
---|
| 143 | <div class="form-group col-md-6">
|
---|
| 144 | <label class="form-control-label">Expiration Date</label>
|
---|
| 145 | <input type="text" id="exp" name="exp" placeholder="MM/YYYY" maxlength="7">
|
---|
| 146 | </div>
|
---|
| 147 | <div class="form-group col-md-6">
|
---|
| 148 | <label class="form-control-label">CVV</label>
|
---|
| 149 | <input type="text" id="cvv" name="cvv" placeholder="***" maxlength="3">
|
---|
| 150 | </div>
|
---|
| 151 | </div>
|
---|
| 152 | </div>
|
---|
| 153 | <div class="col-lg-4 mt-2">
|
---|
| 154 | <div class="row d-flex justify-content-between px-4">
|
---|
| 155 | <p class="mb-1 text-left">Subtotal</p>
|
---|
| 156 | <h6 class="mb-1 text-right">$<?php echo $sub_total_price ?></h6>
|
---|
| 157 | </div>
|
---|
| 158 | <div class="row d-flex justify-content-between px-4">
|
---|
| 159 | <p class="mb-1 text-left">Shipping</p>
|
---|
| 160 | <h6 class="mb-1 text-right">$<?php echo $shipping_price ?></h6>
|
---|
| 161 | </div>
|
---|
| 162 | <div class="row d-flex justify-content-between px-4" id="tax">
|
---|
| 163 | <p class="mb-1 text-left">Total</p>
|
---|
| 164 | <h6 class="mb-1 text-right">$<?php echo $sub_total_price + $shipping_price ?></h6>
|
---|
| 165 | </div>
|
---|
| 166 | <form action="./CreateOrder.php" method="POST">
|
---|
| 167 | <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_ID'] ?>">
|
---|
| 168 | <button class="btn-block btn-blue">
|
---|
| 169 | <span>
|
---|
| 170 | <span id="checkout">Checkout</span>
|
---|
| 171 | <span id="check-amt">$<?php echo $sub_total_price + $shipping_price ?></span>
|
---|
| 172 | </span>
|
---|
| 173 | </button>
|
---|
| 174 | </form>
|
---|
| 175 | </div>
|
---|
| 176 | </div>
|
---|
| 177 | </div>
|
---|
| 178 | </div>
|
---|
| 179 | </div>
|
---|
| 180 | </div>
|
---|
| 181 | </section>
|
---|
| 182 |
|
---|
| 183 | <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
---|
| 184 | <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
|
---|
| 185 | <script src="Cart.js"></script>
|
---|
| 186 | </body>
|
---|
| 187 | </html> |
---|