orderItemRequestDTO.setQuantity(item.getQuantity() + orderItemRequestDTO.getQuantity());
orderItemRequestDTO.setOrderItemId(item.getId());
try {
return updateItemQuantity(orderId, orderItemRequestDTO, priceOrder);
} catch (RemoveFromCartException e) {
throw new AddToCartException("Unexpected error - system tried to remove item while adding to cart", e);
} catch (UpdateCartException e) {
throw new AddToCartException("Could not update quantity for matched item", e);
}
}
}
try {
// We only want to price on the last addition for performance reasons and only if the user asked for it.
int numAdditionRequests = priceOrder ? (1 + orderItemRequestDTO.getChildOrderItems().size()) : -1;
int currentAddition = 1;
CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, currentAddition == numAdditionRequests);
ProcessContext<CartOperationRequest> context = (ProcessContext<CartOperationRequest>) addItemWorkflow.doActivities(cartOpRequest);
List<ActivityMessageDTO> orderMessages = new ArrayList<ActivityMessageDTO>();
orderMessages.addAll(((ActivityMessages) context).getActivityMessages());
if (CollectionUtils.isNotEmpty(orderItemRequestDTO.getChildOrderItems())) {
for (OrderItemRequestDTO childRequest : orderItemRequestDTO.getChildOrderItems()) {
childRequest.setParentOrderItemId(context.getSeedData().getOrderItem().getId());
currentAddition++;
CartOperationRequest childCartOpRequest = new CartOperationRequest(context.getSeedData().getOrder(), childRequest, currentAddition == numAdditionRequests);
ProcessContext<CartOperationRequest> childContext = (ProcessContext<CartOperationRequest>) addItemWorkflow.doActivities(childCartOpRequest);
orderMessages.addAll(((ActivityMessages) childContext).getActivityMessages());
}
}
context.getSeedData().getOrder().setOrderMessages(orderMessages);
return context.getSeedData().getOrder();
} catch (WorkflowException e) {
throw new AddToCartException("Could not add to cart", getCartOperationExceptionRootCause(e));
}
}