use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCategoryController method handleRequest.
@Override
@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView();
if (request.getParameterMap().containsKey("facetField")) {
// If we receive a facetField parameter, we need to convert the field to the
// product search criteria expected format. This is used in multi-facet selection. We
// will send a redirect to the appropriate URL to maintain canonical URLs
String fieldName = request.getParameter("facetField");
List<String> activeFieldFilters = new ArrayList<String>();
Map<String, String[]> parameters = new HashMap<String, String[]>(request.getParameterMap());
for (Iterator<Entry<String, String[]>> iter = parameters.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, String[]> entry = iter.next();
String key = entry.getKey();
if (key.startsWith(fieldName + "-")) {
activeFieldFilters.add(key.substring(key.indexOf('-') + 1));
iter.remove();
}
}
parameters.remove(SearchCriteria.PAGE_NUMBER);
parameters.put(fieldName, activeFieldFilters.toArray(new String[activeFieldFilters.size()]));
parameters.remove("facetField");
String newUrl = ProcessorUtils.getUrl(request.getRequestURL().toString(), parameters);
model.setViewName("redirect:" + newUrl);
} else {
// Else, if we received a GET to the category URL (either the user clicked this link or we redirected
// from the POST method, we can actually process the results
Category category = (Category) request.getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME);
assert (category != null);
SearchCriteria searchCriteria = facetService.buildSearchCriteria(request);
SearchResult result = getSearchService().findSearchResults(searchCriteria);
facetService.setActiveFacetResults(result.getFacets(), request);
model.addObject(CATEGORY_ATTRIBUTE_NAME, category);
model.addObject(PRODUCTS_ATTRIBUTE_NAME, result.getProducts());
model.addObject(SKUS_ATTRIBUTE_NAME, result.getSkus());
model.addObject(FACETS_ATTRIBUTE_NAME, result.getFacets());
model.addObject(PRODUCT_SEARCH_RESULT_ATTRIBUTE_NAME, result);
if (request.getParameterMap().containsKey("q")) {
model.addObject(ORIGINAL_QUERY_ATTRIBUTE_NAME, request.getParameter("q"));
}
model.addObject("BLC_PAGE_TYPE", "category");
if (result.getProducts() != null) {
model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, new HashSet<Product>(result.getProducts()));
}
if (result.getSkus() != null) {
model.addObject(ALL_SKUS_ATTRIBUTE_NAME, new HashSet<Sku>(result.getSkus()));
}
addDeepLink(model, deepLinkService, category);
String templatePath = null;
// Use the categories custom template if available
if (StringUtils.isNotBlank(category.getDisplayTemplate())) {
templatePath = category.getDisplayTemplate();
} else {
// Otherwise, use the controller default.
templatePath = getDefaultCategoryView();
}
// Allow extension managers to override.
ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, category);
if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
templatePath = erh.getResult();
}
model.setViewName(templatePath);
}
return model;
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class CategoryDaoImpl method findCategoryByURI.
@Override
public Category findCategoryByURI(String uri) {
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(uri, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
return (Category) holder.getResult();
}
}
Query query;
query = em.createNamedQuery("BC_READ_CATEGORY_OUTGOING_URL");
query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
query.setParameter("url", uri);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
@SuppressWarnings("unchecked") List<Category> results = query.getResultList();
if (results != null && !results.isEmpty()) {
return results.get(0);
} else {
return null;
}
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class CategoryDaoImpl method readCategoryByName.
@Override
@Deprecated
public Category readCategoryByName(String categoryName) {
Query query = em.createNamedQuery("BC_READ_CATEGORY_BY_NAME");
query.setParameter("categoryName", categoryName);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return (Category) query.getSingleResult();
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class SeoDefaultPropertyServiceImpl method getProductDescriptionPattern.
@Override
public String getProductDescriptionPattern(Product product) {
try {
Category category = product.getCategory();
String pattern = category.getProductDescriptionPatternOverride();
if (StringUtils.isEmpty(pattern)) {
pattern = env.getProperty("seo.product.description.pattern");
}
return pattern;
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
return "";
}
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class CatalogServiceImpl method findCategoryByURI.
@Override
public Category findCategoryByURI(String uri) {
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(createCatalogContextDTO(), uri, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
return (Category) holder.getResult();
}
}
return findOriginalCategoryByURI(uri);
}
Aggregations