svn commit: r489337 - in /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart: CheckOutHelper.java ShoppingCart.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r489337 - in /incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart: CheckOutHelper.java ShoppingCart.java

jacopoc
Author: jacopoc
Date: Thu Dec 21 04:12:28 2006
New Revision: 489337

URL: http://svn.apache.org/viewvc?view=rev&rev=489337
Log:
Some minor refactorings to the way the billing account is set in the cart: now it is sufficient to set the billing account id using the setBillingAccount* methods (already available) and it is no more necessary to set the payment method to EXT_BILLACT in the cart.
In fact the correct OrderPaymentPreference for the billing account is created by the cart when the order is created (if a billingAccountId is set).
So now, if you want to add a billing account to the cart you can simply do this:
   cart.setBillingAccount(billingAccountId, maxAmount);
and you can remove the billing account from the cart with:
   cart.setBillingAccount(null, 0.0);

This also fixes a bug that was happening when a billing account was selected and an error was returned (no credit available): the EXTBILLACT method was left in the cart, leading to an incorrect order.

Modified:
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

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=489337&r1=489336&r2=489337
==============================================================================
--- 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 Thu Dec 21 04:12:28 2006
@@ -247,18 +247,18 @@
             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")) {
+            if (selectedPaymentMethods.containsKey("EXT_BILLACT") && selectedPaymentMethods.size() == 1) {
                 double accountCredit = this.availableAccountBalance(cart.getBillingAccountId());
                 // make sure we have enough to cover; if this is selected we don't have other payment methods
                 if (cart.getGrandTotal() > accountCredit) {
+                    // if _NA_ was supplied, erase all billing account data
+                    cart.setBillingAccount(null, 0.0);
                     errMsg = UtilProperties.getMessage(resource,"checkhelper.insufficient_credit_available_on_account",
                             (cart != null ? cart.getLocale() : Locale.getDefault()));
                     errorMessages.add(errMsg);

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=489337&r1=489336&r2=489337
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Thu Dec 21 04:12:28 2006
@@ -3298,9 +3298,16 @@
         while (i.hasNext()) {
             CartPaymentInfo inf = (CartPaymentInfo) i.next();
             allOpPrefs.addAll(inf.makeOrderPaymentInfos(this.getDelegator()));
-
         }
-
+        if (getBillingAccountId() != null) {
+            GenericValue opp = delegator.makeValue("OrderPaymentPreference", new HashMap());
+            opp.set("paymentMethodTypeId", "EXT_BILLACT");
+            opp.set("presentFlag", "N");
+            opp.set("overflowFlag", "N");
+            opp.set("maxAmount", new Double(getBillingAccountAmount()));
+            opp.set("statusId", "PAYMENT_NOT_RECEIVED");
+            allOpPrefs.add(opp);
+        }
         return allOpPrefs;
     }