use of com.salesmanager.shop.model.shop.Breadcrumb in project shopizer by shopizer-ecommerce.
the class ShoppingCategoryController method displayCategory.
@SuppressWarnings("unchecked")
private String displayCategory(final String friendlyUrl, final String ref, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
// set ref as request attribute
String encoded = SanitizeUtils.getSafeRequestParamString(ref);
if (!encoded.equals(ref)) {
// possible xss
throw new Exception("Wrong input parameter [" + ref + "]");
}
request.setAttribute("ref", encoded);
// get category
Category category = categoryService.getBySeUrl(store, friendlyUrl);
Language language = (Language) request.getAttribute("LANGUAGE");
if (category == null) {
LOGGER.error("No category found for friendlyUrl " + friendlyUrl);
// redirect on page not found
return PageBuilderUtils.build404(store);
}
if (!category.isVisible()) {
return PageBuilderUtils.buildHomePage(store);
}
ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), store, language);
Breadcrumb breadCrumb = breadcrumbsUtils.buildCategoryBreadcrumb(categoryProxy, store, language, request.getContextPath());
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageDescription(categoryProxy.getDescription().getMetaDescription());
pageInformation.setPageKeywords(categoryProxy.getDescription().getKeyWords());
pageInformation.setPageTitle(categoryProxy.getDescription().getTitle());
pageInformation.setPageUrl(categoryProxy.getDescription().getFriendlyUrl());
// ** retrieves category id drill down**//
String lineage = new StringBuilder().append(category.getLineage()).append(Constants.CATEGORY_LINEAGE_DELIMITER).toString();
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
List<Category> categs = categoryService.getListByLineage(store, lineage);
categs.add(category);
StringBuilder subCategoriesCacheKey = new StringBuilder();
subCategoriesCacheKey.append(store.getId()).append("_").append(category.getId()).append("_").append(Constants.SUBCATEGORIES_CACHE_KEY).append("-").append(language.getCode());
StringBuilder subCategoriesMissed = new StringBuilder();
subCategoriesMissed.append(subCategoriesCacheKey.toString()).append(Constants.MISSED_CACHE_KEY);
List<BigDecimal> prices = new ArrayList<BigDecimal>();
List<ReadableCategory> subCategories = null;
Map<Long, Long> countProductsByCategories = null;
if (store.isUseCache()) {
// get from the cache
subCategories = (List<ReadableCategory>) cache.getFromCache(subCategoriesCacheKey.toString());
if (subCategories == null) {
// get from missed cache
// Boolean missedContent = (Boolean)cache.getFromCache(subCategoriesMissed.toString());
// if(missedContent==null) {
countProductsByCategories = getProductsByCategory(store, categs);
subCategories = getSubCategories(store, category, countProductsByCategories, language, locale);
if (subCategories != null) {
cache.putInCache(subCategories, subCategoriesCacheKey.toString());
} else {
// cache.putInCache(new Boolean(true), subCategoriesCacheKey.toString());
}
// }
}
} else {
countProductsByCategories = getProductsByCategory(store, categs);
subCategories = getSubCategories(store, category, countProductsByCategories, language, locale);
}
// Parent category
ReadableCategory parentProxy = null;
if (category.getParent() != null) {
Category parent = categoryService.getById(category.getParent().getId(), store.getId());
parentProxy = populator.populate(parent, new ReadableCategory(), store, language);
}
// ** List of manufacturers **//
List<ReadableManufacturer> manufacturerList = getManufacturersByProductAndCategory(store, category, categs, language);
model.addAttribute("manufacturers", manufacturerList);
model.addAttribute("parent", parentProxy);
model.addAttribute("category", categoryProxy);
model.addAttribute("subCategories", subCategories);
if (parentProxy != null) {
request.setAttribute(Constants.LINK_CODE, parentProxy.getDescription().getFriendlyUrl());
}
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Category.category).append(".").append(store.getStoreTemplate());
return template.toString();
}
Aggregations