@RequestMapping(
     value = "/viewCart.htm",
     params = "updateItemQuantity",
     method = RequestMethod.POST)
 public String updateItemQuantity(
     @ModelAttribute(value = "cartSummary") CartSummary cartSummary,
     Errors errors,
     ModelMap model,
     HttpServletRequest request)
     throws PricingException {
   if (errors.hasErrors()) {
     model.addAttribute("cartSummary", cartSummary);
     return cartView;
   }
   Order currentCartOrder = retrieveCartOrder(request, model);
   List<OrderItem> orderItems = currentCartOrder.getOrderItems();
   List<CartOrderItem> items = new ArrayList<CartOrderItem>(cartSummary.getRows());
   for (CartOrderItem cartOrderItem : items) {
     OrderItem orderItem =
         (OrderItem)
             CollectionUtils.find(
                 orderItems,
                 new BeanPropertyValueEqualsPredicate("id", cartOrderItem.getOrderItem().getId()));
     // in case the item was removed from the cart from another browser tab
     if (orderItem != null) {
       if (cartOrderItem.getQuantity() > 0) {
         orderItem.setQuantity(cartOrderItem.getQuantity());
         try {
           cartService.updateItemQuantity(currentCartOrder, orderItem);
         } catch (ItemNotFoundException e) {
           LOG.error("Item not found in order: (" + orderItem.getId() + ")", e);
         } catch (PricingException e) {
           LOG.error("Unable to price the order: (" + currentCartOrder.getId() + ")", e);
         }
       } else {
         try {
           cartService.removeItemFromOrder(currentCartOrder, orderItem);
           cartSummary.getRows().remove(cartOrderItem);
         } catch (Exception e) {
           // TODO: handle exception gracefully
           LOG.error("Unable to remove item from the order: (" + currentCartOrder.getId() + ")");
         }
       }
     }
   }
   cartSummary.setOrderDiscounts(currentCartOrder.getTotalAdjustmentsValue().getAmount());
   return cartView;
 }
  @RequestMapping(
      value = "/viewCart.htm",
      params = "removeItemFromCart",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String removeItem(
      @RequestParam long orderItemId,
      @ModelAttribute CartSummary cartSummary,
      ModelMap model,
      HttpServletRequest request) {
    Order currentCartOrder = retrieveCartOrder(request, model);
    try {
      currentCartOrder = cartService.removeItemFromOrder(currentCartOrder.getId(), orderItemId);
    } catch (PricingException e) {
      model.addAttribute("error", "remove");
      LOG.error("An error occurred while removing an item from the cart: (" + orderItemId + ")", e);
    }
    cartSummary.setOrderDiscounts(currentCartOrder.getTotalAdjustmentsValue().getAmount());

    return removeItemViewRedirect ? "redirect:" + removeItemView : removeItemView;
  }