svn commit: r567525 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/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: r567525 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

jonesde
Author: jonesde
Date: Sun Aug 19 19:21:01 2007
New Revision: 567525

URL: http://svn.apache.org/viewvc?rev=567525&view=rev
Log:
Added method to get total for all promotions in cart

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?rev=567525&r1=567524&r2=567525&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 Sun Aug 19 19:21:01 2007
@@ -2928,6 +2928,43 @@
     public Iterator getProductPromoUseInfoIter() {
         return productPromoUseInfoList.iterator();
     }
+    
+    public double getProductPromoTotal() {
+        double totalDiscount = 0;
+        List cartAdjustments = this.getAdjustments();
+        if (cartAdjustments != null) {
+            Iterator cartAdjustmentIter = cartAdjustments.iterator();
+            while (cartAdjustmentIter.hasNext()) {
+                GenericValue checkOrderAdjustment = (GenericValue) cartAdjustmentIter.next();
+                if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) &&
+                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) &&
+                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) {
+                    if (checkOrderAdjustment.get("amount") != null) {
+                        totalDiscount += checkOrderAdjustment.getDouble("amount").doubleValue();
+                    }
+                }
+            }
+        }
+
+        // remove cart lines that are promos (ie GWPs) and cart line adjustments from promo actions
+        Iterator cartItemIter = this.iterator();
+        while (cartItemIter.hasNext()) {
+            ShoppingCartItem checkItem = (ShoppingCartItem) cartItemIter.next();
+            Iterator checkOrderAdjustments = UtilMisc.toIterator(checkItem.getAdjustments());
+            while (checkOrderAdjustments != null && checkOrderAdjustments.hasNext()) {
+                GenericValue checkOrderAdjustment = (GenericValue) checkOrderAdjustments.next();
+                if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) &&
+                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) &&
+                        UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) {
+                    if (checkOrderAdjustment.get("amount") != null) {
+                        totalDiscount += checkOrderAdjustment.getDouble("amount").doubleValue();
+                    }
+                }
+            }
+        }
+
+        return totalDiscount;
+    }
 
     /** Get total discount for a given ProductPromo, or for ANY ProductPromo if the passed in productPromoId is null. */
     public double getProductPromoUseTotalDiscount(String productPromoId) {