Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected Cart validateOrRevertPromotion( HttpServletRequest request, Cart cart ) {
- log.trace( "validateOrRevertPromotion : enter" );
- Account account = null;
- if( SecurityContextHolder.getContext().getAuthentication().isAuthenticated() ) {
- Authentication auth = SecurityContextHolder.getContext().getAuthentication();
- if( null != auth ) {
- try {
- account = userService.authenticated( (String) auth.getPrincipal() );
- } catch( MyAccountException e ) {
- log.error( "validateOrRevertPromotion : error", e );
- return cart;
- }
- } else {
- log.trace( "validateOrRevertPromotion : user is not authenticated" );
- return cart;
- }
- }
- if( account.getGuest() ) {
- if( null == cart.getPromotion() && StringUtils.isNotBlank( cart.getPromotionCode() ) ) {
- cart = Cart.fromCartDetails( promotionUtils.populatePromotion( cart.toCartDetails() ) );
- log.trace( "validateOrRevertPromotion : guest used promotion code '" + cart.getPromotionCode() + "'" );
- }
- log.trace( "validateOrRevertPromotion : cart is for guest" );
- return cart;
- }
- try {
- User user = userService.getUser( account.getGuid() );
- if( StringUtils.isNotBlank( user.getCampaign() ) && ( user.isCampaignVerified() && !user.isCampaignRevoked() ) ) {
- log.trace( "validateOrRevertPromotion : authenticated user is part of campaign" );
- ThirdPartyCampaign campaign = userService.getCampaign( user.getCampaign() );
- if( null != campaign ) {
- cart.setPromotionCode( campaign.getPromoCode() );
- cart = Cart.fromCartDetails( promotionUtils.populatePromotion( cart.toCartDetails() ) );
- log.trace( "validateOrRevertPromotion : campaign added to cart" );
- }
- log.trace( "validateOrRevertPromotion : cart is for authenticated user with campaign" );
- return cart;
- } else {
- if( null == cart.getPromotion() && StringUtils.isNotBlank( cart.getPromotionCode() ) ) {
- cart = Cart.fromCartDetails( promotionUtils.populatePromotion( cart.toCartDetails() ) );
- log.trace( "validateOrRevertPromotion : authenticated user used promotion code '" + cart.getPromotionCode() + "'" );
- }
- log.trace( "validateOrRevertPromotion : cart is for authenticated user" );
- return cart;
- }
- } catch( MyAccountException e ) {
- log.error( "validateOrRevertPromotion : error", e );
- }
- log.trace( "validateOrRevertPromotion : exit, no promotion applied" );
- return cart;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement