use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductDefinitionFacadeImpl method saveProductDefinition.
@Override
public Long saveProductDefinition(MerchantStore store, PersistableProductDefinition product, Language language) {
Product target = null;
if (product.getId() != null && product.getId().longValue() > 0) {
target = productService.getById(product.getId());
} else {
target = new Product();
}
try {
target = persistableProductDefinitionMapper.merge(product, target, store, language);
if (target.getId() != null && target.getId() > 0) {
productService.update(target);
} else {
productService.create(target);
product.setId(target.getId());
}
return target.getId();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProduct.
@Override
public ReadableProduct getProduct(MerchantStore store, String sku, Language language) throws Exception {
Product product = productService.getByCode(sku, 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 getProductByCode.
@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) {
Product product = productService.getByCode(uniqueCode, language);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
try {
populator.populate(product, readableProduct, product.getMerchantStore(), language);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Product with code [" + uniqueCode + "] cannot be converted", e);
}
return readableProduct;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductPrice.
@Override
public ReadableProductPrice getProductPrice(Long id, ProductPriceRequest priceRequest, MerchantStore store, Language language) {
Validate.notNull(id, "Product id cannot be null");
Validate.notNull(priceRequest, "Product price request cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
try {
Product model = productService.findOne(id, store);
// TODO check if null
List<Long> attrinutesIds = priceRequest.getOptions().stream().map(p -> p.getId()).collect(Collectors.toList());
List<ProductAttribute> attributes = productAttributeService.getByAttributeIds(store, model, attrinutesIds);
for (ProductAttribute attribute : attributes) {
if (attribute.getProduct().getId().longValue() != id.longValue()) {
// throw unauthorized
throw new OperationNotAllowedException("Attribute with id [" + attribute.getId() + "] is not attached to product id [" + id + "]");
}
}
FinalPrice price;
price = pricingService.calculateProductPrice(model, attributes);
ReadableProductPrice readablePrice = new ReadableProductPrice();
ReadableFinalPricePopulator populator = new ReadableFinalPricePopulator();
populator.setPricingService(pricingService);
return populator.populate(price, readablePrice, store, language);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while getting product price", e);
}
}
use of com.salesmanager.core.model.catalog.product.Product 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;
}
Aggregations