Search in sources :

Example 1 with ReadableTotal

use of com.salesmanager.shop.model.order.total.ReadableTotal 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;
}
Also used : ReadableOrderTotalMapper(com.salesmanager.shop.mapper.order.ReadableOrderTotalMapper) Order(com.salesmanager.core.model.order.Order) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableCustomerMapper(com.salesmanager.shop.mapper.customer.ReadableCustomerMapper) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) LabelUtils(com.salesmanager.shop.utils.LabelUtils) Service(org.springframework.stereotype.Service) Logger(org.slf4j.Logger) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) ReadableOrderConfirmation(com.salesmanager.shop.model.order.v1.ReadableOrderConfirmation) Set(java.util.Set) Collectors(java.util.stream.Collectors) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) List(java.util.List) Validate(org.apache.commons.lang3.Validate) OrderFacade(com.salesmanager.shop.store.controller.order.facade.v1.OrderFacade) Optional(java.util.Optional) Comparator(java.util.Comparator) ReadableOrderProductMapper(com.salesmanager.shop.mapper.order.ReadableOrderProductMapper) ReadableTotal(com.salesmanager.shop.model.order.total.ReadableTotal) OrderTotal(com.salesmanager.core.model.order.OrderTotal) ReadableTotal(com.salesmanager.shop.model.order.total.ReadableTotal) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableOrderConfirmation(com.salesmanager.shop.model.order.v1.ReadableOrderConfirmation) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) OrderTotal(com.salesmanager.core.model.order.OrderTotal)

Aggregations

LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 Customer (com.salesmanager.core.model.customer.Customer)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Order (com.salesmanager.core.model.order.Order)1 OrderTotal (com.salesmanager.core.model.order.OrderTotal)1 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)1 Language (com.salesmanager.core.model.reference.language.Language)1 ReadableCustomerMapper (com.salesmanager.shop.mapper.customer.ReadableCustomerMapper)1 ReadableOrderProductMapper (com.salesmanager.shop.mapper.order.ReadableOrderProductMapper)1 ReadableOrderTotalMapper (com.salesmanager.shop.mapper.order.ReadableOrderTotalMapper)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)1 ReadableOrderTotal (com.salesmanager.shop.model.order.total.ReadableOrderTotal)1 ReadableTotal (com.salesmanager.shop.model.order.total.ReadableTotal)1 ReadableOrderConfirmation (com.salesmanager.shop.model.order.v1.ReadableOrderConfirmation)1 OrderFacade (com.salesmanager.shop.store.controller.order.facade.v1.OrderFacade)1 LabelUtils (com.salesmanager.shop.utils.LabelUtils)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1