HttpServletRequest request,
HttpServletResponse response)
throws Throwable {
ContentBean contentBean = getContentBean(request);
Site site = contentBean.getContentSessionBean().getSiteDomain().getSite();
ShoppingCartActionForm form = (ShoppingCartActionForm) actionForm;
String couponCode = form.getCouponCode();
createEmptySecureTemplateInfo(request);
ActionMessages messages = new ActionMessages();
ShoppingCart shoppingCart = ShoppingCart.getSessionInstance(request, true);
if (Format.isNullOrEmpty(couponCode)) {
this.initAddressInfo(form, site, shoppingCart, request, messages);
this.initCartInfo(form, site, shoppingCart, request, messages);
messages.add("couponCode", new ActionMessage("content.error.string.required"));
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
Coupon coupon = CouponDAO.loadByCouponCode(site.getSiteId(), couponCode);
if (coupon == null) {
this.initAddressInfo(form, site, shoppingCart, request, messages);
this.initCartInfo(form, site, shoppingCart, request, messages);
messages.add("couponCode", new ActionMessage("content.error.coupon.invalid"));
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
try {
shoppingCart.addCoupon(coupon, contentBean);
}
catch (CouponNotApplicableException e1) {
this.initAddressInfo(form, site, shoppingCart, request, messages);
this.initCartInfo(form, site, shoppingCart, request, messages);
messages.add("couponCode", new ActionMessage("content.error.coupon.notApplicable"));
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
catch (CouponUserNotRegisterException e2) {
this.initAddressInfo(form, site, shoppingCart, request, messages);
this.initCartInfo(form, site, shoppingCart, request, messages);
messages.add("couponCode", new ActionMessage("content.error.coupon.notRegister"));
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
form.setCouponCode("");
this.initCartInfo(form, site, shoppingCart, request, messages);
if (shoppingCart.isShippingQuoteLock()) {
this.saveOpenOrder(shoppingCart, Constants.ORDER_STEP_QUOTE_REVIEWPURCHASE);
}