Application app = context.getApplication();
CustomerController customerController =
(CustomerController) app.evaluateExpressionGet(context, "#{customerController}",
CustomerController.class);
Order order = new Order();
order.setCustomer(customerController.getCustomer());
order.setOrderDate(new Timestamp((new Date()).getTime()));
order.setStatusEnum(StatusEnum.CHECKPAYMENT);
order.setBank(this.bank);
try {
// Salvar pedido.
order = facade.saveOrder(order);
} catch (ServiceException e) {
logger.error("Erro ao salvar pedido.", e);
FacesUtil.mensErro("", FacesUtil.getMessage("cartControllerMessageErrorSaveOrder"));
}
order.setItemsOrders(new HashSet<ItemsOrder>());
for (ItemsOrder itemsOrder : this.cart.getProducts()) {
// Novo item de pedido com Chave composta.
ItemsOrder newItemsOrder = new ItemsOrder(order.getId(), itemsOrder.getProduct().getId(),
itemsOrder.getQuantity(), itemsOrder.getSubTotal());
// Configurando pedido.
newItemsOrder.setOrder(order);
// Configurando Produto.
newItemsOrder.setProduct(itemsOrder.getProduct());
try {
// Salvando Item de pedido.
facade.mergeItemsOrder(newItemsOrder);
} catch (ServiceException e) {
logger.error("Erro ao salvar item de pedido - " + itemsOrder, e);
FacesUtil.mensErro("", FacesUtil.getMessage("cartControllerMessageErrorSaveItemOrder")
+ itemsOrder);
}
// Adicionando a lista de item de pedido.
order.getItemsOrders().add(newItemsOrder);
}
try {
sendConfirmOrder(order);
} catch (ServiceException e1) {