@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); }
/** * Puts two products in the cart, applies one 10% product promotion, and redeems * * <ul> * <li>1. one voucher without free shipping or * <li>2. one voucher with free shipping or * <li>3. two vouchers, one with free shipping and the other one without. * </ul> */ @Test public void testPromotionWithVoucher() throws JaloPriceFactoryException { // PRO-64 promotionGroup = promotionsService.getPromotionGroup("prGroup10"); final List<PromotionGroupModel> groups = new ArrayList<PromotionGroupModel>(); groups.add(promotionGroup); cartService.addNewEntry(cart, product1, 2, product1.getUnit()); deliveryModeDhl = deliveryModeService.getDeliveryModeForCode("dhl"); cart.setDeliveryMode(deliveryModeDhl); cart.setDeliveryAddress(user.getDefaultShipmentAddress()); /** * General information: * * <ul> * <li>product(HW2110-0012) price = 81.08 --> 2x = 162.16, delivery cost 8.0, totally 170.16 * <li>applied 10% ProductPercentageDiscountPromotion, 162.16 * 0.9 = 145.94 * </ul> * * Three different situations with vouchers: * * <ul> * <li>1. 5% voucher without free shipping, 145.94 * 0.95 = 138.64, delivery cost 8.0, totally * 146.64 * <li>2. 20% voucher with free shipping, 145.94 * 0.8 = 116.75, free shipping, totally 116.75 * <li>3. both the vouchers above, 145.94 * (1 - 0.05 - 0.20) = 109.45, free shipping, totally * 109.45 * </ul> */ applyVouchersAndPromotions(new String[] {voucherCode}, groups, 146.64); applyVouchersAndPromotions(new String[] {freeShippingVoucherCode}, groups, 116.75); applyVouchersAndPromotions(new String[] {voucherCode, freeShippingVoucherCode}, groups, 109.45); }
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(); }