public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws ServletException {
HttpSession session = request.getSession();
UserAttributes userAttrs = (UserAttributes)session.getAttribute(UserAttributes.NAME);
if(userAttrs==null){
userAttrs = new UserAttributes();
userAttrs.setStoreId(storeResolver.getStoreId(
request.getRequestURL().toString()));
userAttrs.setLanguageId(DefaultSettings.LANGUAGE_ID);
userAttrs.setCurrencyCode(currencyService.getDefaultCurrencyCode());
session.setAttribute(UserAttributes.NAME, userAttrs);
}
String langCode = request.getParameter(this.languageParam);
if (langCode != null) {
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
if (localeResolver == null) {
throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
}
Locale locale = StringUtils.parseLocaleString(langCode);
localeResolver.setLocale(request, response, locale);
Language language = languageService.getByCode(langCode);
if(language!=null){
userAttrs.setLanguageId(language.getId());
locale = language.getLocale();
}else{
logger.warn("Language id not found for code: {}", langCode);
}
}
String currencyCode = request.getParameter(this.currencyParam);
if(currencyCode != null){
if(!currencyService.has(currencyCode)){
currencyCode = settingService.getConfig(
userAttrs.getStoreId(), SettingKey.CFG_CURRENCY);
}
userAttrs.setCurrencyCode(currencyCode);
}
return true;
}