use of com.salesmanager.shop.model.order.PersistableOrderProduct in project shopizer by shopizer-ecommerce.
the class PersistableOrderPopulator method populate.
@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "productService must be set");
Validate.notNull(digitalProductService, "digitalProductService must be set");
Validate.notNull(productAttributeService, "productAttributeService must be set");
Validate.notNull(customerService, "customerService must be set");
Validate.notNull(countryService, "countryService must be set");
Validate.notNull(zoneService, "zoneService must be set");
Validate.notNull(currencyService, "currencyService must be set");
try {
Map<String, Country> countriesMap = countryService.getCountriesMap(language);
Map<String, Zone> zonesMap = zoneService.getZones(language);
/**
* customer *
*/
PersistableCustomer customer = source.getCustomer();
if (customer != null) {
if (customer.getId() != null && customer.getId() > 0) {
Customer modelCustomer = customerService.getById(customer.getId());
if (modelCustomer == null) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists");
}
if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
}
target.setCustomerId(modelCustomer.getId());
target.setBilling(modelCustomer.getBilling());
target.setDelivery(modelCustomer.getDelivery());
target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
}
}
target.setLocale(LocaleUtils.getLocale(store));
CreditCard creditCard = source.getCreditCard();
if (creditCard != null) {
String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
creditCard.setCcNumber(maskedNumber);
target.setCreditCard(creditCard);
}
Currency currency = null;
try {
currency = currencyService.getByCode(source.getCurrency());
} catch (Exception e) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
if (currency == null) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
target.setCurrency(currency);
target.setDatePurchased(source.getDatePurchased());
// target.setCurrency(store.getCurrency());
target.setCurrencyValue(new BigDecimal(0));
target.setMerchant(store);
target.setStatus(source.getOrderStatus());
target.setPaymentModuleCode(source.getPaymentModule());
target.setPaymentType(source.getPaymentType());
target.setShippingModuleCode(source.getShippingModule());
target.setCustomerAgreement(source.isCustomerAgreed());
target.setConfirmedAddress(source.isConfirmedAddress());
if (source.getPreviousOrderStatus() != null) {
List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
for (OrderStatus status : orderStatusList) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(status);
statusHistory.setOrder(target);
target.getOrderHistory().add(statusHistory);
}
}
if (!StringUtils.isBlank(source.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(null);
statusHistory.setOrder(target);
statusHistory.setComments(source.getComments());
target.getOrderHistory().add(statusHistory);
}
List<PersistableOrderProduct> products = source.getOrderProductItems();
if (CollectionUtils.isEmpty(products)) {
throw new ConversionException("Requires at least 1 PersistableOrderProduct");
}
com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
orderProductPopulator.setDigitalProductService(digitalProductService);
for (PersistableOrderProduct orderProduct : products) {
OrderProduct modelOrderProduct = new OrderProduct();
orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
target.getOrderProducts().add(modelOrderProduct);
}
List<OrderTotal> orderTotals = source.getTotals();
if (CollectionUtils.isNotEmpty(orderTotals)) {
for (OrderTotal total : orderTotals) {
com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
totalModel.setModule(total.getModule());
totalModel.setOrder(target);
totalModel.setOrderTotalCode(total.getCode());
totalModel.setTitle(total.getTitle());
totalModel.setValue(total.getValue());
target.getOrderTotal().add(totalModel);
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.shop.model.order.PersistableOrderProduct in project shopizer by shopizer-ecommerce.
the class ShoppingCartItemPopulator method populate.
@Override
public ShoppingCartItem populate(PersistableOrderProduct source, /**
* TODO: Fix, target not used possible future bug ! *
*/
ShoppingCartItem target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "Requires to set productService");
Validate.notNull(productAttributeService, "Requires to set productAttributeService");
Validate.notNull(shoppingCartService, "Requires to set shoppingCartService");
Product product = productService.getById(source.getProduct().getId());
if (source.getAttributes() != null) {
for (com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute attr : source.getAttributes()) {
ProductAttribute attribute = productAttributeService.getById(attr.getId());
if (attribute == null) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is null");
}
if (attribute.getProduct().getId().longValue() != source.getProduct().getId().longValue()) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is not assigned to Product id " + source.getProduct().getId());
}
product.getAttributes().add(attribute);
}
}
try {
return shoppingCartService.populateShoppingCartItem(product);
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.shop.model.order.PersistableOrderProduct in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method calculateOrderTotal.
@Override
public OrderTotalSummary calculateOrderTotal(MerchantStore store, com.salesmanager.shop.model.order.v0.PersistableOrder order, Language language) throws Exception {
List<PersistableOrderProduct> orderProducts = order.getOrderProductItems();
ShoppingCartItemPopulator populator = new ShoppingCartItemPopulator();
populator.setProductAttributeService(productAttributeService);
populator.setProductService(productService);
populator.setShoppingCartService(shoppingCartService);
List<ShoppingCartItem> items = new ArrayList<ShoppingCartItem>();
for (PersistableOrderProduct orderProduct : orderProducts) {
ShoppingCartItem item = populator.populate(orderProduct, new ShoppingCartItem(), store, language);
items.add(item);
}
Customer customer = customer(order.getCustomer(), store, language);
OrderTotalSummary summary = this.calculateOrderTotal(store, customer, order, language);
return summary;
}
use of com.salesmanager.shop.model.order.PersistableOrderProduct in project shopizer by shopizer-ecommerce.
the class PersistableOrderProductPopulator method populate.
/**
* Converts a ShoppingCartItem carried in the ShoppingCart to an OrderProduct
* that will be saved in the system
*/
@Override
public OrderProduct populate(PersistableOrderProduct source, OrderProduct target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "productService must be set");
Validate.notNull(digitalProductService, "digitalProductService must be set");
Validate.notNull(productAttributeService, "productAttributeService must be set");
try {
Product modelProduct = productService.getById(source.getProduct().getId());
if (modelProduct == null) {
throw new ConversionException("Cannot get product with id (productId) " + source.getProduct().getId());
}
if (modelProduct.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid product id " + source.getProduct().getId());
}
DigitalProduct digitalProduct = digitalProductService.getByProduct(store, modelProduct);
if (digitalProduct != null) {
OrderProductDownload orderProductDownload = new OrderProductDownload();
orderProductDownload.setOrderProductFilename(digitalProduct.getProductFileName());
orderProductDownload.setOrderProduct(target);
orderProductDownload.setDownloadCount(0);
orderProductDownload.setMaxdays(ApplicationConstants.MAX_DOWNLOAD_DAYS);
target.getDownloads().add(orderProductDownload);
}
target.setOneTimeCharge(source.getPrice());
target.setProductName(source.getProduct().getDescription().getName());
target.setProductQuantity(source.getOrderedQuantity());
target.setSku(source.getProduct().getSku());
OrderProductPrice orderProductPrice = new OrderProductPrice();
orderProductPrice.setDefaultPrice(true);
orderProductPrice.setProductPrice(source.getPrice());
orderProductPrice.setOrderProduct(target);
Set<OrderProductPrice> prices = new HashSet<OrderProductPrice>();
prices.add(orderProductPrice);
/**
* DO NOT SUPPORT MUTIPLE PRICES *
*/
/* //Other prices
List<FinalPrice> otherPrices = finalPrice.getAdditionalPrices();
if(otherPrices!=null) {
for(FinalPrice otherPrice : otherPrices) {
OrderProductPrice other = orderProductPrice(otherPrice);
other.setOrderProduct(target);
prices.add(other);
}
}*/
target.setPrices(prices);
// OrderProductAttribute
List<ProductAttribute> attributeItems = source.getAttributes();
if (!CollectionUtils.isEmpty(attributeItems)) {
Set<OrderProductAttribute> attributes = new HashSet<OrderProductAttribute>();
for (ProductAttribute attribute : attributeItems) {
OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
orderProductAttribute.setOrderProduct(target);
Long id = attribute.getId();
com.salesmanager.core.model.catalog.product.attribute.ProductAttribute attr = productAttributeService.getById(id);
if (attr == null) {
throw new ConversionException("Attribute id " + id + " does not exists");
}
if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Attribute id " + id + " invalid for this store");
}
orderProductAttribute.setProductAttributeIsFree(attr.getProductAttributeIsFree());
orderProductAttribute.setProductAttributeName(attr.getProductOption().getDescriptionsSettoList().get(0).getName());
orderProductAttribute.setProductAttributeValueName(attr.getProductOptionValue().getDescriptionsSettoList().get(0).getName());
orderProductAttribute.setProductAttributePrice(attr.getProductAttributePrice());
orderProductAttribute.setProductAttributeWeight(attr.getProductAttributeWeight());
orderProductAttribute.setProductOptionId(attr.getProductOption().getId());
orderProductAttribute.setProductOptionValueId(attr.getProductOptionValue().getId());
attributes.add(orderProductAttribute);
}
target.setOrderAttributes(attributes);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
Aggregations