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() + "]");
}
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations