use of com.salesmanager.shop.model.order.total.OrderTotal 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.total.OrderTotal in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method setOrderTotals.
private void setOrderTotals(OrderEntity order, OrderTotalSummary summary) {
List<OrderTotal> totals = new ArrayList<OrderTotal>();
List<com.salesmanager.core.model.order.OrderTotal> orderTotals = summary.getTotals();
for (com.salesmanager.core.model.order.OrderTotal t : orderTotals) {
OrderTotal total = new OrderTotal();
total.setCode(t.getOrderTotalCode());
total.setTitle(t.getTitle());
total.setValue(t.getValue());
totals.add(total);
}
order.setTotals(totals);
}
use of com.salesmanager.shop.model.order.total.OrderTotal in project shopizer by shopizer-ecommerce.
the class ShoppingCartDataPopulator method populate.
@Override
public ShoppingCartData populate(final ShoppingCart shoppingCart, final ShoppingCartData cart, final MerchantStore store, final Language language) {
Validate.notNull(shoppingCart, "Requires ShoppingCart");
Validate.notNull(language, "Requires Language not null");
int cartQuantity = 0;
cart.setCode(shoppingCart.getShoppingCartCode());
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> items = shoppingCart.getLineItems();
List<ShoppingCartItem> shoppingCartItemsList = Collections.emptyList();
try {
if (items != null) {
shoppingCartItemsList = new ArrayList<ShoppingCartItem>();
for (com.salesmanager.core.model.shoppingcart.ShoppingCartItem item : items) {
ShoppingCartItem shoppingCartItem = new ShoppingCartItem();
shoppingCartItem.setCode(cart.getCode());
shoppingCartItem.setProductCode(item.getProduct().getSku());
shoppingCartItem.setProductVirtual(item.isProductVirtual());
shoppingCartItem.setProductId(item.getProductId());
shoppingCartItem.setId(item.getId());
String itemName = item.getProduct().getProductDescription().getName();
if (!CollectionUtils.isEmpty(item.getProduct().getDescriptions())) {
for (ProductDescription productDescription : item.getProduct().getDescriptions()) {
if (language != null && language.getId().intValue() == productDescription.getLanguage().getId().intValue()) {
itemName = productDescription.getName();
break;
}
}
}
shoppingCartItem.setName(itemName);
shoppingCartItem.setPrice(pricingService.getDisplayAmount(item.getItemPrice(), store));
shoppingCartItem.setQuantity(item.getQuantity());
cartQuantity = cartQuantity + item.getQuantity();
shoppingCartItem.setProductPrice(item.getItemPrice());
shoppingCartItem.setSubTotal(pricingService.getDisplayAmount(item.getSubTotal(), store));
ProductImage image = item.getProduct().getProductImage();
if (image != null && imageUtils != null) {
String imagePath = imageUtils.buildProductImageUtils(store, item.getProduct().getSku(), image.getProductImage());
shoppingCartItem.setImage(imagePath);
}
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem> attributes = item.getAttributes();
if (attributes != null) {
List<ShoppingCartAttribute> cartAttributes = new ArrayList<ShoppingCartAttribute>();
for (com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem attribute : attributes) {
ShoppingCartAttribute cartAttribute = new ShoppingCartAttribute();
cartAttribute.setId(attribute.getId());
cartAttribute.setAttributeId(attribute.getProductAttributeId());
cartAttribute.setOptionId(attribute.getProductAttribute().getProductOption().getId());
cartAttribute.setOptionValueId(attribute.getProductAttribute().getProductOptionValue().getId());
List<ProductOptionDescription> optionDescriptions = attribute.getProductAttribute().getProductOption().getDescriptionsSettoList();
List<ProductOptionValueDescription> optionValueDescriptions = attribute.getProductAttribute().getProductOptionValue().getDescriptionsSettoList();
if (!CollectionUtils.isEmpty(optionDescriptions) && !CollectionUtils.isEmpty(optionValueDescriptions)) {
String optionName = optionDescriptions.get(0).getName();
String optionValue = optionValueDescriptions.get(0).getName();
for (ProductOptionDescription optionDescription : optionDescriptions) {
if (optionDescription.getLanguage() != null && optionDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
optionName = optionDescription.getName();
break;
}
}
for (ProductOptionValueDescription optionValueDescription : optionValueDescriptions) {
if (optionValueDescription.getLanguage() != null && optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
optionValue = optionValueDescription.getName();
break;
}
}
cartAttribute.setOptionName(optionName);
cartAttribute.setOptionValue(optionValue);
cartAttributes.add(cartAttribute);
}
}
shoppingCartItem.setShoppingCartAttributes(cartAttributes);
}
shoppingCartItemsList.add(shoppingCartItem);
}
}
if (CollectionUtils.isNotEmpty(shoppingCartItemsList)) {
cart.setShoppingCartItems(shoppingCartItemsList);
}
if (shoppingCart.getOrderId() != null) {
cart.setOrderId(shoppingCart.getOrderId());
}
OrderSummary summary = new OrderSummary();
List<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> productsList = new ArrayList<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>();
productsList.addAll(shoppingCart.getLineItems());
summary.setProducts(productsList.stream().filter(p -> p.getProduct().isAvailable()).collect(Collectors.toList()));
OrderTotalSummary orderSummary = shoppingCartCalculationService.calculate(shoppingCart, store, language);
if (CollectionUtils.isNotEmpty(orderSummary.getTotals())) {
List<OrderTotal> totals = new ArrayList<OrderTotal>();
for (com.salesmanager.core.model.order.OrderTotal t : orderSummary.getTotals()) {
OrderTotal total = new OrderTotal();
total.setCode(t.getOrderTotalCode());
total.setText(t.getText());
total.setValue(t.getValue());
totals.add(total);
}
cart.setTotals(totals);
}
cart.setSubTotal(pricingService.getDisplayAmount(orderSummary.getSubTotal(), store));
cart.setTotal(pricingService.getDisplayAmount(orderSummary.getTotal(), store));
cart.setQuantity(cartQuantity);
cart.setId(shoppingCart.getId());
} catch (ServiceException ex) {
LOG.error("Error while converting cart Model to cart Data.." + ex);
throw new ConversionException("Unable to create cart data", ex);
}
return cart;
}
Aggregations