Search in sources :

Example 16 with Category

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;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ModelAndView(org.springframework.web.servlet.ModelAndView) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) SearchCriteria(org.broadleafcommerce.core.search.domain.SearchCriteria) Entry(java.util.Map.Entry) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 17 with Category

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;
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 18 with Category

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();
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query)

Example 19 with Category

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 "";
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 20 with Category

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);
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

Category (org.broadleafcommerce.core.catalog.domain.Category)49 Product (org.broadleafcommerce.core.catalog.domain.Product)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)13 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)8 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)7 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)7 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)7 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 ArrayList (java.util.ArrayList)6 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)6 CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)6 Money (org.broadleafcommerce.common.money.Money)5 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Customer (org.broadleafcommerce.profile.core.domain.Customer)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)4 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 Calendar (java.util.Calendar)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3