Skip to Content
0
Former Member
Oct 11, 2014 at 09:16 AM

Voucher Price

312 Views

Hi all,

I ve written the below method for Voucher redemption in Controller.In PriceCalculation Strategy am using price from another model for calculation.When add to ccart,update cart etc takes that price and works well.But while calling the below method,after redemption when it refreshes the cart page my price is not getting reflected.It gives the old Product price.Should I set the calculated price manually somewhere?Any help is appreciated in this regard.

@RequestMapping(value = "/redeem", method = RequestMethod.POST) public String redeemVoucher(final Model model,finalVoucherForm form, final BindingResult bindingResult, final HttpServletRequest request, final RedirectAttributes redirectModel) throws CMSItemNotFoundException, VoucherOperationException {

     String voucherCode= form.getVoucherCode();
     LOG.info("Voucher code Obtained is"+voucherCode);
     boolean isVoucherValid;
     
     final CartData cartData = cartFacade.getSessionCart();

     
     
     
     if(voucherCode!=null){
         
     /*    boolean isValidForUser=voucherModelService.isReservable(getVoucherModel(voucherCode), voucherCode,userService.getCurrentUser());
         if(isValidForUser){
             LOG.info("Is this Voucher for a User true"+isValidForUser);
 
         }else{
             LOG.info("Is this Voucher for a User no"+isValidForUser);

         }*/
         if (cartData.getEntries() != null && !cartData.getEntries().isEmpty())
         {
             for (final OrderEntryData entry : cartData.getEntries())
             {
                 
                 LOG.info("Cart entry in controller"+entry.getBasePrice().getFormattedValue());

             }
         }
         isVoucherValid = voucherFacade.checkVoucherCode(voucherCode);
         
         if(isVoucherValid){
             try{
                 LOG.info("Voucher Code is Valid");
                 voucherFacade.applyVoucher(voucherCode);
                 GlobalMessages
                 .addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "promotion.code.success");
                 return REDIRECT_PREFIX + "/cart";    
             }catch(VoucherOperationException voucher){
                 GlobalMessages.addErrorMessage(redirectModel, "error.processing.voucher");
             }
             
         }else{
             LOG.info("Voucher Code is InValid");
             GlobalMessages.addFlashMessage(redirectModel,GlobalMessages.ERROR_MESSAGES_HOLDER, "promotion.code.not.valid");
             return REDIRECT_PREFIX + "/cart";

         }
         
 
     
 }

     prepareDataForPage(model);
     return ControllerConstants.Views.Pages.Cart.CartPage;

}

Thanks Kalpana