Administrator
|
Why removing? This may prove useful in some cases...
> - if (Debug.verboseOn()) Debug.logVerbose("Performing " + productPromoActions.size() + " actions for rule " + > productPromoRule, module); > Iterator productPromoActionIter = UtilMisc.toIterator(productPromoActions); > while (productPromoActionIter != null && productPromoActionIter.hasNext()) { > GenericValue productPromoAction = (GenericValue) productPromoActionIter.next(); > - > - // Debug.logInfo("Doing action: " + productPromoAction, module); Jacques > Author: hansbak > Date: Mon Jan 31 07:58:48 2011 > New Revision: 1065504 > > URL: http://svn.apache.org/viewvc?rev=1065504&view=rev > Log: > shipping promotion now working on all shipping methods: https://issues.apache.org/jira/browse/OFBIZ-2488 > > Modified: > ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java > ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.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?rev=1065504&r1=1065503&r2=1065504&view=diff > ============================================================================== > --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original) > +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Mon Jan 31 07:58:48 2011 > @@ -2740,6 +2740,17 @@ public class ShoppingCart implements Ite > return adjustments; > } > > + public int getAdjustmentPromoIndex(String productPromoId) { > + int index = adjustments.size(); > + while (index > 0) { > + if (adjustments.get(index).getString("productPromoId").equals(productPromoId)) { > + return(index); > + } > + index++; > + } > + return -1; > + } > + > /** Add an adjustment to the order; don't worry about setting the orderId, orderItemSeqId or orderAdjustmentId; they will be > set when the order is created */ > public int addAdjustment(GenericValue adjustment) { > adjustments.add(adjustment); > @@ -2750,6 +2761,10 @@ public class ShoppingCart implements Ite > adjustments.remove(index); > } > > + public GenericValue getAdjustment(int index) { > + return adjustments.get(index); > + } > + > /** Get a List of orderTerms on the order (ie cart) */ > public List getOrderTerms() { > return orderTerms; > > Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java?rev=1065504&r1=1065503&r2=1065504&view=diff > ============================================================================== > --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java (original) > +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java Mon Jan 31 07:58:48 2011 > @@ -779,12 +779,9 @@ public class ProductPromoWorker { > // perform all actions, either apply or unapply > > List productPromoActions = productPromoRule.getRelatedCache("ProductPromoAction", null, > UtilMisc.toList("productPromoActionSeqId")); > - if (Debug.verboseOn()) Debug.logVerbose("Performing " + productPromoActions.size() + " actions for rule " + > productPromoRule, module); > Iterator productPromoActionIter = UtilMisc.toIterator(productPromoActions); > while (productPromoActionIter != null && productPromoActionIter.hasNext()) { > GenericValue productPromoAction = (GenericValue) productPromoActionIter.next(); > - > - // Debug.logInfo("Doing action: " + productPromoAction, module); > try { > ActionResultInfo actionResultInfo = performAction(productPromoAction, cart, delegator, dispatcher, > nowTimestamp); > totalDiscountAmount = totalDiscountAmount.add(actionResultInfo.totalDiscountAmount); > @@ -1759,9 +1756,17 @@ public class ProductPromoWorker { > BigDecimal percentage = (productPromoAction.get("amount") == null ? BigDecimal.ZERO : > (productPromoAction.getBigDecimal("amount").movePointLeft(2))).negate(); > BigDecimal amount = cart.getTotalShipping().multiply(percentage); > if (amount.compareTo(BigDecimal.ZERO) != 0) { > - doOrderPromoAction(productPromoAction, cart, amount, "amount", delegator); > - actionResultInfo.ranAction = true; > - actionResultInfo.totalDiscountAmount = amount; > + int existingOrderPromoIndex = cart.getAdjustmentPromoIndex(productPromoAction.getString("productPromoId")); > + if (existingOrderPromoIndex != -1 && > cart.getAdjustment(existingOrderPromoIndex).getBigDecimal("amount").compareTo(amount) == 0) { > + actionResultInfo.ranAction = false; // already ran, no need to repeat > + } else { > + if (existingOrderPromoIndex != -1 && > cart.getAdjustment(existingOrderPromoIndex).getBigDecimal("amount").compareTo(amount) != 0) { > + cart.removeAdjustment(existingOrderPromoIndex); > + } > + doOrderPromoAction(productPromoAction, cart, amount, "amount", delegator); > + actionResultInfo.ranAction = true; > + actionResultInfo.totalDiscountAmount = amount; > + } > } > } else { > Debug.logError("An un-supported productPromoActionType was used: " + productPromoActionEnumId + ", not performing any > action", module); > > |
Free forum by Nabble | Edit this page |