Exemple #1
0
  // req: 11.7
  public Order createFromShoppingCart(ShoppingCart shoppingCart, Consumer consumer) {
    Assert.notNull(shoppingCart);
    Assert.isTrue(shoppingCart.getId() != 0);
    Assert.notNull(consumer);
    Assert.isTrue(consumer.getId() != 0);

    Order result;
    Collection<OrderItem> orderItems;
    double amount;

    result = this.create();

    // Adding OrderItems
    orderItems = orderItemService.createByShoppingCart(shoppingCart, result);
    result.setOrderItems(orderItems);

    // Calculate amount
    amount = this.amountCalculate(orderItems);
    result.setAmount(amount);

    // Adding Order to Consumer
    result.setConsumer(consumer);

    return result;
  }
Exemple #2
0
  /** Guarda la Order desde ShoppingCart. NO USAR. Usar desde ShoppingCartService.saveCheckOut. */
  public void saveFromShoppingCart(ShoppingCart shoppingCart, Order order) {
    Assert.notNull(shoppingCart);
    Assert.notNull(order);

    Collection<OrderItem> orderItems;
    double amount;

    // Check CreditCard
    Assert.isTrue(
        this.checkCreditcard(order.getCreditCard()), "order.commit.error.creditcard.date");

    // Adding OrderItems
    orderItems = orderItemService.createByShoppingCart(shoppingCart, order);
    order.setOrderItems(orderItems);

    // Calculate amount
    amount = this.amountCalculate(orderItems);
    Assert.isTrue(amount == order.getAmount(), "order.commit.AmountChanged");

    order = this.save(order);

    // Saving OrderItems
    orderItems = orderItemService.createByShoppingCart(shoppingCart, order);
    orderItemService.save(orderItems);
  }