You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/10/03 10:35:06 UTC

svn commit: r821270 - /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

Author: jleroux
Date: Sat Oct  3 08:35:06 2009
New Revision: 821270

URL: http://svn.apache.org/viewvc?rev=821270&view=rev
Log:
A patch from Wickersheimer Jeremy "promotion giving gift items and inventory check." (https://issues.apache.org/jira/browse/OFBIZ-2991) - OFBIZ-2991

The code in the ProductPromoWorker should be checking if a git item is available before adding to the order, but it only checks the quantity in the inventory without taking into account the quantity already in the cart.

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

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=821270&r1=821269&r2=821270&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 Sat Oct  3 08:35:06 2009
@@ -1231,7 +1231,15 @@
                         // check inventory on this product, make sure it is available before going on
                         //NOTE: even though the store may not require inventory for purchase, we will always require inventory for gifts
                         try {
-                            Map invReqResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productId, "product", product, "quantity", quantity));
+                            // get the quantity in cart for inventory check
+                            BigDecimal quantityAlreadyInCart = BigDecimal.ZERO;
+                            if (cart != null) {
+                                List<ShoppingCartItem> matchingItems = cart.findAllCartItems(productId);
+                                for (ShoppingCartItem item : matchingItems) {
+                                    quantityAlreadyInCart = quantityAlreadyInCart.add(item.getQuantity());
+                                }
+                            }
+                            Map invReqResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productId, "product", product, "quantity", quantity.add(quantityAlreadyInCart)));
                             if (ServiceUtil.isError(invReqResult)) {
                                 Debug.logError("Error calling isStoreInventoryAvailable service, result is: " + invReqResult, module);
                                 throw new CartItemModifyException((String) invReqResult.get(ModelService.ERROR_MESSAGE));
@@ -1260,7 +1268,15 @@
                     String optionProductId = (String) optionProductIdIter.next();
 
                     try {
-                        Map invReqResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", optionProductId, "product", product, "quantity", quantity));
+                        // get the quantity in cart for inventory check
+                        BigDecimal quantityAlreadyInCart = BigDecimal.ZERO;
+                        if (cart != null) {
+                            List<ShoppingCartItem> matchingItems = cart.findAllCartItems(optionProductId);
+                            for (ShoppingCartItem item : matchingItems) {
+                                quantityAlreadyInCart = quantityAlreadyInCart.add(item.getQuantity());
+                            }
+                        }
+                        Map invReqResult = dispatcher.runSync("isStoreInventoryAvailable", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", optionProductId, "product", product, "quantity", quantity.add(quantityAlreadyInCart)));
                         if (ServiceUtil.isError(invReqResult)) {
                             Debug.logError("Error calling isStoreInventoryAvailable service, result is: " + invReqResult, module);
                             throw new CartItemModifyException((String) invReqResult.get(ModelService.ERROR_MESSAGE));