showcart.jsp

  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
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*, cartexample.*, java.text.DecimalFormat" %>
<%@ page errorPage="apperror.jsp"%>

<%
String actionparam = request.getParameter("action");

if(actionparam != null && actionparam.equals("clear")) {
	session.removeAttribute("cart");
	session.removeAttribute("cartitems");
}

List<Product> productlist = (List)session.getAttribute("cart");

int cartproducts = 0;

if(session.getAttribute("cartitems") != null) {
	cartproducts = (Integer)session.getAttribute("cartitems");
}

DecimalFormat df = new DecimalFormat("####0.00");
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <meta name="description" content="Καλάθι αγορών">
	    <meta name="author" content="sofos@aueb.gr">
	    <title>Simple Cart Example - Καλάθι αγορών</title>	
	  	<!-- Latest compiled and minified CSS -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
		<!-- Bootstrap theme -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
		<!-- Custom style for this template -->
	    <link href="css/theme.css" rel="stylesheet">
	    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	    <!--[if lt IE 9]>
	      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	    <![endif]-->
    </head>
  	<body>
	    <!-- Fixed navbar -->
	    <nav class="navbar navbar-inverse navbar-fixed-top">
	      <div class="container">
	        <div class="navbar-header">
	          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
	            <span class="sr-only">Toggle navigation</span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	          </button>
	          <a class="navbar-brand" href="viewproduct.jsp">Simple Cart Example</a>
	        </div>
	        <div id="navbar" class="navbar-collapse collapse">
	          <ul class="nav navbar-nav">
	            <li><a href="viewproduct.jsp">Προϊόντα</a></li>            
	          </ul>			  
				<ul class="nav navbar-nav navbar-right">
					<li class="active">
					  	<a href="showcart.jsp">
					  		<span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Καλάθι 
					  		<span id="cart_total_products" class="badge badge-success"><% if(cartproducts > 0) {  out.println(cartproducts); } %></span>
					  	</a>				  
					</li>
				</ul>			  
	        </div><!--/.nav-collapse -->
	      </div>
	    </nav>
    	<div class="container theme-showcase" role="main">	  
			<div class="row">
				<div class="col-lg-12">
					<div class="page-header">
						<h1 class="text-info">Καλάθι αγορών</h1>
					</div>								
<%
	if(productlist != null) {
%>
					<table class="table table-bordered table-hover">	
						<tr>
							<th>Εικόνα</th>
							<th>Κωδικός</th>
							<th>Προϊόν</th>
							<th>Τιμή</th>
							<th>Ποσότητα</th>
							<th>Σύνολο</th>
						</tr>				
<%
		Product product = null;
		double sum = 0;
		
		for (int i = 0; i < productlist.size(); i++) {
			product = productlist.get(i);
			sum += product.getTotalPrice();
%>				
						<tr>
							<td><img src="<%=product.getImage() %>"  alt="<%=product.getName() %>"></td>
							<td><%=product.getCode() %></td>
							<td><%=product.getName() %></td>
							<td><%=df.format( product.getPrice() ).replace(",", ".") %> &euro;</td>
							<td><%=product.getQuantity() %></td>
							<td><%=df.format( product.getTotalPrice() ).replace(",", ".") %> &euro;</td>
						</tr>		
<%  } %>
						<tr>
							<td colspan="5" style="text-align: right;"><strong>Ολικό Σύνολο:</strong></td>
							<td><%=df.format(sum).replace(",", ".") %> &euro;</td>
						</tr>
					</table>
					<p class="text-right"><a class="btn btn-danger" href="showcart.jsp?action=clear">Άδειασμα Καλαθιού</a> <a class="btn btn-success" href="buy.jsp">Αγορά</a></p>
<%
	} else {
%>
					<div role="alert" class="alert alert-danger">Το καλάθι σας είναι άδειο</div>				
<%	}%>					
				</div>	<!-- /col-lg-12 -->	
			</div> <!-- /row -->
    	</div> <!-- /container -->
	    <!-- Bootstrap core JavaScript
	    ================================================== -->
	    <!-- Placed at the end of the document so the pages load faster -->
   		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    	<!-- Latest compiled and minified JavaScript -->
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>   
	</body>
</html>