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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations