public FormSubmission processUpdate() {
l.info("modifying cart for session: "+req.getSession().getId());
FormSubmission fs = new FormSubmission();
try {
String action = req.getParameter(Parameters.CART_ACTION.getId());
if (action.equals("Checkout")) {
fs.setResultView(checkout());
}
else if (action.equals("Move Selected to WishList")) {
fs = moveSelectedToWishList();
}
else if (action.equals("Update Quantity")) {
for (Enumeration e = req.getParameterNames() ; e.hasMoreElements() ;) {
String name = (String) e.nextElement();
if (name.endsWith(Constants.Parameters.PRODUCT_QUANTITY.getId())) {
String[] parts = name.split("_");
Integer quantity = Integer.parseInt(req.getParameter(name));
String id = parts[0];
l.fine("updating qty for "+id);
ProductsInCartService pics = new ProductsInCartService();
ProductsInCart pic = pics.getById(new Long(id));
if (quantity == 0) {
pics.remove(pic);
}
else {
pic.setQuantity(quantity);
pics.store(pic);
}
}
}
updateCart();
fs.setResultView(getCartView());
}
} catch (Exception e) {
l.log(Level.WARNING, "Unable to process cart update", e);
View v = getCartView();
v.setMessage("Unable to process request.");
fs.setResultView(v);
fs.setResultMessage("Unable to process request.");
}
return fs;