Search in sources :

Example 6 with ReadableProductList

use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.

the class ProductFacadeImpl method getProductListsByCriterias.

@Override
public ReadableProductList getProductListsByCriterias(MerchantStore store, Language language, ProductCriteria criterias) throws Exception {
    Validate.notNull(criterias, "ProductCriteria must be set for this product");
    /**
     * This is for category *
     */
    if (CollectionUtils.isNotEmpty(criterias.getCategoryIds())) {
        if (criterias.getCategoryIds().size() == 1) {
            com.salesmanager.core.model.catalog.category.Category category = categoryService.getById(criterias.getCategoryIds().get(0));
            if (category != null) {
                String lineage = new StringBuilder().append(category.getLineage()).toString();
                List<com.salesmanager.core.model.catalog.category.Category> categories = categoryService.getListByLineage(store, lineage);
                List<Long> ids = new ArrayList<Long>();
                if (categories != null && categories.size() > 0) {
                    for (com.salesmanager.core.model.catalog.category.Category c : categories) {
                        ids.add(c.getId());
                    }
                }
                ids.add(category.getId());
                criterias.setCategoryIds(ids);
            }
        }
    }
    Page<Product> modelProductList = productService.listByStore(store, language, criterias, criterias.getStartPage(), criterias.getMaxCount());
    List<Product> products = modelProductList.getContent();
    List<Product> prds = products.stream().sorted(Comparator.comparing(Product::getSortOrder)).collect(Collectors.toList());
    products = prds;
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    // productList.setTotalPages(products.getTotalCount());
    productList.setRecordsTotal(modelProductList.getTotalElements());
    productList.setNumber(productList.getProducts().size());
    productList.setTotalPages(modelProductList.getTotalPages());
    return productList;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ArrayList(java.util.ArrayList) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator)

Example 7 with ReadableProductList

use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.

the class ProductFacadeV2Impl method getProductListsByCriterias.

@Override
public ReadableProductList getProductListsByCriterias(MerchantStore store, Language language, ProductCriteria criterias) throws Exception {
    // same as v1
    Validate.notNull(criterias, "ProductCriteria must be set for this product");
    /**
     * This is for category *
     */
    if (CollectionUtils.isNotEmpty(criterias.getCategoryIds())) {
        if (criterias.getCategoryIds().size() == 1) {
            com.salesmanager.core.model.catalog.category.Category category = categoryService.getById(criterias.getCategoryIds().get(0));
            if (category != null) {
                String lineage = new StringBuilder().append(category.getLineage()).toString();
                List<com.salesmanager.core.model.catalog.category.Category> categories = categoryService.getListByLineage(store, lineage);
                List<Long> ids = new ArrayList<Long>();
                if (categories != null && categories.size() > 0) {
                    for (com.salesmanager.core.model.catalog.category.Category c : categories) {
                        ids.add(c.getId());
                    }
                }
                ids.add(category.getId());
                criterias.setCategoryIds(ids);
            }
        }
    }
    Page<Product> modelProductList = productService.listByStore(store, language, criterias, criterias.getStartPage(), criterias.getMaxCount());
    List<Product> products = modelProductList.getContent();
    List<Product> prds = products.stream().sorted(Comparator.comparing(Product::getSortOrder)).collect(Collectors.toList());
    products = prds;
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    // productList.setTotalPages(products.getTotalCount());
    productList.setRecordsTotal(modelProductList.getTotalElements());
    productList.setNumber(productList.getProducts().size());
    productList.setTotalPages(modelProductList.getTotalPages());
    return productList;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator)

Example 8 with ReadableProductList

use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.

the class ProductItemsFacadeImpl method listItemsByIds.

@Override
public ReadableProductList listItemsByIds(MerchantStore store, Language language, List<Long> ids, int startCount, int maxCount) throws Exception {
    if (CollectionUtils.isEmpty(ids)) {
        return new ReadableProductList();
    }
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setMaxCount(maxCount);
    productCriteria.setStartIndex(startCount);
    productCriteria.setProductIds(ids);
    com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(store, language, productCriteria);
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products.getProducts()) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    productList.setNumber(Math.toIntExact(products.getTotalCount()));
    productList.setRecordsTotal(new Long(products.getTotalCount()));
    return productList;
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 9 with ReadableProductList

use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.

the class ProductItemsFacadeImpl method listItemsByGroup.

@Override
public ReadableProductList listItemsByGroup(String group, MerchantStore store, Language language) throws Exception {
    // get product group
    List<ProductRelationship> groups = productRelationshipService.getByGroup(store, group, language);
    if (group != null) {
        List<Long> ids = new ArrayList<Long>();
        for (ProductRelationship relationship : groups) {
            Product product = relationship.getRelatedProduct();
            ids.add(product.getId());
        }
        ReadableProductList list = listItemsByIds(store, language, ids, 0, 0);
        List<ReadableProduct> prds = list.getProducts().stream().sorted(Comparator.comparing(ReadableProduct::getSortOrder)).collect(Collectors.toList());
        list.setProducts(prds);
        // no paging
        list.setTotalPages(1);
        return list;
    }
    return null;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 10 with ReadableProductList

use of com.salesmanager.shop.model.catalog.product.ReadableProductList in project shopizer by shopizer-ecommerce.

the class ProductItemsFacadeImpl method listItemsByManufacturer.

@Override
public ReadableProductList listItemsByManufacturer(MerchantStore store, Language language, Long manufacturerId, int startCount, int maxCount) throws Exception {
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setMaxCount(maxCount);
    productCriteria.setStartIndex(startCount);
    productCriteria.setManufacturerId(manufacturerId);
    com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(store, language, productCriteria);
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products.getProducts()) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    productList.setTotalPages(Math.toIntExact(products.getTotalCount()));
    return productList;
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Aggregations

ReadableProductList (com.salesmanager.shop.model.catalog.product.ReadableProductList)10 Product (com.salesmanager.core.model.catalog.product.Product)9 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)6 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)5 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ProductCriteria (com.salesmanager.core.model.catalog.product.ProductCriteria)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3 ProductRelationship (com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)2 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 Category (com.salesmanager.core.model.catalog.category.Category)1 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)1 QueryFilter (com.salesmanager.shop.store.model.filter.QueryFilter)1 Date (java.util.Date)1