@Override @Transactional( value = "blTransactionManager", rollbackFor = {AddToCartException.class}) public Order addItemWithPriceOverrides( Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws AddToCartException { Order order = findOrderById(orderId); if (automaticallyMergeLikeItems) { OrderItem item = findMatchingItem(order, orderItemRequestDTO); if (item != null) { 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 { CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder); CartOperationContext context = (CartOperationContext) addItemWorkflow.doActivities(cartOpRequest); return context.getSeedData().getOrder(); } catch (WorkflowException e) { throw new AddToCartException("Could not add to cart", getCartOperationExceptionRootCause(e)); } }
@Override @Transactional( value = "blTransactionManager", rollbackFor = {UpdateCartException.class, RemoveFromCartException.class}) public Order updateItemQuantity( Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws UpdateCartException, RemoveFromCartException { if (orderItemRequestDTO.getQuantity() == 0) { return removeItem(orderId, orderItemRequestDTO.getOrderItemId(), priceOrder); } try { CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder); CartOperationContext context = (CartOperationContext) updateItemWorkflow.doActivities(cartOpRequest); return context.getSeedData().getOrder(); } catch (WorkflowException e) { throw new UpdateCartException( "Could not update cart quantity", getCartOperationExceptionRootCause(e)); } }