cancel
Showing results for 
Search instead for 
Did you mean: 

Voucher Price

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Kalpana,

perhaps try and MOVE the line 'final CartData cartData = cartFacade.getSessionCart();' from its current position (line 5) to immediately BEFORE the 'prepareDataForPage(model);' method. If you do this, you will of course have to also move the lines 20 to 28; or simply comment them out. Good luck and please let me know how you get on.

Cheers Danny

Former Member
0 Kudos

Hi Danny,

Thats just for logging.Voucher facade takes cart from session and calculates.Can you tell me one thing.For calculation, since my price comes from another model(external system and not in Product Model) am overriding FindPricingCal;culationStrategy basePrice() method and so for all my calculations that price is used and not from price factory.Now for discount what should be the change in the method findDiscountValues()?Where is the Voucher taking price for calculation?That is the reason am getting a different price after discount calculation.

Thanks Kalpana