use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getReadableOrder.
@Override
public com.salesmanager.shop.model.order.v0.ReadableOrder getReadableOrder(Long orderId, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order not found with id " + orderId);
}
com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
Long customerId = modelOrder.getCustomerId();
if (customerId != null) {
ReadableCustomer readableCustomer = customerFacade.getCustomerById(customerId, store, language);
if (readableCustomer == null) {
LOGGER.warn("Customer id " + customerId + " not found in order " + orderId);
} else {
readableOrder.setCustomer(readableCustomer);
}
}
try {
readableOrderPopulator.populate(modelOrder, readableOrder, store, language);
// order products
List<ReadableOrderProduct> orderProducts = new ArrayList<ReadableOrderProduct>();
for (OrderProduct p : modelOrder.getOrderProducts()) {
ReadableOrderProductPopulator orderProductPopulator = new ReadableOrderProductPopulator();
orderProductPopulator.setProductService(productService);
orderProductPopulator.setPricingService(pricingService);
orderProductPopulator.setimageUtils(imageUtils);
ReadableOrderProduct orderProduct = new ReadableOrderProduct();
orderProductPopulator.populate(p, orderProduct, store, language);
orderProducts.add(orderProduct);
}
readableOrder.setProducts(orderProducts);
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting order [" + orderId + "]");
}
return readableOrder;
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method convertCustomerListToReadableCustomerList.
private ReadableCustomerList convertCustomerListToReadableCustomerList(CustomerList customerList, MerchantStore store, Language language) {
List<ReadableCustomer> readableCustomers = customerList.getCustomers().stream().map(customer -> convertCustomerToReadableCustomer(customer, store, language)).collect(Collectors.toList());
ReadableCustomerList readableCustomerList = new ReadableCustomerList();
readableCustomerList.setCustomers(readableCustomers);
readableCustomerList.setTotalPages(Math.toIntExact(customerList.getTotalCount()));
return readableCustomerList;
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method update.
@Override
public PersistableCustomer update(String userName, PersistableCustomer customer, MerchantStore store) {
ReadableCustomer customerModel = getByUserName(userName, store, store.getDefaultLanguage());
customer.setId(customerModel.getId());
customer.setUserName(userName);
return updateAuthCustomer(customer, store);
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method getByUserName.
@Override
public ReadableCustomer getByUserName(String userName, MerchantStore merchantStore, Language language) {
Validate.notNull(userName, "Username cannot be null");
Validate.notNull(merchantStore, "MerchantStore cannot be null");
Customer customerModel = getCustomerByNickAndStoreId(userName, merchantStore);
return convertCustomerToReadableCustomer(customerModel, merchantStore, language);
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method orderConfirmation.
@Override
public ReadableOrderConfirmation orderConfirmation(Order order, Customer customer, MerchantStore store, Language language) {
Validate.notNull(order, "Order cannot be null");
Validate.notNull(customer, "Customer cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
ReadableOrderConfirmation orderConfirmation = new ReadableOrderConfirmation();
ReadableCustomer readableCustomer = readableCustomerMapper.convert(customer, store, language);
orderConfirmation.setBilling(readableCustomer.getBilling());
orderConfirmation.setDelivery(readableCustomer.getDelivery());
ReadableTotal readableTotal = new ReadableTotal();
Set<OrderTotal> totals = order.getOrderTotal();
List<ReadableOrderTotal> readableTotals = totals.stream().sorted(Comparator.comparingInt(OrderTotal::getSortOrder)).map(tot -> convertOrderTotal(tot, store, language)).collect(Collectors.toList());
readableTotal.setTotals(readableTotals);
Optional<ReadableOrderTotal> grandTotal = readableTotals.stream().filter(tot -> tot.getCode().equals("order.total.total")).findFirst();
if (grandTotal.isPresent()) {
readableTotal.setGrandTotal(grandTotal.get().getText());
}
orderConfirmation.setTotal(readableTotal);
List<ReadableOrderProduct> products = order.getOrderProducts().stream().map(pr -> convertOrderProduct(pr, store, language)).collect(Collectors.toList());
orderConfirmation.setProducts(products);
if (!StringUtils.isBlank(order.getShippingModuleCode())) {
StringBuilder optionCodeBuilder = new StringBuilder();
try {
optionCodeBuilder.append("module.shipping.").append(order.getShippingModuleCode());
String shippingName = messages.getMessage(optionCodeBuilder.toString(), new String[] { store.getStorename() }, languageService.toLocale(language, store));
orderConfirmation.setShipping(shippingName);
} catch (Exception e) {
// label not found
LOGGER.warn("No shipping code found for " + optionCodeBuilder.toString());
}
}
if (order.getPaymentType() != null) {
orderConfirmation.setPayment(order.getPaymentType().name());
}
/**
* Confirmation may be formatted
*/
orderConfirmation.setId(order.getId());
return orderConfirmation;
}
Aggregations