Author: doogie
Date: Tue May 14 18:09:02 2013
New Revision: 1482504

URL: http://svn.apache.org/r1482504
Log:
FEATURE: In makeItem(), move the product lookup code into it's own helper 
method.

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

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=1482504&r1=1482503&r2=1482504&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
 Tue May 14 18:09:02 2013
@@ -319,34 +319,9 @@ public class ShoppingCartItem implements
             String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, 
LocalDispatcher dispatcher, ShoppingCart cart, Boolean triggerExternalOpsBool, 
Boolean triggerPriceRulesBool, String parentProductId, Boolean 
skipInventoryChecks, Boolean skipProductChecks)
             throws CartItemModifyException, ItemNotFoundException {
         Delegator delegator = cart.getDelegator();
-        GenericValue product = null;
+        GenericValue product = findProduct(delegator, 
skipProductChecks.booleanValue(), prodCatalogId, productId, cart.getLocale());
         GenericValue parentProduct = null;
 
-        try {
-            product = delegator.findOne("Product", UtilMisc.toMap("productId", 
productId), true);
-
-            // first see if there is a purchase allow category and if this 
product is in it or not
-            String purchaseProductCategoryId = 
CatalogWorker.getCatalogPurchaseAllowCategoryId(delegator, prodCatalogId);
-            if (!skipProductChecks.booleanValue() && product != null && 
purchaseProductCategoryId != null) {
-                if (!CategoryWorker.isProductInCategory(delegator, 
product.getString("productId"), purchaseProductCategoryId)) {
-                    // a Purchase allow productCategoryId was found, but the 
product is not in the category, axe it...
-                    Debug.logWarning("Product [" + productId + "] is not in 
the purchase allow category [" + purchaseProductCategoryId + "] and cannot be 
purchased", module);
-                    product = null;
-                }
-            }
-        } catch (GenericEntityException e) {
-            Debug.logWarning(e.toString(), module);
-            product = null;
-        }
-
-        if (product == null) {
-            Map<String, Object> messageMap = UtilMisc.<String, 
Object>toMap("productId", productId);
-            String excMsg = UtilProperties.getMessage(resource_error, 
"item.product_not_found", messageMap , cart.getLocale());
-
-            Debug.logWarning(excMsg, module);
-            throw new ItemNotFoundException(excMsg);
-        }
-
         if (parentProductId != null)
         {
             try
@@ -587,6 +562,36 @@ public class ShoppingCartItem implements
         return newItem;
     }
 
+    public static GenericValue findProduct(Delegator delegator, boolean 
skipProductChecks, String prodCatalogId, String productId, Locale locale) 
throws CartItemModifyException, ItemNotFoundException {
+        GenericValue product;
+
+        try {
+            product = delegator.findOne("Product", UtilMisc.toMap("productId", 
productId), true);
+
+            // first see if there is a purchase allow category and if this 
product is in it or not
+            String purchaseProductCategoryId = 
CatalogWorker.getCatalogPurchaseAllowCategoryId(delegator, prodCatalogId);
+            if (!skipProductChecks && product != null && 
purchaseProductCategoryId != null) {
+                if (!CategoryWorker.isProductInCategory(delegator, 
product.getString("productId"), purchaseProductCategoryId)) {
+                    // a Purchase allow productCategoryId was found, but the 
product is not in the category, axe it...
+                    Debug.logWarning("Product [" + productId + "] is not in 
the purchase allow category [" + purchaseProductCategoryId + "] and cannot be 
purchased", module);
+                    product = null;
+                }
+            }
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e.toString(), module);
+            product = null;
+        }
+
+        if (product == null) {
+            Map<String, Object> messageMap = UtilMisc.<String, 
Object>toMap("productId", productId);
+            String excMsg = UtilProperties.getMessage(resource_error, 
"item.product_not_found", messageMap , locale);
+
+            Debug.logWarning(excMsg, module);
+            throw new ItemNotFoundException(excMsg);
+        }
+        return product;
+    }
+
     /**
      * Makes a non-product ShoppingCartItem and adds it to the cart.
      * NOTE: This is only for non-product items; items without a product 
entity (work items, bulk items, etc)


Reply via email to