protected void addTotals(final AbstractOrderModel source, final AbstractOrderData prototype) {
   prototype.setTotalPrice(createPrice(source, source.getTotalPrice()));
   prototype.setTotalTax(createPrice(source, source.getTotalTax()));
   prototype.setSubTotal(createPrice(source, source.getSubtotal()));
   prototype.setDeliveryCost(
       source.getDeliveryMode() != null ? createPrice(source, source.getDeliveryCost()) : null);
   prototype.setTotalPriceWithTax((createPrice(source, calcTotalWithTax(source))));
 }
  @RequestMapping(value = "/placeOrder")
  @RequireHardLogIn
  public String placeOrder(
      final Model model, @Valid final PlaceOrderForm placeOrderForm, final BindingResult result)
      throws CMSItemNotFoundException {
    if (result.hasErrors()) {
      GlobalMessages.addErrorMessage(model, "checkout.placeOrder.failed");

      placeOrderForm.setTermsCheck(false);
      model.addAttribute(placeOrderForm);

      return checkoutSummary(model);
    }

    // placeOrderData is the same as placeOrderForm, should use placeOrderData replace
    // placeOrderForm
    final PlaceOrderData placeOrderData = new PlaceOrderData();
    placeOrderData.setNDays(placeOrderForm.getnDays());
    placeOrderData.setNDaysOfWeek(placeOrderForm.getnDaysOfWeek());
    placeOrderData.setNegotiateQuote(placeOrderForm.isNegotiateQuote());
    placeOrderData.setNthDayOfMonth(placeOrderForm.getNthDayOfMonth());
    placeOrderData.setNWeeks(placeOrderForm.getnWeeks());
    placeOrderData.setQuoteRequestDescription(placeOrderForm.getQuoteRequestDescription());
    placeOrderData.setReplenishmentOrder(placeOrderForm.isReplenishmentOrder());
    placeOrderData.setReplenishmentRecurrence(placeOrderForm.getReplenishmentRecurrence());
    placeOrderData.setReplenishmentStartDate(placeOrderForm.getReplenishmentStartDate());
    placeOrderData.setSecurityCode(placeOrderForm.getSecurityCode());
    placeOrderData.setTermsCheck(placeOrderForm.isTermsCheck());

    try {
      final AbstractOrderData orderData = getB2BCheckoutFacade().placeOrder(placeOrderData);

      if (placeOrderForm.isReplenishmentOrder()) {
        return REDIRECT_PREFIX
            + "/checkout/replenishmentConfirmation/"
            + ((ScheduledCartData) orderData).getJobCode();
      } else if (placeOrderForm.isNegotiateQuote()) {
        return REDIRECT_PREFIX + "/checkout/quoteOrderConfirmation/" + orderData.getCode();
      } else {
        return REDIRECT_PREFIX + "/checkout/orderConfirmation/" + orderData.getCode();
      }
    } catch (final EntityValidationException ve) {
      GlobalMessages.addErrorMessage(model, ve.getLocalizedMessage());

      placeOrderForm.setTermsCheck(false);
      model.addAttribute(placeOrderForm);

      return checkoutSummary(model);
    } catch (final Exception e) {
      GlobalMessages.addErrorMessage(model, "checkout.placeOrder.failed");

      placeOrderForm.setTermsCheck(false);
      model.addAttribute(placeOrderForm);

      return checkoutSummary(model);
    }
  }
  protected void addPromotions(
      final AbstractOrderModel source,
      final PromotionOrderResults promoOrderResults,
      final AbstractOrderData prototype) {
    if (promoOrderResults != null) {
      final double productsDiscountsAmount = getProductsDiscountsAmount(source);
      final double orderDiscountsAmount = getOrderDiscountsAmount(source);

      prototype.setProductDiscounts(createPrice(source, Double.valueOf(productsDiscountsAmount)));
      prototype.setOrderDiscounts(createPrice(source, Double.valueOf(orderDiscountsAmount)));
      prototype.setTotalDiscounts(
          createPrice(source, Double.valueOf(productsDiscountsAmount + orderDiscountsAmount)));
      prototype.setAppliedOrderPromotions(
          getPromotions(promoOrderResults.getAppliedOrderPromotions()));
      prototype.setAppliedProductPromotions(
          getPromotions(promoOrderResults.getAppliedProductPromotions()));
    }
  }
  protected void addPaymentInformation(
      final AbstractOrderModel source, final AbstractOrderData prototype) {
    final PaymentInfoModel paymentInfo = source.getPaymentInfo();
    if (paymentInfo instanceof CreditCardPaymentInfoModel) {
      final CCPaymentInfoData paymentInfoData =
          getCreditCardPaymentInfoConverter().convert((CreditCardPaymentInfoModel) paymentInfo);

      final boolean isDefaultPayment = isDefaultPaymentInfo(source.getUser(), paymentInfo);
      paymentInfoData.setDefaultPaymentInfo(isDefaultPayment);
      prototype.setPaymentInfo(paymentInfoData);
    }
  }
  protected void addDeliveryMethod(
      final AbstractOrderModel source, final AbstractOrderData prototype) {
    final DeliveryModeModel deliveryMode = source.getDeliveryMode();
    if (deliveryMode != null) {
      // unnecessary if?
      if (deliveryMode instanceof ZoneDeliveryModeModel) {
        final ZoneDeliveryModeData zoneDeliveryModeData =
            getZoneDeliveryModeConverter().convert((ZoneDeliveryModeModel) deliveryMode);

        final PriceValue deliveryCost =
            getDeliveryService()
                .getDeliveryCostForDeliveryModeAndAbstractOrder(deliveryMode, source);
        if (deliveryCost != null) {
          zoneDeliveryModeData.setDeliveryCost(
              getPriceDataFactory()
                  .create(
                      PriceDataType.BUY,
                      BigDecimal.valueOf(deliveryCost.getValue()),
                      deliveryCost.getCurrencyIso()));
        }
        prototype.setDeliveryMode(zoneDeliveryModeData);
      } else {
        final DeliveryModeData deliveryModeData = getDeliveryModeConverter().convert(deliveryMode);

        final PriceValue deliveryCost =
            getDeliveryService()
                .getDeliveryCostForDeliveryModeAndAbstractOrder(deliveryMode, source);
        if (deliveryCost != null) {
          deliveryModeData.setDeliveryCost(
              getPriceDataFactory()
                  .create(
                      PriceDataType.BUY,
                      BigDecimal.valueOf(deliveryCost.getValue()),
                      deliveryCost.getCurrencyIso()));
        }
        prototype.setDeliveryMode(deliveryModeData);
      }
    }
  }
 protected void addCommon(final AbstractOrderModel source, final AbstractOrderData prototype) {
   prototype.setCode(source.getCode());
   if (source.getSite() != null) {
     prototype.setSite(source.getSite().getUid());
   }
   if (source.getStore() != null) {
     prototype.setStore(source.getStore().getUid());
   }
   prototype.setTotalItems(calcTotalItems(source));
   prototype.setNet(Boolean.TRUE.equals(source.getNet()));
   prototype.setGuid(source.getGuid());
   prototype.setCalculated(Boolean.TRUE.equals(source.getCalculated()));
 }
 protected void addPrincipalInformation(
     final AbstractOrderModel source, final AbstractOrderData target) {
   target.setUser(getPrincipalConverter().convert(source.getUser()));
 }
 protected void addDeliveryAddress(
     final AbstractOrderModel source, final AbstractOrderData prototype) {
   if (source.getDeliveryAddress() != null) {
     prototype.setDeliveryAddress(getAddressConverter().convert(source.getDeliveryAddress()));
   }
 }
 protected void addEntries(final AbstractOrderModel source, final AbstractOrderData prototype) {
   prototype.setEntries(Converters.convertAll(source.getEntries(), getOrderEntryConverter()));
 }