ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaco...@apache.org
Subject svn commit: r1720312 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart: ShoppingCart.java product/ProductPromoWorker.java
Date Wed, 16 Dec 2015 10:04:25 GMT
Author: jacopoc
Date: Wed Dec 16 10:04:25 2015
New Revision: 1720312

URL: http://svn.apache.org/viewvc?rev=1720312&view=rev
Log:
OFBIZ-6772 and OFBIZ-6773:
* added ability to specify comparison operators for promotions with conditions on quantity
* added ability to specify categories/products to filter the order sub-total amount eligible
for a discount

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=1720312&r1=1720311&r2=1720312&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 Wed
Dec 16 10:04:25 2015
@@ -2759,6 +2759,18 @@ public class ShoppingCart implements Ite
         }
         return itemsTotal.add(this.getOrderOtherAdjustmentTotal());
     }
+    public BigDecimal getSubTotalForPromotions(Set<String> productIds) {
+        BigDecimal itemsTotal = BigDecimal.ZERO;
+        for (ShoppingCartItem cartItem : this.cartLines) {
+            GenericValue product = cartItem.getProduct();
+            if (product == null || "N".equals(product.getString("includeInPromotions")) ||
!productIds.contains(cartItem.getProductId())) {
+                // don't include in total if this is the case...
+                continue;
+            }
+            itemsTotal = itemsTotal.add(cartItem.getItemSubTotal());
+        }
+        return itemsTotal;
+    }
 
     /**
      * Get the total payment amount by payment type.  Specify null to get amount

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=1720312&r1=1720311&r2=1720312&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
Wed Dec 16 10:04:25 2015
@@ -986,9 +986,10 @@ public class ProductPromoWorker {
                 compareBase = Integer.valueOf(amountAvailable.compareTo(amountNeeded));
             }
         } else if ("PPIP_PRODUCT_QUANT".equals(inputParamEnumId)) {
-            // for this type of promo force the operatorEnumId = PPC_EQ, effectively ignore
that setting because the comparison is implied in the code
-            operatorEnumId = "PPC_EQ";
-
+            if (operatorEnumId == null) {
+                // if the operator is not specified in the condition, then assume as default
PPC_EQ (for backward compatibility)
+                operatorEnumId = "PPC_EQ";
+            }
             BigDecimal quantityNeeded = BigDecimal.ONE;
             if (UtilValidate.isNotEmpty(condValue)) {
                 quantityNeeded = new BigDecimal(condValue);
@@ -1008,7 +1009,7 @@ public class ProductPromoWorker {
                         (productIds.contains(cartItem.getProductId()) || (parentProductId
!= null && productIds.contains(parentProductId))) &&
                         (product == null || !"N".equals(product.getString("includeInPromotions"))))
{
                     // reduce quantity still needed to qualify for promo (quantityNeeded)
-                    quantityNeeded = quantityNeeded.subtract(cartItem.addPromoQuantityCandidateUse(quantityNeeded,
productPromoCond, false));
+                    quantityNeeded = quantityNeeded.subtract(cartItem.addPromoQuantityCandidateUse(quantityNeeded,
productPromoCond, !"PPC_EQ".equals(operatorEnumId)));
                 }
             }
 
@@ -1743,7 +1744,13 @@ public class ProductPromoWorker {
             }
         } else if ("PROMO_ORDER_PERCENT".equals(productPromoActionEnumId)) {
             BigDecimal percentage = (productPromoAction.get("amount") == null ? BigDecimal.ZERO
: (productPromoAction.getBigDecimal("amount").movePointLeft(2))).negate();
-            BigDecimal amount = cart.getSubTotalForPromotions().multiply(percentage);
+            Set<String> productIds = ProductPromoWorker.getPromoRuleActionProductIds(productPromoAction,
delegator, nowTimestamp);
+            BigDecimal amount;
+            if (productIds.isEmpty()) {
+                amount = cart.getSubTotalForPromotions().multiply(percentage);
+            } else {
+                amount = cart.getSubTotalForPromotions(productIds).multiply(percentage);
+            }
             if (amount.compareTo(BigDecimal.ZERO) != 0) {
                 doOrderPromoAction(productPromoAction, cart, amount, "amount", delegator);
                 actionResultInfo.ranAction = true;
@@ -1969,7 +1976,6 @@ public class ProductPromoWorker {
         List<GenericValue> productPromoCategoriesAll = EntityQuery.use(delegator).from("ProductPromoCategory").where("productPromoId",
productPromoCond.get("productPromoId")).cache(true).queryList();
         List<GenericValue> productPromoCategories = EntityUtil.filterByAnd(productPromoCategoriesAll,
UtilMisc.toMap("productPromoRuleId", "_NA_", "productPromoCondSeqId", "_NA_"));
         productPromoCategories.addAll(EntityUtil.filterByAnd(productPromoCategoriesAll, UtilMisc.toMap("productPromoRuleId",
productPromoCond.get("productPromoRuleId"), "productPromoCondSeqId", productPromoCond.get("productPromoCondSeqId"))));
-
         List<GenericValue> productPromoProductsAll = EntityQuery.use(delegator).from("ProductPromoProduct").where("productPromoId",
productPromoCond.get("productPromoId")).cache(true).queryList();
         List<GenericValue> productPromoProducts = EntityUtil.filterByAnd(productPromoProductsAll,
UtilMisc.toMap("productPromoRuleId", "_NA_", "productPromoCondSeqId", "_NA_"));
         productPromoProducts.addAll(EntityUtil.filterByAnd(productPromoProductsAll, UtilMisc.toMap("productPromoRuleId",
productPromoCond.get("productPromoRuleId"), "productPromoCondSeqId", productPromoCond.get("productPromoCondSeqId"))));



Mime
View raw message