%@ page import="com.brainysoftware.burnaby.Product" %>
<%@ page import="com.brainysoftware.burnaby.ShoppingItem" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
String base = (String) application.getAttribute("base");
Hashtable shoppingCart = (Hashtable) session.getAttribute("shoppingCart");
if (shoppingCart==null)
shoppingCart = new Hashtable(10);
String action = request.getParameter("action");
if (action!=null && action.equals("addShoppingItem")) {
try {
int productId = Integer.parseInt(request.getParameter("productId"));
Product product = dbBean.getProductDetails(productId);
if (product!=null) {
ShoppingItem item = new ShoppingItem();
item.productId = productId;
item.quantity = 1;
item.price = product.price;
item.name = product.name;
item.description = product.description;
shoppingCart.remove(Integer.toString(productId));
shoppingCart.put(Integer.toString(productId), item);
session.setAttribute("shoppingCart", shoppingCart);
}
}
catch (Exception e) {
out.println("Error adding the selected product to the shopping cart");
}
}
if (action!=null && action.equals("updateShoppingItem")) {
try {
int productId = Integer.parseInt(request.getParameter("productId"));
int quantity = Integer.parseInt(request.getParameter("quantity"));
ShoppingItem item = (ShoppingItem) shoppingCart.get(Integer.toString(productId));
if (item!=null) {
item.quantity = quantity;
}
}
catch (Exception e) {
out.println("Error updating shopping cart");
}
}
if (action!=null && action.equals("deleteShoppingItem")) {
try {
int productId = Integer.parseInt(request.getParameter("productId"));
shoppingCart.remove(Integer.toString(productId));
}
catch (Exception e) {
out.println("Error deleting the selected item from the shopping cart");
}
}
%>
Shopping Cart
|
|
<%
%>
Name |
Description |
Price |
Quantity |
Subtotal |
Update |
Delete |
<%
Enumeration enum = shoppingCart.elements();
while (enum.hasMoreElements()) {
ShoppingItem item = (ShoppingItem) enum.nextElement();
%>
<%=item.name%> |
<%=item.description%> |
<%=item.price%> |
<%
}
%>
Check Out |
|