@RequestMapping(value = "/viewCart.htm", params = "addPromo", method = RequestMethod.POST) public String addPromoCode( @ModelAttribute(value = "cartSummary") CartSummary cartSummary, ModelMap model, HttpServletRequest request) throws PricingException { Order currentCartOrder = retrieveCartOrder(request, model); if (cartSummary.getPromoCode() != null) { OfferCode code = offerService.lookupOfferCodeByCode(cartSummary.getPromoCode()); if (code != null) { try { currentCartOrder = cartService.addOfferCode(currentCartOrder, code, true); } catch (OfferMaxUseExceededException e) { model.addAttribute("error", "Promotion Max Uses Exceeded"); } currentCartOrder = updateFulfillmentGroups(cartSummary, currentCartOrder); } else { model.addAttribute("promoError", "Invalid promo code entered."); } } cartSummary.setPromoCode(null); model.addAttribute("currentCartOrder", currentCartOrder); model.addAttribute("cartSummary", cartSummary); return cartView; }
@RequestMapping( value = "/viewCart.htm", params = "removePromoFromCart", method = {RequestMethod.GET, RequestMethod.POST}) public String removePromoCode( @RequestParam String orderOfferCode, @ModelAttribute CartSummary cartSummary, ModelMap model, HttpServletRequest request) { Order currentCartOrder = retrieveCartOrder(request, model); try { currentCartOrder = cartService.removeOfferCode( currentCartOrder, offerService.lookupOfferCodeByCode(orderOfferCode), true); } catch (PricingException e) { model.addAttribute("error", "remove"); LOG.error( "An error occurred while removing a promo from the cart: (" + orderOfferCode + ")", e); } cartSummary.setOrderDiscounts(currentCartOrder.getTotalAdjustmentsValue().getAmount()); return "redirect:/basket/viewCart.htm"; }