Search in sources :

Example 1 with ReadableCategoryPopulator

use of com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator in project shopizer by shopizer-ecommerce.

the class ShoppingCategoryController method getSubCategories.

private List<ReadableCategory> getSubCategories(MerchantStore store, Category category, Map<Long, Long> productCount, Language language, Locale locale) throws Exception {
    // sub categories
    List<Category> subCategories = categoryService.listByParent(category, language);
    ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
    List<ReadableCategory> subCategoryProxies = new ArrayList<ReadableCategory>();
    for (Category sub : subCategories) {
        ReadableCategory cProxy = populator.populate(sub, new ReadableCategory(), store, language);
        if (productCount != null) {
            Long total = productCount.get(cProxy.getId());
            if (total != null) {
                cProxy.setProductCount(total.intValue());
            }
        }
        subCategoryProxies.add(cProxy);
    }
    return subCategoryProxies;
}
Also used : ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ArrayList(java.util.ArrayList) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Example 2 with ReadableCategoryPopulator

use of com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator in project shopizer by shopizer-ecommerce.

the class SearchFacadeImpl method convertCategoryToReadableCategory.

private ReadableCategory convertCategoryToReadableCategory(MerchantStore merchantStore, Language language, Map<String, Long> productCategoryCount, Category category) {
    ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
    try {
        ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), merchantStore, language);
        Long total = productCategoryCount.get(categoryProxy.getCode());
        if (total != null) {
            categoryProxy.setProductCount(total.intValue());
        }
        return categoryProxy;
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 3 with ReadableCategoryPopulator

use of com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator in project shopizer by shopizer-ecommerce.

the class CategoryFacadeImpl method getCategoryByFriendlyUrl.

@Override
public ReadableCategory getCategoryByFriendlyUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
    Validate.notNull(friendlyUrl, "Category search friendly URL must not be null");
    ReadableCategoryPopulator categoryPopulator = new ReadableCategoryPopulator();
    ReadableCategory readableCategory = new ReadableCategory();
    Category category = categoryService.getBySeUrl(store, friendlyUrl);
    categoryPopulator.populate(category, readableCategory, store, language);
    return readableCategory;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Example 4 with ReadableCategoryPopulator

use of com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator in project shopizer by shopizer-ecommerce.

the class CategoryFacadeImpl method getByCode.

@Override
public ReadableCategory getByCode(MerchantStore store, String code, Language language) throws Exception {
    Validate.notNull(code, "category code must not be null");
    ReadableCategoryPopulator categoryPopulator = new ReadableCategoryPopulator();
    ReadableCategory readableCategory = new ReadableCategory();
    Category category = categoryService.getByCode(store, code);
    categoryPopulator.populate(category, readableCategory, store, language);
    return readableCategory;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)

Example 5 with ReadableCategoryPopulator

use of com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator 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)

Aggregations

ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)7 ReadableCategoryPopulator (com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator)7 Category (com.salesmanager.core.model.catalog.category.Category)6 Language (com.salesmanager.core.model.reference.language.Language)3 ArrayList (java.util.ArrayList)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 CategoryDescription (com.salesmanager.core.model.catalog.category.CategoryDescription)1 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)1 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)1 Breadcrumb (com.salesmanager.shop.model.shop.Breadcrumb)1 PageInformation (com.salesmanager.shop.model.shop.PageInformation)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 BigDecimal (java.math.BigDecimal)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1