use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductBySeUrl.
@Override
public ReadableProduct getProductBySeUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
Product product = productService.getBySeUrl(store, friendlyUrl, LocaleUtils.getLocale(language));
if (product == null) {
return null;
}
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, store, language);
return readableProduct;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method relatedItems.
@Override
public List<ReadableProduct> relatedItems(MerchantStore store, Product product, Language language) throws Exception {
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
List<ProductRelationship> relatedItems = productRelationshipService.getByType(store, product, ProductRelationshipType.RELATED_ITEM);
if (relatedItems != null && relatedItems.size() > 0) {
List<ReadableProduct> items = new ArrayList<ReadableProduct>();
for (ProductRelationship relationship : relatedItems) {
Product relatedProduct = relationship.getRelatedProduct();
ReadableProduct proxyProduct = populator.populate(relatedProduct, new ReadableProduct(), store, language);
items.add(proxyProduct);
}
return items;
}
return null;
}
use of com.salesmanager.core.model.catalog.product.Product 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.core.model.catalog.product.Product 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.core.model.catalog.product.Product 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;
}
Aggregations