Author: jacopoc
Date: Tue Dec 19 00:55:49 2006 New Revision: 488588 URL: http://svn.apache.org/viewvc?view=rev&rev=488588 Log: Misc fixes and cleanups for the checkout process: 1) cleaned up some old code 2) now the selected billing account (if any) will be stored in the cart However this patch should be intended as a temp fix because there are some parts of the code there are still a bit obscure to me and will need further testing and cleanups. Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java?view=diff&rev=488588&r1=488587&r2=488588 ============================================================================== --- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java (original) +++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java Tue Dec 19 00:55:49 2006 @@ -573,7 +573,6 @@ String isGift = null; String internalCode = null; String methodType = null; - String checkOutPaymentId = null; String singleUsePayment = null; String appendPayment = null; String shipBeforeDate = null; @@ -703,18 +702,12 @@ } } // ############################################################################### - // get the payment - checkOutPaymentId = request.getParameter("checkOutPaymentId"); - if (checkOutPaymentId == null) { - checkOutPaymentId = (String) request.getAttribute("paymentMethodId"); - } // check for offline payment type // payment option; if offline we skip the payment screen methodType = request.getParameter("paymentMethodType"); if ("offline".equals(methodType)) { Debug.log("Changing mode from->to: " + mode + "->payment", module); - checkOutPaymentId = "EXT_OFFLINE"; mode = "payment"; } singleUsePayment = request.getParameter("singleUsePayment"); @@ -741,18 +734,15 @@ request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderInvalidAmountSetForBillingAccount", UtilMisc.toMap("billingAccountId",billingAccountId), (cart != null ? cart.getLocale() : Locale.getDefault()))); return "error"; } - - Map selPaymentMethods = null; - if (checkOutPaymentId != null) { - callResult = checkOutHelper.finalizeOrderEntryPayment(checkOutPaymentId, null, isSingleUsePayment, doAppendPayment); - ServiceUtil.addErrors(errorMessages, errorMaps, callResult); - selPaymentMethods = UtilMisc.toMap(checkOutPaymentId, null); - } - callResult = checkOutHelper.checkGiftCard(paramMap, selPaymentMethods); + // The selected payment methods are set + errorMessages.addAll(checkOutHelper.setCheckOutPaymentInternal(selectedPaymentMethods, null, billingAccountId, billingAccountAmt)); + // Verify if a gift card has been selected during order entry + callResult = checkOutHelper.checkGiftCard(paramMap, selectedPaymentMethods); ServiceUtil.addErrors(errorMessages, errorMaps, callResult); if (errorMessages.size() == 0 && errorMaps.size() == 0) { String gcPaymentMethodId = (String) callResult.get("paymentMethodId"); Double giftCardAmount = (Double) callResult.get("amount"); + // WARNING: if gcPaymentMethodId is not empty, all the previously set payment methods will be removed Map gcCallRes = checkOutHelper.finalizeOrderEntryPayment(gcPaymentMethodId, giftCardAmount, true, true); ServiceUtil.addErrors(errorMessages, errorMaps, gcCallRes); } Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?view=diff&rev=488588&r1=488587&r2=488588 ============================================================================== --- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original) +++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Tue Dec 19 00:55:49 2006 @@ -231,7 +231,7 @@ return result; } - private List setCheckOutPaymentInternal(Map selectedPaymentMethods, List singleUsePayments, String billingAccountId, Double billingAccountAmt) { + public List setCheckOutPaymentInternal(Map selectedPaymentMethods, List singleUsePayments, String billingAccountId, Double billingAccountAmt) { List errorMessages = new ArrayList(); String errMsg = null; @@ -244,6 +244,16 @@ // clear out the old payments cart.clearPayments(); + if (billingAccountId != null && billingAccountAmt != null && !billingAccountId.equals("_NA_")) { + // set cart billing account data and generate a payment method containing the amount we will be charging + cart.setBillingAccount(billingAccountId, billingAccountAmt.doubleValue()); + selectedPaymentMethods.put("EXT_BILLACT", billingAccountAmt); + } else if ("_NA_".equals(billingAccountId)) { + // if _NA_ was supplied, erase all billing account data + cart.setBillingAccount(null, 0.0); + cart.clearPayment("EXT_BILLACT"); + } + // TODO: the following code needs some review (JAC20061213) // if checkoutPaymentId == EXT_BILLACT, then we have billing account only, so make sure we have enough credit if (selectedPaymentMethods.containsKey("EXT_BILLACT")) { double accountCredit = this.availableAccountBalance(cart.getBillingAccountId()); @@ -253,16 +263,6 @@ (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } - } - - if (billingAccountId != null && billingAccountAmt != null && !billingAccountId.equals("_NA_")) { - // set cart billing account data and generate a payment method containing the amount we will be charging - cart.setBillingAccount(billingAccountId, billingAccountAmt.doubleValue()); - selectedPaymentMethods.put("EXT_BILLACT", new Double(cart.getBillingAccountAmount())); - } else if ("_NA_".equals(billingAccountId)) { - // if _NA_ was supplied, erase all billing account data - cart.setBillingAccount(null, 0.0); - cart.clearPayment("EXT_BILLACT"); } Set paymentMethods = selectedPaymentMethods.keySet(); |
Free forum by Nabble | Edit this page |