@RequestMapping(value = "/viewCart.htm", method = RequestMethod.GET)
  public String viewCart(ModelMap model, HttpServletRequest request) throws PricingException {
    Order cart = retrieveCartOrder(request, model);
    CartSummary cartSummary = new CartSummary();

    if (cart.getOrderItems() != null) {
      for (OrderItem orderItem : cart.getOrderItems()) {
        if (orderItem instanceof DiscreteOrderItem) {
          Sku sku = catalogService.findSkuById(((DiscreteOrderItem) orderItem).getSku().getId());
          if (!(sku.getSalePrice().equals(((DiscreteOrderItem) orderItem).getSalePrice()))) {
            orderItem.setSalePrice(sku.getSalePrice());
          }
          if (!(sku.getRetailPrice().equals(((DiscreteOrderItem) orderItem).getRetailPrice()))) {
            orderItem.setRetailPrice(sku.getRetailPrice());
          }

          if (orderItem.getSalePrice() != orderItem.getRetailPrice()) {
            orderItem.setPrice(orderItem.getSalePrice());
          } else {
            orderItem.setPrice(orderItem.getRetailPrice());
          }

          orderItem.getPrice();
        }
      }
    }

    if (cart.getOrderItems() != null) {
      for (OrderItem orderItem : cart.getOrderItems()) {
        CartOrderItem cartOrderItem = new CartOrderItem();
        cartOrderItem.setOrderItem(orderItem);
        cartOrderItem.setQuantity(orderItem.getQuantity());
        cartSummary.getRows().add(cartOrderItem);
      }
    }

    if ((cart.getFulfillmentGroups() != null) && (cart.getFulfillmentGroups().isEmpty() == false)) {
      String cartShippingMethod = cart.getFulfillmentGroups().get(0).getMethod();
      String cartShippingService = cart.getFulfillmentGroups().get(0).getService();

      if (cartShippingMethod != null) {
        if (cartShippingMethod.equals("standard")) {
          cartSummary = createFulfillmentGroup(cartSummary, "standard", cartShippingService, cart);
        } else if (cartShippingMethod.equals("expedited")) {
          cartSummary = createFulfillmentGroup(cartSummary, "expedited", cartShippingService, cart);
        }
      }
    }

    updateFulfillmentGroups(cartSummary, cart);
    cartSummary.setOrderDiscounts(cart.getTotalAdjustmentsValue().getAmount());
    model.addAttribute("cartSummary", cartSummary);
    return cartViewRedirect ? "redirect:" + cartView : cartView;
  }
 protected Order updateFulfillmentGroups(CartSummary cartSummary, Order currentCartOrder)
     throws PricingException {
   FulfillmentGroup fg = cartSummary.getFulfillmentGroup();
   if (fg.getId() == null) {
     cartService.removeAllFulfillmentGroupsFromOrder(currentCartOrder, false);
     for (CartOrderItem item : cartSummary.getRows()) {
       item.getOrderItem().setOrder(currentCartOrder);
       fg =
           cartService.addItemToFulfillmentGroup(
               item.getOrderItem(), fg, item.getQuantity(), false);
     }
     cartSummary.setFulfillmentGroup(fg);
   }
   return cartService.save(currentCartOrder, true);
 }
 @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;
 }