use of com.salesmanager.core.model.catalog.category.Category in project shopizer by shopizer-ecommerce.
the class BreadcrumbsUtils method buildCategoryBreadcrumb.
public Breadcrumb buildCategoryBreadcrumb(ReadableCategory categoryClicked, MerchantStore store, Language language, String contextPath) throws Exception {
/**
* Rebuild breadcrumb *
*/
BreadcrumbItem home = new BreadcrumbItem();
home.setItemType(BreadcrumbItemType.HOME);
home.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, LocaleUtils.getLocale(language)));
home.setUrl(filePathUtils.buildStoreUri(store, contextPath) + Constants.SHOP_URI);
Breadcrumb breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
items.add(home);
List<String> categoryIds = parseCategoryLineage(categoryClicked.getLineage());
List<Long> ids = new ArrayList<Long>();
for (String c : categoryIds) {
ids.add(Long.parseLong(c));
}
ids.add(categoryClicked.getId());
List<Category> categories = categoryService.listByIds(store, ids, language);
// category path - use lineage
for (Category c : categories) {
BreadcrumbItem categoryBreadcrump = new BreadcrumbItem();
categoryBreadcrump.setItemType(BreadcrumbItemType.CATEGORY);
categoryBreadcrump.setLabel(c.getDescription().getName());
categoryBreadcrump.setUrl(filePathUtils.buildCategoryUrl(store, contextPath, c.getDescription().getSeUrl()));
items.add(categoryBreadcrump);
}
breadCrumb.setUrlRefContent(buildBreadCrumb(ids));
breadCrumb.setBreadCrumbs(items);
breadCrumb.setItemType(BreadcrumbItemType.CATEGORY);
return breadCrumb;
}
use of com.salesmanager.core.model.catalog.category.Category in project shopizer by shopizer-ecommerce.
the class BreadcrumbsUtils method buildProductBreadcrumb.
public Breadcrumb buildProductBreadcrumb(String refContent, ReadableProduct productClicked, MerchantStore store, Language language, String contextPath) throws Exception {
/**
* Rebuild breadcrumb *
*/
BreadcrumbItem home = new BreadcrumbItem();
home.setItemType(BreadcrumbItemType.HOME);
home.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, LocaleUtils.getLocale(language)));
home.setUrl(filePathUtils.buildStoreUri(store, contextPath) + Constants.SHOP_URI);
Breadcrumb breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
items.add(home);
if (!StringUtils.isBlank(refContent)) {
List<String> categoryIds = parseBreadCrumb(refContent);
List<Long> ids = new ArrayList<Long>();
for (String c : categoryIds) {
ids.add(Long.parseLong(c));
}
List<Category> categories = categoryService.listByIds(store, ids, language);
// category path - use lineage
for (Category c : categories) {
BreadcrumbItem categoryBreadcrump = new BreadcrumbItem();
categoryBreadcrump.setItemType(BreadcrumbItemType.CATEGORY);
categoryBreadcrump.setLabel(c.getDescription().getName());
categoryBreadcrump.setUrl(filePathUtils.buildCategoryUrl(store, contextPath, c.getDescription().getSeUrl()));
items.add(categoryBreadcrump);
}
breadCrumb.setUrlRefContent(buildBreadCrumb(ids));
}
BreadcrumbItem productBreadcrump = new BreadcrumbItem();
productBreadcrump.setItemType(BreadcrumbItemType.PRODUCT);
productBreadcrump.setLabel(productClicked.getDescription().getName());
productBreadcrump.setUrl(filePathUtils.buildProductUrl(store, contextPath, productClicked.getDescription().getFriendlyUrl()));
items.add(productBreadcrump);
breadCrumb.setBreadCrumbs(items);
breadCrumb.setItemType(BreadcrumbItemType.CATEGORY);
return breadCrumb;
}
use of com.salesmanager.core.model.catalog.category.Category in project shopizer by shopizer-ecommerce.
the class StoreFilter method getCategories.
/**
* @param store
* @param language
* @return
* @throws Exception
*/
// private Map<String, List<Category>> getCategories(MerchantStore store,
// Language language)
// throws Exception {
private Map<String, List<ReadableCategory>> getCategories(MerchantStore store, Language language) throws Exception {
// Map<String, List<Category>> objects = new ConcurrentHashMap<String,
// List<Category>>();
Map<String, List<ReadableCategory>> objects = new ConcurrentHashMap<String, List<ReadableCategory>>();
/**
* returns categories with required depth, 0 = root category, 1 = root +
* 1 layer child ...)
*/
List<Category> categories = categoryService.getListByDepth(store, 0, language);
ReadableCategoryPopulator readableCategoryPopulator = new ReadableCategoryPopulator();
Map<String, ReadableCategory> subs = new ConcurrentHashMap<String, ReadableCategory>();
if (categories != null && categories.size() > 0) {
// create a Map<String,List<Content>
for (Category category : categories) {
if (category.isVisible()) {
// if(category.getDepth().intValue()==0) {
// ReadableCategory readableCategory = new
// ReadableCategory();
// readableCategoryPopulator.populate(category,
// readableCategory, store, language);
Set<CategoryDescription> descriptions = category.getDescriptions();
for (CategoryDescription description : descriptions) {
Language lang = description.getLanguage();
ReadableCategory readableCategory = new ReadableCategory();
readableCategoryPopulator.populate(category, readableCategory, store, language);
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CATEGORIES_CACHE_KEY).append("-").append(lang.getCode()).toString();
if (category.getDepth().intValue() == 0) {
// List<Category> cacheCategories = null;
List<ReadableCategory> cacheCategories = null;
if (objects == null || objects.size() == 0) {
// objects = new HashMap<String,
// List<Category>>();
objects = new HashMap<String, List<ReadableCategory>>();
}
if (!objects.containsKey(key)) {
// cacheCategories = new ArrayList<Category>();
cacheCategories = new ArrayList<ReadableCategory>();
objects.put(key, cacheCategories);
} else {
cacheCategories = objects.get(key.toString());
if (cacheCategories == null) {
LOGGER.error("Cannot find categories key in cache " + key);
continue;
}
}
// cacheCategories.add(category);
cacheCategories.add(readableCategory);
} else {
subs.put(lang.getCode(), readableCategory);
}
}
}
}
}
return objects;
}
use of com.salesmanager.core.model.catalog.category.Category in project shopizer by shopizer-ecommerce.
the class StoreFilter method setBreadcrumb.
private void setBreadcrumb(HttpServletRequest request, Locale locale) {
try {
// breadcrumb
Breadcrumb breadCrumb = (Breadcrumb) request.getSession().getAttribute(Constants.BREADCRUMB);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
if (breadCrumb == null) {
breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
BreadcrumbItem item = this.getDefaultBreadcrumbItem(language, locale);
breadCrumb.getBreadCrumbs().add(item);
} else {
// check language
if (language.getCode().equals(breadCrumb.getLanguage().getCode())) {
// rebuild using the appropriate language
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
for (BreadcrumbItem item : breadCrumb.getBreadCrumbs()) {
if (item.getItemType().name().equals(BreadcrumbItemType.HOME)) {
BreadcrumbItem homeItem = this.getDefaultBreadcrumbItem(language, locale);
homeItem.setItemType(BreadcrumbItemType.HOME);
homeItem.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
homeItem.setUrl(Constants.HOME_URL);
items.add(homeItem);
} else if (item.getItemType().name().equals(BreadcrumbItemType.PRODUCT)) {
Product product = productService.getProductForLocale(item.getId(), language, locale);
if (product != null) {
BreadcrumbItem productItem = new BreadcrumbItem();
productItem.setId(product.getId());
productItem.setItemType(BreadcrumbItemType.PRODUCT);
productItem.setLabel(product.getProductDescription().getName());
productItem.setUrl(product.getProductDescription().getSeUrl());
items.add(productItem);
}
} else if (item.getItemType().name().equals(BreadcrumbItemType.CATEGORY)) {
Category category = categoryService.getOneByLanguage(item.getId(), language);
if (category != null) {
BreadcrumbItem categoryItem = new BreadcrumbItem();
categoryItem.setId(category.getId());
categoryItem.setItemType(BreadcrumbItemType.CATEGORY);
categoryItem.setLabel(category.getDescription().getName());
categoryItem.setUrl(category.getDescription().getSeUrl());
items.add(categoryItem);
}
} else if (item.getItemType().name().equals(BreadcrumbItemType.PAGE)) {
Content content = contentService.getByLanguage(item.getId(), language);
if (content != null) {
BreadcrumbItem contentItem = new BreadcrumbItem();
contentItem.setId(content.getId());
contentItem.setItemType(BreadcrumbItemType.PAGE);
contentItem.setLabel(content.getDescription().getName());
contentItem.setUrl(content.getDescription().getSeUrl());
items.add(contentItem);
}
}
}
breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
breadCrumb.setBreadCrumbs(items);
}
}
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
} catch (Exception e) {
LOGGER.error("Error while building breadcrumbs", e);
}
}
use of com.salesmanager.core.model.catalog.category.Category 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