Search in sources :

Example 46 with Category

use of com.salesmanager.core.model.catalog.category.Category 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;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 47 with Category

use of com.salesmanager.core.model.catalog.category.Category 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;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) ArrayList(java.util.ArrayList) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 48 with Category

use of com.salesmanager.core.model.catalog.category.Category in project shopizer by shopizer-ecommerce.

the class StoreFilter method getCategories.

/**
 * @param store
 * @param language
 * @return
 * @throws Exception
 */
// private Map<String, List<Category>> getCategories(MerchantStore store,
// Language language)
// throws Exception {
private Map<String, List<ReadableCategory>> getCategories(MerchantStore store, Language language) throws Exception {
    // Map<String, List<Category>> objects = new ConcurrentHashMap<String,
    // List<Category>>();
    Map<String, List<ReadableCategory>> objects = new ConcurrentHashMap<String, List<ReadableCategory>>();
    /**
     * returns categories with required depth, 0 = root category, 1 = root +
     * 1 layer child ...)
     */
    List<Category> categories = categoryService.getListByDepth(store, 0, language);
    ReadableCategoryPopulator readableCategoryPopulator = new ReadableCategoryPopulator();
    Map<String, ReadableCategory> subs = new ConcurrentHashMap<String, ReadableCategory>();
    if (categories != null && categories.size() > 0) {
        // create a Map<String,List<Content>
        for (Category category : categories) {
            if (category.isVisible()) {
                // if(category.getDepth().intValue()==0) {
                // ReadableCategory readableCategory = new
                // ReadableCategory();
                // readableCategoryPopulator.populate(category,
                // readableCategory, store, language);
                Set<CategoryDescription> descriptions = category.getDescriptions();
                for (CategoryDescription description : descriptions) {
                    Language lang = description.getLanguage();
                    ReadableCategory readableCategory = new ReadableCategory();
                    readableCategoryPopulator.populate(category, readableCategory, store, language);
                    String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CATEGORIES_CACHE_KEY).append("-").append(lang.getCode()).toString();
                    if (category.getDepth().intValue() == 0) {
                        // List<Category> cacheCategories = null;
                        List<ReadableCategory> cacheCategories = null;
                        if (objects == null || objects.size() == 0) {
                            // objects = new HashMap<String,
                            // List<Category>>();
                            objects = new HashMap<String, List<ReadableCategory>>();
                        }
                        if (!objects.containsKey(key)) {
                            // cacheCategories = new ArrayList<Category>();
                            cacheCategories = new ArrayList<ReadableCategory>();
                            objects.put(key, cacheCategories);
                        } else {
                            cacheCategories = objects.get(key.toString());
                            if (cacheCategories == null) {
                                LOGGER.error("Cannot find categories key in cache " + key);
                                continue;
                            }
                        }
                        // cacheCategories.add(category);
                        cacheCategories.add(readableCategory);
                    } else {
                        subs.put(lang.getCode(), readableCategory);
                    }
                }
            }
        }
    }
    return objects;
}
Also used : ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) Language(com.salesmanager.core.model.reference.language.Language) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Example 49 with Category

use of com.salesmanager.core.model.catalog.category.Category 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);
    }
}
Also used : ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) Language(com.salesmanager.core.model.reference.language.Language) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) Content(com.salesmanager.core.model.content.Content) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 50 with Category

use of com.salesmanager.core.model.catalog.category.Category 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

Category (com.salesmanager.core.model.catalog.category.Category)52 Language (com.salesmanager.core.model.reference.language.Language)30 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)28 ArrayList (java.util.ArrayList)28 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)26 Product (com.salesmanager.core.model.catalog.product.Product)20 ServiceException (com.salesmanager.core.business.exception.ServiceException)15 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)14 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)14 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)13 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)13 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 ReadableCategoryPopulator (com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)12 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)12 Validate (org.apache.commons.lang3.Validate)12 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)11 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)11 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)11