@RequestMapping(value = "/apply", method = RequestMethod.POST)
  public String applyGiftCard(
      HttpServletRequest request,
      HttpServletResponse response,
      Model model,
      @ModelAttribute("orderInfoForm") OrderInfoForm orderInfoForm,
      @ModelAttribute("shippingInfoForm") ShippingInfoForm shippingForm,
      @ModelAttribute("billingInfoForm") BillingInfoForm billingForm,
      @ModelAttribute("giftCardInfoForm") GiftCardInfoForm giftCardInfoForm,
      BindingResult result) {
    Order cart = CartState.getCart();

    giftCardInfoFormValidator.validate(giftCardInfoForm, result);
    if (!result.hasErrors()) {
      result.reject(
          "giftCardNumber",
          "The Gift Card module is not enabled. Please contact us for more information about our AccountCredit Module (http://www.broadleafcommerce.com/contact)");
    }

    if (!(cart instanceof NullOrderImpl)) {
      model.addAttribute(
          "orderMultishipOptions",
          orderMultishipOptionService.getOrGenerateOrderMultishipOptions(cart));
      model.addAttribute("paymentRequestDTO", dtoTranslationService.translateOrder(cart));
    }

    populateModelWithReferenceData(request, model);

    return getCheckoutView();
  }
 @RequestMapping("/updateQuantity")
 public String updateQuantity(
     HttpServletRequest request,
     HttpServletResponse response,
     Model model,
     RedirectAttributes redirectAttributes,
     @ModelAttribute("addToCartItem") AddToCartItem addToCartItem)
     throws IOException, PricingException, UpdateCartException, RemoveFromCartException {
   try {
     String returnPath = super.updateQuantity(request, response, model, addToCartItem);
     if (isAjaxRequest(request)) {
       returnPath += " :: ajax";
     }
     return returnPath;
   } catch (UpdateCartException e) {
     if (e.getCause() instanceof InventoryUnavailableException) {
       // Since there was an exception, the order gets detached from the Hibernate session. This
       // re-attaches it
       CartState.setCart(orderService.findOrderById(CartState.getCart().getId()));
       if (isAjaxRequest(request)) {
         model.addAttribute(
             "errorMessage",
             "Not enough inventory to fulfill your requested amount of "
                 + addToCartItem.getQuantity());
         return getCartView() + " :: ajax";
       } else {
         redirectAttributes.addAttribute(
             "errorMessage",
             "Not enough inventory to fulfill your requested amount of "
                 + addToCartItem.getQuantity());
         return getCartPageRedirect();
       }
     } else {
       throw e;
     }
   }
 }
  /*
   * The Heat Clinic does not show the cart when a product is added. Instead, when the product is added via an AJAX
   * POST that requests JSON, we only need to return a few attributes to update the state of the page. The most
   * efficient way to do this is to call the regular add controller method, but instead return a map that contains
   * the necessary attributes. By using the @ResposeBody tag, Spring will automatically use Jackson to convert the
   * returned object into JSON for easy processing via JavaScript.
   */
  @RequestMapping(value = "/add", produces = "application/json")
  public @ResponseBody Map<String, Object> addJson(
      HttpServletRequest request,
      HttpServletResponse response,
      Model model,
      @ModelAttribute("addToCartItem") AddToCartItem addToCartItem)
      throws IOException, PricingException, AddToCartException {
    Map<String, Object> responseMap = new HashMap<String, Object>();
    try {
      super.add(request, response, model, addToCartItem);

      if (addToCartItem.getItemAttributes() == null
          || addToCartItem.getItemAttributes().size() == 0) {
        responseMap.put("productId", addToCartItem.getProductId());
      }
      responseMap.put(
          "productName", catalogService.findProductById(addToCartItem.getProductId()).getName());
      responseMap.put("quantityAdded", addToCartItem.getQuantity());
      responseMap.put("cartItemCount", String.valueOf(CartState.getCart().getItemCount()));
      if (addToCartItem.getItemAttributes() == null
          || addToCartItem.getItemAttributes().size() == 0) {
        // We don't want to return a productId to hide actions for when it is a product that has
        // multiple
        // product options. The user may want the product in another version of the options as well.
        responseMap.put("productId", addToCartItem.getProductId());
      }
      if (useSku) {
        responseMap.put("skuId", addToCartItem.getSkuId());
      }
    } catch (AddToCartException e) {
      if (e.getCause() instanceof RequiredAttributeNotProvidedException) {
        responseMap.put("error", "allOptionsRequired");
      } else if (e.getCause() instanceof ProductOptionValidationException) {
        ProductOptionValidationException exception =
            (ProductOptionValidationException) e.getCause();
        responseMap.put("error", "productOptionValidationError");
        responseMap.put("errorCode", exception.getErrorCode());
        responseMap.put("errorMessage", exception.getMessage());
        // blMessages.getMessage(exception.get, lfocale))
      } else if (e.getCause() instanceof InventoryUnavailableException) {
        responseMap.put("error", "inventoryUnavailable");
      } else {
        throw e;
      }
    }

    return responseMap;
  }