use of com.salesmanager.core.model.content.ContentDescription 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.core.model.content.ContentDescription in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContentPagesNames.
private Map<String, List<ContentDescription>> getContentPagesNames(MerchantStore store, Language language) throws Exception {
Map<String, List<ContentDescription>> contents = new ConcurrentHashMap<String, List<ContentDescription>>();
// Get boxes and sections from the database
List<ContentType> contentTypes = new ArrayList<ContentType>();
contentTypes.add(ContentType.PAGE);
List<ContentDescription> contentPages = contentService.listNameByType(contentTypes, store, language);
if (contentPages != null && contentPages.size() > 0) {
// create a Map<String,List<Content>
for (ContentDescription content : contentPages) {
Language lang = language;
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_PAGE_CACHE_KEY).append("-").append(lang.getCode()).toString();
List<ContentDescription> contentList = null;
if (contents == null || contents.size() == 0) {
contents = new HashMap<String, List<ContentDescription>>();
}
if (!contents.containsKey(key)) {
contentList = new ArrayList<ContentDescription>();
contents.put(key, contentList);
} else {
// get from key
contentList = contents.get(key);
if (contentList == null) {
LOGGER.error("Cannot find content key in cache " + key);
continue;
}
}
contentList.add(content);
}
}
return contents;
}
use of com.salesmanager.core.model.content.ContentDescription in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContent.
private Map<String, List<Content>> getContent(MerchantStore store, Language language) throws Exception {
Map<String, List<Content>> contents = new ConcurrentHashMap<String, List<Content>>();
// Get boxes and sections from the database
List<ContentType> contentTypes = new ArrayList<ContentType>();
contentTypes.add(ContentType.BOX);
contentTypes.add(ContentType.SECTION);
List<Content> contentPages = contentService.listByType(contentTypes, store, language);
if (contentPages != null && contentPages.size() > 0) {
// create a Map<String,List<Content>
for (Content content : contentPages) {
if (content.isVisible()) {
List<ContentDescription> descriptions = content.getDescriptions();
for (ContentDescription contentDescription : descriptions) {
Language lang = contentDescription.getLanguage();
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_CACHE_KEY).append("-").append(lang.getCode()).toString();
List<Content> contentList = null;
if (contents == null || contents.size() == 0) {
contents = new HashMap<String, List<Content>>();
}
if (!contents.containsKey(key)) {
contentList = new ArrayList<Content>();
contents.put(key, contentList);
} else {
// get from key
contentList = contents.get(key);
if (contentList == null) {
LOGGER.error("Cannot find content key in cache " + key);
continue;
}
}
contentList.add(content);
}
}
}
}
return contents;
}
use of com.salesmanager.core.model.content.ContentDescription in project shopizer by shopizer-ecommerce.
the class StoreFilter method preHandle.
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.setCharacterEncoding("UTF-8");
/**
* if url contains /services exit from here !
*/
if (request.getRequestURL().toString().toLowerCase().contains(SERVICES_URL_PATTERN) || request.getRequestURL().toString().toLowerCase().contains(REFERENCE_URL_PATTERN)) {
return true;
}
try {
/**
* merchant store *
*/
MerchantStore store = (MerchantStore) request.getSession().getAttribute(Constants.MERCHANT_STORE);
String storeCode = request.getParameter(STORE_REQUEST_PARAMETER);
// remove link set from controllers for declaring active - inactive
// links
request.removeAttribute(Constants.LINK_CODE);
if (!StringUtils.isBlank(storeCode)) {
if (store != null) {
if (!store.getCode().equals(storeCode)) {
store = setMerchantStoreInSession(request, storeCode);
}
} else {
// when url sm-shop/shop is being loaded for first time
// store is null
store = setMerchantStoreInSession(request, storeCode);
}
}
if (store == null) {
store = setMerchantStoreInSession(request, MerchantStore.DEFAULT_STORE);
}
if (StringUtils.isBlank(store.getStoreTemplate())) {
store.setStoreTemplate(Constants.DEFAULT_TEMPLATE);
}
request.setAttribute(Constants.MERCHANT_STORE, store);
/*
//remote ip address
String remoteAddress = "";
try {
if (request != null) {
remoteAddress = request.getHeader("X-Forwarded-For");
if (remoteAddress == null || "".equals(remoteAddress)) {
remoteAddress = request.getRemoteAddr();
}
}
remoteAddress = remoteAddress != null && remoteAddress.contains(",") ? remoteAddress.split(",")[0] : remoteAddress;
LOGGER.info("remote ip addres {}", remoteAddress);
} catch (Exception e) {
LOGGER.error("Error while getting user remote address");
}
*/
String ipAddress = GeoLocationUtils.getClientIpAddress(request);
UserContext userContext = UserContext.create();
userContext.setIpAddress(ipAddress);
/**
* customer *
*/
Customer customer = (Customer) request.getSession().getAttribute(Constants.CUSTOMER);
if (customer != null) {
if (customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
request.getSession().removeAttribute(Constants.CUSTOMER);
}
if (!customer.isAnonymous()) {
if (!request.isUserInRole("AUTH_CUSTOMER")) {
request.removeAttribute(Constants.CUSTOMER);
}
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
request.setAttribute(Constants.CUSTOMER, customer);
}
if (customer == null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerService.getByNick(auth.getName());
if (customer != null) {
request.setAttribute(Constants.CUSTOMER, customer);
}
}
}
AnonymousCustomer anonymousCustomer = (AnonymousCustomer) request.getSession().getAttribute(Constants.ANONYMOUS_CUSTOMER);
if (anonymousCustomer == null) {
Address address = null;
try {
if (!StringUtils.isBlank(ipAddress)) {
com.salesmanager.core.model.common.Address geoAddress = customerService.getCustomerAddress(store, ipAddress);
if (geoAddress != null) {
address = new Address();
address.setCountry(geoAddress.getCountry());
address.setCity(geoAddress.getCity());
address.setZone(geoAddress.getZone());
/**
* no postal code *
*/
// address.setPostalCode(geoAddress.getPostalCode());
}
}
} catch (Exception ce) {
LOGGER.error("Cannot get geo ip component ", ce);
}
if (address == null) {
address = new Address();
address.setCountry(store.getCountry().getIsoCode());
if (store.getZone() != null) {
address.setZone(store.getZone().getCode());
} else {
address.setStateProvince(store.getStorestateprovince());
}
/**
* no postal code *
*/
// address.setPostalCode(store.getStorepostalcode());
}
anonymousCustomer = new AnonymousCustomer();
anonymousCustomer.setBilling(address);
request.getSession().setAttribute(Constants.ANONYMOUS_CUSTOMER, anonymousCustomer);
} else {
request.setAttribute(Constants.ANONYMOUS_CUSTOMER, anonymousCustomer);
}
/**
* language & locale *
*/
Language language = languageUtils.getRequestLanguage(request, response);
request.setAttribute(Constants.LANGUAGE, language);
Locale locale = languageService.toLocale(language, store);
request.setAttribute(Constants.LOCALE, locale);
// Locale locale = LocaleContextHolder.getLocale();
LocaleContextHolder.setLocale(locale);
/**
* Breadcrumbs *
*/
setBreadcrumb(request, locale);
/**
* Get global objects Themes are built on a similar way displaying
* Header, Body and Footer Header and Footer are displayed on each
* page Some themes also contain side bars which may include similar
* emements
*
* Elements from Header : - CMS links - Customer - Mini shopping
* cart - Store name / logo - Top categories - Search
*
* Elements from Footer : - CMS links - Store address - Global
* payment information - Global shipping information
*/
// get from the cache first
/**
* The cache for each object contains 2 objects, a Cache and a
* Missed-Cache Get objects from the cache If not null use those
* objects If null, get entry from missed-cache If missed-cache not
* null then nothing exist If missed-cache null, add missed-cache
* entry and load from the database If objects from database not
* null store in cache
*/
/**
***** CMS Objects *******
*/
this.getContentObjects(store, language, request);
/**
***** CMS Page names *********
*/
this.getContentPageNames(store, language, request);
/**
***** Top Categories *******
*/
// this.getTopCategories(store, language, request);
this.setTopCategories(store, language, request);
/**
***** Default metatags ******
*/
/**
* Title Description Keywords
*/
PageInformation pageInformation = new PageInformation();
pageInformation.setPageTitle(store.getStorename());
pageInformation.setPageDescription(store.getStorename());
pageInformation.setPageKeywords(store.getStorename());
@SuppressWarnings("unchecked") Map<String, ContentDescription> contents = (Map<String, ContentDescription>) request.getAttribute(Constants.REQUEST_CONTENT_OBJECTS);
if (contents != null) {
// for(String key : contents.keySet()) {
// List<ContentDescription> contentsList = contents.get(key);
// for(Content content : contentsList) {
// if(key.equals(Constants.CONTENT_LANDING_PAGE)) {
// List<ContentDescription> descriptions =
// content.getDescriptions();
ContentDescription contentDescription = contents.get(Constants.CONTENT_LANDING_PAGE);
if (contentDescription != null) {
// for(ContentDescription contentDescription : descriptions)
// {
// if(contentDescription.getLanguage().getCode().equals(language.getCode()))
// {
pageInformation.setPageTitle(contentDescription.getName());
pageInformation.setPageDescription(contentDescription.getMetatagDescription());
pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
// }
}
// }
// }
// }
}
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
/**
***** Configuration objects ******
*/
/**
* SHOP configuration type Should contain - Different configuration
* flags - Google analytics - Facebook page - Twitter handle - Show
* customer login - ...
*/
this.getMerchantConfigurations(store, request);
/**
***** Shopping Cart ********
*/
String shoppingCarCode = (String) request.getSession().getAttribute(Constants.SHOPPING_CART);
if (shoppingCarCode != null) {
request.setAttribute(Constants.REQUEST_SHOPPING_CART, shoppingCarCode);
}
} catch (Exception e) {
LOGGER.error("Error in StoreFilter", e);
}
return true;
}
use of com.salesmanager.core.model.content.ContentDescription in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentBoxToContent.
private Content convertContentBoxToContent(MerchantStore store, Content model, PersistableContentBox content) throws Exception {
Content contentModel = new Content();
if (model != null) {
contentModel = model;
}
List<ContentDescription> descriptions = buildDescriptions(contentModel, content.getDescriptions());
for (ContentDescription cd : descriptions) {
cd.setContent(contentModel);
}
contentModel.setCode(content.getCode());
contentModel.setContentType(ContentType.BOX);
contentModel.setMerchantStore(store);
contentModel.setVisible(content.isVisible());
contentModel.setDescriptions(descriptions);
contentModel.setId(content.getId());
return contentModel;
}
Aggregations