Ejemplo n.º 1
0
 @Override
 public void executeAction(final ReplenishmentProcessModel process) throws Exception {
   final CartToOrderCronJobModel cartToOrderCronJob = process.getCartToOrderCronJob();
   final CartModel cronJobCart = cartToOrderCronJob.getCart();
   getUserService().setCurrentUser(cronJobCart.getUser());
   final CartModel clone =
       getCartService()
           .clone(
               getTypeService().getComposedTypeForClass(CartModel.class),
               getTypeService().getComposedTypeForClass(CartEntryModel.class),
               cronJobCart,
               getGuidKeyGenerator().generate().toString());
   clone.setPaymentAddress(cartToOrderCronJob.getPaymentAddress());
   clone.setDeliveryAddress(cartToOrderCronJob.getDeliveryAddress());
   clone.setPaymentInfo(cartToOrderCronJob.getPaymentInfo());
   clone.setStatus(OrderStatus.CREATED);
   clone.setAllPromotionResults(Collections.EMPTY_SET);
   clone.setPaymentTransactions(Collections.EMPTY_LIST);
   clone.setPermissionResults(Collections.EMPTY_LIST);
   clone.setGuid(getGuidKeyGenerator().generate().toString());
   this.modelService.save(clone);
   processParameterHelper.setProcessParameter(process, "cart", clone);
 }
  protected OrderModel placeTestOrder(final boolean valid)
      throws InvalidCartException, CalculationException {
    final CartModel cart = cartService.getSessionCart();
    final UserModel user = userService.getCurrentUser();
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null);
    cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null);

    final AddressModel deliveryAddress = new AddressModel();
    deliveryAddress.setOwner(user);
    deliveryAddress.setFirstname("Der");
    deliveryAddress.setLastname("Buck");
    deliveryAddress.setTown("Muenchen");
    deliveryAddress.setCountry(commonI18NService.getCountry("DE"));
    modelService.save(deliveryAddress);

    final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel();
    paymentInfo.setOwner(cart);
    paymentInfo.setBank("MeineBank");
    paymentInfo.setUser(user);
    paymentInfo.setAccountNumber("34434");
    paymentInfo.setBankIDNumber("1111112");
    paymentInfo.setBaOwner("Ich");
    paymentInfo.setCode("testPaymentInfo1");
    modelService.save(paymentInfo);

    cart.setDeliveryMode(deliveryService.getDeliveryModeForCode("free"));
    cart.setDeliveryAddress(deliveryAddress);
    cart.setPaymentInfo(paymentInfo);

    final CardInfo card = new CardInfo();
    card.setCardType(CreditCardType.VISA);
    card.setCardNumber("4111111111111111");
    card.setExpirationMonth(Integer.valueOf(12));
    if (valid) {
      card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2));
    } else {
      card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 2));
    }

    final PaymentTransactionModel paymentTransaction =
        paymentService
            .authorize(
                "code4" + codeNo++,
                BigDecimal.ONE,
                Currency.getInstance("EUR"),
                deliveryAddress,
                deliveryAddress,
                card)
            .getPaymentTransaction();

    cart.setPaymentTransactions(Collections.singletonList(paymentTransaction));
    modelService.save(cart);
    calculationService.calculate(cart);

    final CommerceCheckoutParameter parameter = new CommerceCheckoutParameter();
    parameter.setEnableHooks(true);
    parameter.setCart(cart);
    parameter.setSalesApplication(SalesApplication.WEB);

    return commerceCheckoutService.placeOrder(parameter).getOrder();
  }