Author: jacopoc
Date: Fri Apr 27 03:04:14 2007
New Revision: 533045
URL:
http://svn.apache.org/viewvc?view=rev&rev=533045Log:
When a payment method is selected in the cart, if it is associated to a billing address, the cart verifies that the location of the billing address is allowed for the products in the cart before setting 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=533045&r1=533044&r2=533045==============================================================================
--- 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 03:04:14 2007
@@ -48,6 +48,7 @@
import org.ofbiz.order.shoppinglist.ShoppingListEvents;
import org.ofbiz.product.category.CategoryWorker;
import org.ofbiz.product.config.ProductConfigWrapper;
+import org.ofbiz.product.product.ProductWorker;
import org.ofbiz.product.store.ProductStoreWorker;
import org.ofbiz.service.LocalDispatcher;
@@ -1436,6 +1437,19 @@
/** adds a payment method/payment method type */
public CartPaymentInfo addPaymentAmount(String id, Double amount, String refNum, String authCode, boolean isSingleUse, boolean isPresent, boolean replace) {
CartPaymentInfo inf = this.getPaymentInfo(id, refNum, authCode, amount, true);
+ GenericValue billingAddress = inf.getBillingAddress(this.getDelegator());
+ if (billingAddress != null) {
+ // this payment method will set the billing address for the order;
+ // before it is set we have to verify if the billing address is
+ // compatible with the ProductGeos
+ Iterator products = (this.getItemsProducts(this.cartLines)).iterator();
+ while (products.hasNext()) {
+ GenericValue product = (GenericValue)products.next();
+ if (!ProductWorker.isBillableToAddress(product, billingAddress)) {
+ throw new IllegalArgumentException("The billing address is not compatible with ProductGeos rules.");
+ }
+ }
+ }
inf.singleUse = isSingleUse;
if (replace) {
paymentInfo.remove(inf);
@@ -1709,6 +1723,19 @@
} else {
return true;
}
+ }
+
+ public GenericValue getBillingAddress() {
+ GenericValue billingAddress = null;
+ Iterator i = paymentInfo.iterator();
+ while (i.hasNext()) {
+ CartPaymentInfo inf = (CartPaymentInfo) i.next();
+ billingAddress = inf.getBillingAddress(this.getDelegator());
+ if (billingAddress != null) {
+ break;
+ }
+ }
+ return billingAddress;
}
/**