categoryVirtualFetchPlans.add(new SpecificFetchMode(CatalogCategoryVirtual_.assets.getName()));
}
@RequestMapping(value = FoUrls.STORE_SEARCH_URL, method = RequestMethod.GET)
public ModelAndView search(final HttpServletRequest request, final Model model, @Valid SearchForm searchForm) throws Exception {
ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request), FoUrls.STORE_SEARCH.getVelocityPage());
final RequestData requestData = requestUtil.getRequestData(request);
final Locale locale = requestData.getLocale();
if (StringUtils.isEmpty(searchForm.getText())
&& searchForm.getPage() == 0) {
return displaySearch(request, model);
}
String url = requestUtil.getCurrentRequestUrl(request);
String sessionKeyPagedListHolder = "Search_Store_PagedListHolder_" + request.getSession().getId();
String sessionKeyFacet = "Search_Store_Facet_" + request.getSession().getId();
int page = searchForm.getPage() - 1;
String mode = request.getParameter(Constants.PAGE_VIEW_MODE);
String cities = request.getParameter("cities");
String countries = request.getParameter("countries");
List<String> cityList = new ArrayList<String>();
if (StringUtils.isEmpty(cities)) {
cityList = null;
} else{
String[] arr = cities.split(",");
cityList = Arrays.asList(arr);
}
List<String> countryList = new ArrayList<String>();
if (StringUtils.isEmpty(countries)) {
countryList = null;
} else{
String[] arr = countries.split(",");
countryList = Arrays.asList(arr);
}
String sortBy = searchForm.getSortBy();
String order = searchForm.getOrder();
try {
PagedListHolder<SearchStoreItemViewBean> storesViewBeanPagedListHolder;
if(searchForm.getPage() == 0){
StoreResponseBean storeResponseBean = null;
List<String> facetFields = Arrays.asList(StoreResponseBean.STORE_DEFAULT_FACET_FIELD,StoreResponseBean.STORE_SECOND_FACET_FIELD);
storeResponseBean = storeSolrService.searchStore(StoreResponseBean.STORE_DEFAULT_SEARCH_FIELD, searchForm.getText(), facetFields, cityList,countryList);
StoreResponseBean storeResponBeanNonFilter = storeSolrService.searchStore(StoreResponseBean.STORE_DEFAULT_SEARCH_FIELD, searchForm.getText(), facetFields);
storesViewBeanPagedListHolder = initList(request, sessionKeyPagedListHolder, storeResponseBean, new PagedListHolder<SearchStoreItemViewBean>(), searchForm);
// FACETS
List<SearchFacetViewBean> facets = frontofficeViewBeanFactory.buildListViewBeanStoreSearchFacet(requestData, storeResponBeanNonFilter);
modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
request.getSession().setAttribute(sessionKeyFacet, facets);
} else {
storesViewBeanPagedListHolder = (PagedListHolder<SearchStoreItemViewBean>) request.getSession().getAttribute(sessionKeyPagedListHolder);
// FACETS
List<SearchFacetViewBean> facets = (List<SearchFacetViewBean>) request.getSession().getAttribute(sessionKeyFacet);
modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
}
int pageCurrent = storesViewBeanPagedListHolder.getPage();
if (pageCurrent < page) {
for (int i = pageCurrent; i < page; i++) {
storesViewBeanPagedListHolder.nextPage();
}
} else if (pageCurrent > page) {
for (int i = page; i < pageCurrent; i++) {
storesViewBeanPagedListHolder.previousPage();
}
}
modelAndView.addObject(Constants.PAGINATION_PAGE_URL, url);
modelAndView.addObject(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, storesViewBeanPagedListHolder);
modelAndView.addObject(Constants.SEARCH_TEXT, searchForm.getText());
modelAndView.addObject(Constants.PAGINATION_PAGE_SIZE, storesViewBeanPagedListHolder.getPageSize());
modelAndView.addObject(Constants.PAGINATION_SORT_BY, sortBy);
modelAndView.addObject(Constants.PAGINATION_ORDER, order);
modelAndView.addObject(Constants.STORE_CITY_PARAMETER, cities);
modelAndView.addObject(Constants.STORE_COUNTRY_PARAMETER, countries);
} catch (Exception e) {
logger.error("SOLR Error", e);
return displaySearch(request, model);
}
loadRecentProducts(request, requestData, model, new FetchPlan(categoryVirtualFetchPlans), new FetchPlan(productMarketingFetchPlans), new FetchPlan(productSkuFetchPlans));
final Cart currentCart = requestData.getCart();
final CartViewBean cartViewBean = frontofficeViewBeanFactory.buildViewBeanCart(requestUtil.getRequestData(request), currentCart);
modelAndView.addObject(ModelConstants.CART_VIEW_BEAN, cartViewBean);
overrideDefaultSeoPageTitleAndMainContentTitle(request, modelAndView, FoUrls.STORE_SEARCH.getKey());
// BREADCRUMB
BreadcrumbViewBean breadcrumbViewBean = new BreadcrumbViewBean();