You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/04/27 15:46:02 UTC

svn commit: r533095 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

Author: jacopoc
Date: Fri Apr 27 06:46:01 2007
New Revision: 533095

URL: http://svn.apache.org/viewvc?view=rev&rev=533095
Log:
When a billing address is set in the cart, the cart verifies that the geo location of the billing address is compatible to the product added to the cart, before adding it.

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

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=533095&r1=533094&r2=533095
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Fri Apr 27 06:46:01 2007
@@ -501,6 +501,17 @@
            throw new CartItemModifyException("Cart items cannot be changed");
         }
         if (!cartLines.contains(item)) {
+            // If the billing address is already set, verify if the new product
+            // is available in the address' geo
+            GenericValue product = item.getProduct();
+            if (product != null) {
+                GenericValue billingAddress = this.getBillingAddress();
+                if (billingAddress != null) {
+                    if (!ProductWorker.isBillableToAddress(product, billingAddress)) {
+                        throw new CartItemModifyException("The billing address is not compatible with ProductGeos rules of this product.");
+                    }
+                }
+            }
             cartLines.add(index, item);
             return index;
         } else {
@@ -520,15 +531,7 @@
 
     /** Add an item to the shopping cart. */
     public int addItemToEnd(ShoppingCartItem item) throws CartItemModifyException {
-        if (isReadOnlyCart()) {
-           throw new CartItemModifyException("Cart items cannot be changed");
-        }
-        if (!cartLines.contains(item)) {
-            cartLines.add(item);
-            return cartLines.size() - 1;
-        } else {
-            return this.getItemIndex(item);
-        }
+        return addItem(cartLines.size(), item);
     }
 
     /** Get a ShoppingCartItem from the cart object. */