Search in sources :

Example 16 with Order

use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method listTransactions.

@Override
public List<ReadableTransaction> listTransactions(Long orderId, MerchantStore store) {
    Validate.notNull(orderId, "orderId must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    List<ReadableTransaction> trx = new ArrayList<ReadableTransaction>();
    try {
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        List<Transaction> transactions = transactionService.listTransactions(modelOrder);
        ReadableTransaction transaction = null;
        ReadableTransactionPopulator trxPopulator = null;
        for (Transaction tr : transactions) {
            transaction = new ReadableTransaction();
            trxPopulator = new ReadableTransactionPopulator();
            trxPopulator.setOrderService(orderService);
            trxPopulator.setPricingService(pricingService);
            trxPopulator.populate(tr, transaction, store, store.getDefaultLanguage());
            trx.add(transaction);
        }
        return trx;
    } catch (Exception e) {
        LOGGER.error("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
        throw new ServiceRuntimeException("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 17 with Order

use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method nextTransaction.

@Override
public TransactionType nextTransaction(Long orderId, MerchantStore store) {
    try {
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        Transaction last = transactionService.lastTransaction(modelOrder, store);
        if (last.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
            return TransactionType.CAPTURE;
        } else if (last.getTransactionType().name().equals(TransactionType.AUTHORIZECAPTURE.name())) {
            return TransactionType.REFUND;
        } else if (last.getTransactionType().name().equals(TransactionType.CAPTURE.name())) {
            return TransactionType.REFUND;
        } else if (last.getTransactionType().name().equals(TransactionType.REFUND.name())) {
            return TransactionType.OK;
        } else {
            return TransactionType.OK;
        }
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while getting last transaction for order [" + orderId + "]", e);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 18 with Order

use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getReadableOrderList.

private com.salesmanager.shop.model.order.v0.ReadableOrderList getReadableOrderList(OrderCriteria criteria, MerchantStore store, Language language) throws Exception {
    OrderList orderList = orderService.listByStore(store, criteria);
    // ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
    Locale locale = LocaleUtils.getLocale(language);
    readableOrderPopulator.setLocale(locale);
    List<Order> orders = orderList.getOrders();
    com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
    if (CollectionUtils.isEmpty(orders)) {
        returnList.setRecordsTotal(0);
        // returnList.setMessage("No results for store code " + store);
        return null;
    }
    List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
    for (Order order : orders) {
        com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
        readableOrderPopulator.populate(order, readableOrder, store, language);
        readableOrders.add(readableOrder);
    }
    returnList.setRecordsTotal(orderList.getTotalCount());
    return this.populateOrderList(orderList, store, language);
}
Also used : Locale(java.util.Locale) ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ArrayList(java.util.ArrayList) OrderList(com.salesmanager.core.model.order.OrderList)

Example 19 with Order

use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method getReadableOrderHistory.

@Override
public List<ReadableOrderStatusHistory> getReadableOrderHistory(Long orderId, MerchantStore store, Language language) {
    Order order = orderService.getOrder(orderId, store);
    if (order == null) {
        throw new ResourceNotFoundException("Order id [" + orderId + "] not found for merchand [" + store.getId() + "]");
    }
    Set<OrderStatusHistory> historyList = order.getOrderHistory();
    List<ReadableOrderStatusHistory> returnList = historyList.stream().map(f -> mapToReadbleOrderStatusHistory(f)).collect(Collectors.toList());
    return returnList;
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) OrderEntity(com.salesmanager.shop.model.order.OrderEntity) DigitalProductService(com.salesmanager.core.business.services.catalog.product.file.DigitalProductService) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ZonedDateTime(java.time.ZonedDateTime) ReadableOrderPopulator(com.salesmanager.shop.populator.order.ReadableOrderPopulator) Autowired(org.springframework.beans.factory.annotation.Autowired) Delivery(com.salesmanager.core.model.common.Delivery) StringUtils(org.apache.commons.lang3.StringUtils) ShippingQuote(com.salesmanager.core.model.shipping.ShippingQuote) BigDecimal(java.math.BigDecimal) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Map(java.util.Map) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) TransactionService(com.salesmanager.core.business.services.payments.TransactionService) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) CreditCardType(com.salesmanager.core.model.payments.CreditCardType) CustomerFacade(com.salesmanager.shop.store.controller.customer.facade.CustomerFacade) FieldError(org.springframework.validation.FieldError) Set(java.util.Set) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) ShoppingCartItemPopulator(com.salesmanager.shop.populator.order.ShoppingCartItemPopulator) ZoneId(java.time.ZoneId) PaymentService(com.salesmanager.core.business.services.payments.PaymentService) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ShippingQuoteService(com.salesmanager.core.business.services.shipping.ShippingQuoteService) ShopOrder(com.salesmanager.shop.model.order.ShopOrder) ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) OrderSummary(com.salesmanager.core.model.order.OrderSummary) Billing(com.salesmanager.core.model.common.Billing) CreditCardUtils(com.salesmanager.core.business.utils.CreditCardUtils) BindingResult(org.springframework.validation.BindingResult) OrderService(com.salesmanager.core.business.services.order.OrderService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ShoppingCartFacade(com.salesmanager.shop.store.controller.shoppingCart.facade.ShoppingCartFacade) ArrayList(java.util.ArrayList) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary) OrderAttribute(com.salesmanager.core.model.order.attributes.OrderAttribute) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Service(org.springframework.stereotype.Service) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) LinkedHashSet(java.util.LinkedHashSet) ShoppingCartService(com.salesmanager.core.business.services.shoppingcart.ShoppingCartService) Product(com.salesmanager.core.model.catalog.product.Product) Country(com.salesmanager.core.model.reference.country.Country) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) EmailTemplatesUtils(com.salesmanager.shop.utils.EmailTemplatesUtils) Validate(org.apache.commons.lang3.Validate) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ServiceException(com.salesmanager.core.business.exception.ServiceException) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ObjectError(org.springframework.validation.ObjectError) Locale(java.util.Locale) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) OrderProductPopulator(com.salesmanager.shop.populator.order.OrderProductPopulator) OrderFacade(com.salesmanager.shop.store.controller.order.facade.OrderFacade) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) OrderList(com.salesmanager.core.model.order.OrderList) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ReadableOrderProductPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductPopulator) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) List(java.util.List) Payment(com.salesmanager.core.model.payments.Payment) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) PersistableOrderStatusHistory(com.salesmanager.shop.model.order.history.PersistableOrderStatusHistory) PersistableOrderApiPopulator(com.salesmanager.shop.populator.order.PersistableOrderApiPopulator) CoreConfiguration(com.salesmanager.core.business.utils.CoreConfiguration) LocalDate(java.time.LocalDate) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Address(com.salesmanager.shop.model.customer.address.Address) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) Async(org.springframework.scheduling.annotation.Async) PersistableCustomerPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerPopulator) Order(com.salesmanager.core.model.order.Order) DateUtil(com.salesmanager.shop.utils.DateUtil) HashMap(java.util.HashMap) TransactionType(com.salesmanager.core.model.payments.TransactionType) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal) PaymentType(com.salesmanager.core.model.payments.PaymentType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) LabelUtils(com.salesmanager.shop.utils.LabelUtils) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CustomerPopulator(com.salesmanager.shop.populator.customer.CustomerPopulator) PersistablePaymentPopulator(com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator) Transaction(com.salesmanager.core.model.payments.Transaction) Constants(com.salesmanager.core.business.constants.Constants) Logger(org.slf4j.Logger) OrderStatus(com.salesmanager.core.model.order.orderstatus.OrderStatus) Customer(com.salesmanager.core.model.customer.Customer) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ShippingSummary(com.salesmanager.core.model.shipping.ShippingSummary) ConversionException(com.salesmanager.core.business.exception.ConversionException) Comparator(java.util.Comparator) Collections(java.util.Collections) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) PersistableOrderStatusHistory(com.salesmanager.shop.model.order.history.PersistableOrderStatusHistory) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)

Example 20 with Order

use of com.salesmanager.core.model.order.Order in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method createOrderStatus.

@Override
public void createOrderStatus(PersistableOrderStatusHistory status, Long id, MerchantStore store) {
    Validate.notNull(status, "OrderStatusHistory must not be null");
    Validate.notNull(id, "Order id must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    // retrieve original order
    Order order = orderService.getOrder(id, store);
    if (order == null) {
        throw new ResourceNotFoundException("Order with id [" + id + "] does not exist for merchant [" + store.getCode() + "]");
    }
    try {
        OrderStatusHistory history = new OrderStatusHistory();
        history.setComments(status.getComments());
        history.setDateAdded(DateUtil.getDate(status.getDate()));
        history.setOrder(order);
        history.setStatus(status.getStatus());
        orderService.addOrderStatusHistory(order, history);
    } catch (Exception e) {
        throw new ServiceRuntimeException("An error occured while converting orderstatushistory", e);
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) PersistableOrderStatusHistory(com.salesmanager.shop.model.order.history.PersistableOrderStatusHistory) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

Order (com.salesmanager.core.model.order.Order)26 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)12 ServiceException (com.salesmanager.core.business.exception.ServiceException)12 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)11 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)11 ArrayList (java.util.ArrayList)11 Customer (com.salesmanager.core.model.customer.Customer)9 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 Language (com.salesmanager.core.model.reference.language.Language)7 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)7 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)6 Transaction (com.salesmanager.core.model.payments.Transaction)6 OrderList (com.salesmanager.core.model.order.OrderList)5 OrderTotalSummary (com.salesmanager.core.model.order.OrderTotalSummary)5 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)5 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)5 ReadableOrderProduct (com.salesmanager.shop.model.order.ReadableOrderProduct)5 HashMap (java.util.HashMap)5 Product (com.salesmanager.core.model.catalog.product.Product)4