|
| 1 | +<%-- |
| 2 | + Document : CartPage |
| 3 | + Created on : Apr 18, 2021, 2:36:30 PM |
| 4 | + Author : engryankey |
| 5 | +--%> |
| 6 | + |
| 7 | +<%@page import="src.CartItem"%> |
| 8 | +<%@page import="java.util.List"%> |
| 9 | +<%@page import="java.util.ArrayList"%> |
| 10 | +<%@page contentType="text/html" pageEncoding="UTF-8"%> |
| 11 | +<!DOCTYPE html> |
| 12 | +<html> |
| 13 | + <jsp:include page="head.jsp" > |
| 14 | + <jsp:param name="title" value="Dashboard" /> |
| 15 | + </jsp:include> |
| 16 | + <% |
| 17 | + if (session.getAttribute("user") == null) { |
| 18 | + response.sendRedirect("login.jsp"); |
| 19 | + } |
| 20 | + %> |
| 21 | + <body> |
| 22 | + <jsp:include page="navbar.jsp" > |
| 23 | + <jsp:param name="login" value="" /> |
| 24 | + <jsp:param name="register" value="" /> |
| 25 | + <jsp:param name="home" value="" /> |
| 26 | + <jsp:param name="dashboard" value="active" /> |
| 27 | + </jsp:include> |
| 28 | + <div class="container"> |
| 29 | + <div class="row"> |
| 30 | + <div class="col-sm-4 toggleds" id="leftdash"> |
| 31 | + <div align="center" class="dashimage"> |
| 32 | + <img src="img/dp.png" class="al" align="center"> |
| 33 | + </div> |
| 34 | + <br> |
| 35 | + <div align="center"> |
| 36 | + <h3 class="head">${user.getName()}</h3> |
| 37 | + <strong>Member since</strong><br> |
| 38 | + ${user.getJoined()} |
| 39 | + <br><br> |
| 40 | + |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <div class="col-sm-8" id="rightdash"> |
| 44 | + <div class="row"> |
| 45 | + <div class="col-1"></div> |
| 46 | + <div class="col-10"> |
| 47 | + <div class="display container"> |
| 48 | + <% if(session.getAttribute("cart") != null) {%> |
| 49 | + <% |
| 50 | + List cart = (ArrayList) session.getAttribute("cart"); |
| 51 | + int total_price = 0; |
| 52 | + int total_items = 0; |
| 53 | + %> |
| 54 | + <% if (cart.size() != 0 ) { %> |
| 55 | + <h4 align="center" class="head">Your Shopping Cart</h4> |
| 56 | + <br> |
| 57 | + <% for(int i=0; i < cart.size(); i++) { %> |
| 58 | + <% CartItem product = (CartItem) cart.get(i); %> |
| 59 | + <% |
| 60 | + total_price += Integer.parseInt(product.getProduct().getPrice()) * product.getQuantity(); |
| 61 | + total_items += product.getQuantity(); |
| 62 | + %> |
| 63 | + <div class="product"> |
| 64 | + <div class="row g-3"> |
| 65 | + <div class="col-md-4" align="center"> |
| 66 | + <form action="Products" method="GET"> |
| 67 | + <a href="" style="text-decoration: none;" onclick="this.closest('form').submit();return false;"><img src="img/uploaded/<%= product.getProduct().getImage()%>" alt="" srcset="" width="150" height="200"></a> |
| 68 | + <input type="hidden" name="id" value="<%= product.getId() %>"> |
| 69 | + </form> |
| 70 | + </div> |
| 71 | + <div class="col-md-6"> |
| 72 | + <h4> |
| 73 | + <a href="" style="text-decoration: none;" onclick="this.closest('form').submit();return false;"><%= product.getProduct().getPtitle() %></a> |
| 74 | + |
| 75 | + </h4> |
| 76 | + <span class="price"> |
| 77 | + £<%= product.getProduct().getPrice() %> <span style="color: black">unit price</span> |
| 78 | + <% if(product.getQuantity() > 1) { %> |
| 79 | + <br> £<%= Integer.parseInt(product.getProduct().getPrice()) * product.getQuantity() %> <span style="color: black">Total price</span> |
| 80 | + <% } %> |
| 81 | + </span> |
| 82 | + <br> |
| 83 | + <br> |
| 84 | + <br> |
| 85 | + <center class="row edit_delete"> |
| 86 | + <form action="CartServlet" method="POST"> |
| 87 | + <div class="row g-3"> |
| 88 | + <div class="col-auto"> |
| 89 | + <input type="text" name="quantity" placeholder="Quantity" value="<%= product.getQuantity() %>" class="form-control" size="3"> |
| 90 | + </div> |
| 91 | + <div class="col-auto"> |
| 92 | + <button type="submit" class="btn btn-outline-success" id="bt"> |
| 93 | + UPDATE <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor" class="bi bi-check2-circle" viewBox="0 0 16 16"> |
| 94 | + <path d="M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z"/> |
| 95 | + <path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z"/> |
| 96 | + </svg> |
| 97 | + </button> |
| 98 | + </div> |
| 99 | + <input type="hidden" name="action" value="UPDATE_QUANTITY"> |
| 100 | + <input type="hidden" name="id" value="<%= product.getId() %>"> |
| 101 | + </div> |
| 102 | + </form> |
| 103 | + </center> |
| 104 | + </div> |
| 105 | + <div class="col-md-1" align="right"> |
| 106 | + <form action="CartServlet" method="POST"> |
| 107 | + <a href="" style="text-decoration: none;" onclick="this.closest('form').submit();return false;"> |
| 108 | + <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="red" class="bi bi-trash danger" viewBox="0 0 16 16"> |
| 109 | + <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/> |
| 110 | + <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/> |
| 111 | + </svg> |
| 112 | + </a> |
| 113 | + <input type="hidden" name="action" value="REMOVE_FROM_CART"> |
| 114 | + <input type="hidden" name="id" value="<%= product.getId() %>"> |
| 115 | + </form> |
| 116 | + </div> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + <% } %> |
| 120 | + <h4 class="category" align="center"> |
| 121 | + Total Price <span class="price">£<%= total_price %></span> |
| 122 | + </h4> |
| 123 | + <h4 class="category" align="center"> |
| 124 | + You have <span class="price"><%= total_items %></span> total item(s) in the cart |
| 125 | + </h4> |
| 126 | + <h4 align="center"> |
| 127 | + <form action="CartServlet" method="POST"> |
| 128 | + <a href="" style="text-decoration: none;" onclick="this.closest('form').submit();return false;"> |
| 129 | + <button class="btn btn-primary btn-lg">CHECK OUT</button> |
| 130 | + </a> |
| 131 | + <input type="hidden" name="action" value="CHECKOUT"> |
| 132 | + <input type="hidden" name="id" value="6"> |
| 133 | + <input type="hidden" name="total_price" value="<%= total_price %>"> |
| 134 | + <input type="hidden" name="total_items" value="<%= total_items %>"> |
| 135 | + </form> |
| 136 | + </h4> |
| 137 | + <% } else { %> |
| 138 | + <center class="head"> |
| 139 | + <br> |
| 140 | + <br> |
| 141 | + <br> |
| 142 | + <h3>You do not have any item in your cart</h3> |
| 143 | + <a href="index.jsp"><button class="btn btn-primary btn-lg">GO TO MARKET</button></a> |
| 144 | + </center> |
| 145 | + <% } %> |
| 146 | + <% } else { %> |
| 147 | + <center class="head"> |
| 148 | + <br> |
| 149 | + <br> |
| 150 | + <br> |
| 151 | + <h3>You do not have any item in your cart</h3> |
| 152 | + <a href="index.jsp"><button class="btn btn-primary btn-lg">GO TO MARKET</button></a> |
| 153 | + </center> |
| 154 | + <% } %> |
| 155 | + </div> |
| 156 | + </div> |
| 157 | + <div class="col-1"></div> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + <jsp:include page="footer.jsp" /> |
| 163 | +</html> |
0 commit comments