use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.
the class ReadableOrderProductMapper method merge.
@Override
public ReadableOrderProduct merge(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) {
Validate.notNull(source, "OrderProduct cannot be null");
Validate.notNull(target, "ReadableOrderProduct cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
target.setId(source.getId());
target.setOrderedQuantity(source.getProductQuantity());
try {
target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
} catch (Exception e) {
throw new ConversionRuntimeException("Cannot convert price", e);
}
target.setProductName(source.getProductName());
target.setSku(source.getSku());
// subtotal = price * quantity
BigDecimal subTotal = source.getOneTimeCharge();
subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
try {
String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
target.setSubTotal(subTotalPrice);
} catch (Exception e) {
throw new ConversionRuntimeException("Cannot format price", e);
}
if (source.getOrderAttributes() != null) {
List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
for (OrderProductAttribute attr : source.getOrderAttributes()) {
ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
try {
String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
readableAttribute.setAttributePrice(price);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Cannot format price", e);
}
readableAttribute.setAttributeName(attr.getProductAttributeName());
readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
attributes.add(readableAttribute);
}
target.setAttributes(attributes);
}
String productSku = source.getSku();
if (!StringUtils.isBlank(productSku)) {
Product product = productService.getByCode(productSku, language);
if (product != null) {
// TODO autowired
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProduct productProxy;
try {
productProxy = populator.populate(product, new ReadableProduct(), store, language);
target.setProduct(productProxy);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Cannot convert product", e);
}
Set<ProductImage> images = product.getImages();
ProductImage defaultImage = null;
if (images != null) {
for (ProductImage image : images) {
if (defaultImage == null) {
defaultImage = image;
}
if (image.isDefaultImage()) {
defaultImage = image;
}
}
}
if (defaultImage != null) {
target.setImage(defaultImage.getProductImage());
}
}
}
return target;
}
use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.
the class ReadableProductAttributeMapper method merge.
@Override
public ReadableProductAttributeEntity merge(ProductAttribute source, ReadableProductAttributeEntity destination, MerchantStore store, Language language) {
ReadableProductAttributeEntity attr = new ReadableProductAttributeEntity();
if (destination != null) {
attr = destination;
}
try {
// attribute of the option
attr.setId(source.getId());
if (source.getProductAttributePrice() != null && source.getProductAttributePrice().doubleValue() > 0) {
String formatedPrice;
formatedPrice = pricingService.getDisplayAmount(source.getProductAttributePrice(), store);
attr.setProductAttributePrice(formatedPrice);
attr.setProductAttributeUnformattedPrice(pricingService.getStringAmount(source.getProductAttributePrice(), store));
}
attr.setProductAttributeWeight(source.getAttributeAdditionalWeight());
attr.setAttributeDisplayOnly(source.getAttributeDisplayOnly());
attr.setAttributeDefault(source.getAttributeDefault());
if (!StringUtils.isBlank(source.getAttributeSortOrder())) {
attr.setSortOrder(Integer.parseInt(source.getAttributeSortOrder()));
}
if (source.getProductOption() != null) {
ReadableProductOptionEntity option = readableProductOptionMapper.convert(source.getProductOption(), store, language);
attr.setOption(option);
}
if (source.getProductOptionValue() != null) {
ReadableProductOptionValueEntity optionValue = readableProductOptionValueMapper.convert(source.getProductOptionValue(), store, language);
attr.setOptionValue(optionValue);
}
} catch (Exception e) {
throw new ConversionRuntimeException("Exception while product attribute conversion", e);
}
return attr;
}
use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.
the class PersistableCatalogCategoryEntryMapper method merge.
@Override
public CatalogCategoryEntry merge(PersistableCatalogCategoryEntry source, CatalogCategoryEntry destination, MerchantStore store, Language language) {
Validate.notNull(source, "CatalogEntry must not be null");
Validate.notNull(store, "MerchantStore must not be null");
Validate.notNull(source.getProductCode(), "ProductCode must not be null");
Validate.notNull(source.getCategoryCode(), "CategoryCode must not be null");
Validate.notNull(source.getCatalog(), "Catalog must not be null");
if (destination == null) {
destination = new CatalogCategoryEntry();
}
destination.setId(source.getId());
destination.setVisible(source.isVisible());
try {
String catalog = source.getCatalog();
Catalog catalogModel = catalogFacade.getCatalog(catalog, store);
if (catalogModel == null) {
throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getCatalog() + "] not found");
}
destination.setCatalog(catalogModel);
/* Product productModel = productFacade.getProduct(source.getProductCode(), store);
if(productModel == null) {
throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getProductCode() + "] not found");
}*/
// destination.setProduct(productModel);
Category categoryModel = categoryFacade.getByCode(source.getCategoryCode(), store);
if (categoryModel == null) {
throw new ConversionRuntimeException("Error while converting CatalogEntry category [" + source.getCategoryCode() + "] not found");
}
destination.setCategory(categoryModel);
} catch (Exception e) {
throw new ConversionRuntimeException("Error while converting CatalogEntry", e);
}
return destination;
}
use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.
the class PersistableProductVariationMapper method merge.
@Override
public ProductVariation merge(PersistableProductVariation source, ProductVariation destination, MerchantStore store, Language language) {
Validate.notNull(destination, "ProductVariation cannot be null");
destination.setId(source.getId());
destination.setCode(source.getCode());
destination.setMerchantStore(store);
ProductOption option = productOptionService.getById(store, source.getOption());
if (option == null) {
throw new ConversionRuntimeException("ProductOption [" + source.getOption() + "] does not exists");
}
destination.setProductOption(option);
ProductOptionValue optionValue = productOptionValueService.getById(store, source.getOptionValue());
if (optionValue == null) {
throw new ConversionRuntimeException("ProductOptionValue [" + source.getOptionValue() + "] does not exists");
}
destination.setProductOptionValue(optionValue);
return destination;
}
use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method update.
@Override
public PersistableCustomer update(PersistableCustomer customer, MerchantStore store) {
if (customer.getId() == null || customer.getId() == 0) {
throw new ServiceRuntimeException("Can't update a customer with null id");
}
Customer cust = customerService.getById(customer.getId());
try {
customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
String password = customer.getPassword();
if (StringUtils.isBlank(password)) {
password = new String(UUID.generateRandomBytes());
customer.setPassword(password);
}
saveCustomer(cust);
customer.setId(cust.getId());
return customer;
}
Aggregations