Search in sources :

Example 6 with Breadcrumb

use of com.salesmanager.shop.model.shop.Breadcrumb 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();
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb) BigDecimal(java.math.BigDecimal) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Aggregations

Breadcrumb (com.salesmanager.shop.model.shop.Breadcrumb)6 ArrayList (java.util.ArrayList)5 Category (com.salesmanager.core.model.catalog.category.Category)4 Language (com.salesmanager.core.model.reference.language.Language)4 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)4 BreadcrumbItem (com.salesmanager.shop.model.shop.BreadcrumbItem)4 Product (com.salesmanager.core.model.catalog.product.Product)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 PageInformation (com.salesmanager.shop.model.shop.PageInformation)3 Content (com.salesmanager.core.model.content.Content)2 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)2 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)2 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)1 ProductRelationship (com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)1 ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)1 ContentDescription (com.salesmanager.core.model.content.ContentDescription)1 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)1 ReadableProductReview (com.salesmanager.shop.model.catalog.product.ReadableProductReview)1