コード例 #1
0
  @Override
  @Transactional("blTransactionManager")
  public Order addAllItemsFromNamedOrder(Order namedOrder, boolean priceOrder)
      throws RemoveFromCartException, AddToCartException {
    Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
    if (cartOrder == null) {
      cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
    }
    List<OrderItem> items = new ArrayList<OrderItem>(namedOrder.getOrderItems());
    for (OrderItem item : items) {
      if (moveNamedOrderItems) {
        removeItem(namedOrder.getId(), item.getId(), false);
      }

      OrderItemRequestDTO orderItemRequest =
          orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
      cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);
    }

    if (deleteEmptyNamedOrders) {
      cancelOrder(namedOrder);
    }

    return cartOrder;
  }
コード例 #2
0
  @Override
  @Transactional("blTransactionManager")
  public Order addItemFromNamedOrder(
      Order namedOrder, OrderItem item, int quantity, boolean priceOrder)
      throws RemoveFromCartException, AddToCartException, UpdateCartException {
    // Validate that the quantity requested makes sense
    if (quantity < 1 || quantity > item.getQuantity()) {
      throw new IllegalArgumentException("Cannot move 0 or less quantity");
    } else if (quantity == item.getQuantity()) {
      return addItemFromNamedOrder(namedOrder, item, priceOrder);
    }

    Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
    if (cartOrder == null) {
      cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
    }

    if (moveNamedOrderItems) {
      // Update the old item to its new quantity only if we're moving items
      OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
      orderItemRequestDTO.setOrderItemId(item.getId());
      orderItemRequestDTO.setQuantity(item.getQuantity() - quantity);
      updateItemQuantity(namedOrder.getId(), orderItemRequestDTO, false);
    }

    OrderItemRequestDTO orderItemRequest =
        orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
    orderItemRequest.setQuantity(quantity);
    cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);

    return cartOrder;
  }
コード例 #3
0
 @Override
 public Order findCartForCustomer(Customer customer) {
   return orderDao.readCartForCustomer(customer);
 }