use of com.salesmanager.shop.model.shop.BreadcrumbItem in project shopizer by shopizer-ecommerce.
the class LandingController method displayLanding.
@RequestMapping(value = { Constants.SHOP_URI + "/home.html", Constants.SHOP_URI + "/", Constants.SHOP_URI }, method = RequestMethod.GET)
public String displayLanding(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
request.setAttribute(Constants.LINK_CODE, HOME_LINK_CODE);
Content content = contentService.getByCode(LANDING_PAGE, store, language);
/**
* Rebuild breadcrumb *
*/
BreadcrumbItem item = new BreadcrumbItem();
item.setItemType(BreadcrumbItemType.HOME);
item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
item.setUrl(Constants.HOME_URL);
Breadcrumb breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
items.add(item);
breadCrumb.setBreadCrumbs(items);
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
if (content != null) {
ContentDescription description = content.getDescription();
model.addAttribute("page", description);
PageInformation pageInformation = new PageInformation();
pageInformation.setPageTitle(description.getName());
pageInformation.setPageDescription(description.getMetatagDescription());
pageInformation.setPageKeywords(description.getMetatagKeywords());
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
}
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
// featured items
List<ProductRelationship> relationships = productRelationshipService.getByType(store, ProductRelationshipType.FEATURED_ITEM, language);
List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>();
Date today = new Date();
for (ProductRelationship relationship : relationships) {
Product product = relationship.getRelatedProduct();
if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language);
featuredItems.add(proxyProduct);
}
}
String tmpl = store.getStoreTemplate();
if (StringUtils.isBlank(tmpl)) {
tmpl = "generic";
}
model.addAttribute("featuredItems", featuredItems);
/**
* template *
*/
StringBuilder template = new StringBuilder().append("landing.").append(tmpl);
return template.toString();
}
use of com.salesmanager.shop.model.shop.BreadcrumbItem in project shopizer by shopizer-ecommerce.
the class StoreFilter method getDefaultBreadcrumbItem.
private BreadcrumbItem getDefaultBreadcrumbItem(Language language, Locale locale) {
// set home page item
BreadcrumbItem item = new BreadcrumbItem();
item.setItemType(BreadcrumbItemType.HOME);
item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
item.setUrl(Constants.HOME_URL);
return item;
}
use of com.salesmanager.shop.model.shop.BreadcrumbItem 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.shop.model.shop.BreadcrumbItem 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.shop.model.shop.BreadcrumbItem 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);
}
}
Aggregations