use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method saveProduct.
@Override
public PersistableProduct saveProduct(MerchantStore store, PersistableProduct product, Language language) {
String manufacturer = Manufacturer.DEFAULT_MANUFACTURER;
if (product.getProductSpecifications() != null) {
manufacturer = product.getProductSpecifications().getManufacturer();
} else {
ProductSpecification specifications = new ProductSpecification();
specifications.setManufacturer(manufacturer);
}
Product target = null;
if (product.getId() != null && product.getId().longValue() > 0) {
target = productService.getById(product.getId());
} else {
target = new Product();
}
try {
persistableProductPopulator.populate(product, target, store, language);
if (target.getId() != null && target.getId() > 0) {
productService.update(target);
} else {
productService.create(target);
product.setId(target.getId());
}
return product;
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProduct.
@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
Product product = productService.findOne(id, store);
if (product == null) {
throw new ResourceNotFoundException("Product [" + id + "] not found");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
}
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
try {
readableProduct = populator.populate(product, readableProduct, store, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
}
return readableProduct;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method updateProductPrice.
@Override
public ReadableProduct updateProductPrice(ReadableProduct product, ProductPriceEntity price, Language language) throws Exception {
Product persistable = productService.getById(product.getId());
if (persistable == null) {
throw new Exception("product is null for id " + product.getId());
}
java.util.Set<ProductAvailability> availabilities = persistable.getAvailabilities();
for (ProductAvailability availability : availabilities) {
ProductPrice productPrice = availability.defaultPrice();
productPrice.setProductPriceAmount(price.getOriginalPrice());
if (price.isDiscounted()) {
productPrice.setProductPriceSpecialAmount(price.getDiscountedPrice());
if (!StringUtils.isBlank(price.getDiscountStartDate())) {
Date startDate = DateUtil.getDate(price.getDiscountStartDate());
productPrice.setProductPriceSpecialStartDate(startDate);
}
if (!StringUtils.isBlank(price.getDiscountEndDate())) {
Date endDate = DateUtil.getDate(price.getDiscountEndDate());
productPrice.setProductPriceSpecialEndDate(endDate);
}
}
}
productService.update(persistable);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(persistable, readableProduct, persistable.getMerchantStore(), language);
return readableProduct;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProductByCode.
@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) throws Exception {
Product product = productService.getByCode(uniqueCode, language);
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, product.getMerchantStore(), language);
return readableProduct;
}
use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method update.
@Override
public void update(Long productId, LightPersistableProduct product, MerchantStore merchant, Language language) {
// Get product
Product modified = productService.findOne(productId, merchant);
// Update product with minimal set
modified.setAvailable(product.isAvailable());
for (ProductAvailability availability : modified.getAvailabilities()) {
availability.setProductQuantity(product.getQuantity());
if (!StringUtils.isBlank(product.getPrice())) {
// set default price
for (ProductPrice price : availability.getPrices()) {
if (price.isDefaultPrice()) {
try {
price.setProductPriceAmount(pricingService.getAmount(product.getPrice()));
} catch (ServiceException e) {
throw new ServiceRuntimeException("Invalid product price format");
}
}
}
}
}
try {
productService.save(modified);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot update product ", e);
}
}
Aggregations