public Cart getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) httpServletRequest.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); Member member = principal != null ? (Member) this.memberDao.find(principal.getId()) : null; if (member != null) { Cart cart = member.getCart(); if (cart != null) { if (!cart.hasExpired()) { if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) { cart.setUpdateDate(new Date()); this.cartDao.merge(cart); } return cart; } this.cartDao.remove(cart); } } else { String cartIdString = CookieUtils.getCookie(httpServletRequest, "cartId"); String cartKeyString = CookieUtils.getCookie(httpServletRequest, "cartKey"); if ((StringUtils.isNotEmpty(cartIdString)) && (StringUtils.isNumeric(cartIdString)) && (StringUtils.isNotEmpty(cartKeyString))) { Cart cart = (Cart) this.cartDao.find(Long.valueOf(cartIdString)); if ((cart != null) && (cart.getMember() == null) && (StringUtils.equals(cart.getKey(), cartKeyString))) { if (!cart.hasExpired()) { if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) { cart.setUpdateDate(new Date()); this.cartDao.merge(cart); } return cart; } this.cartDao.remove(cart); } } } } return null; }