@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; }
@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; }
@Override @Transactional("blTransactionManager") public Order addOfferCode(Order order, OfferCode offerCode, boolean priceOrder) throws PricingException, OfferMaxUseExceededException { if (!order.getAddedOfferCodes().contains(offerCode)) { if (!offerService.verifyMaxCustomerUsageThreshold( order.getCustomer(), offerCode.getOffer())) { throw new OfferMaxUseExceededException( "The customer has used this offer code more than the maximum allowed number of times."); } order.getAddedOfferCodes().add(offerCode); order = save(order, priceOrder); } return order; }
public Customer getCustomer() { return delegate.getCustomer(); }