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 2018/12/06 07:24:13 UTC

svn commit: r1848263 - /ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java

Author: jleroux
Date: Thu Dec  6 07:24:13 2018
New Revision: 1848263

URL: http://svn.apache.org/viewvc?rev=1848263&view=rev
Log:
Fixed: Error on createShoppingListItem when adding item to cart as anonymous
(OFBIZ-5157)

It can be reproduced by setting the product_store field autoSaveCart to 'Y' 
(In Store 9000 for the demo-data). Then the error occurs upon the first visit of 
the ecommerce-site, provided the user is not logged in.

    First Visit: no userLogin
    OFBiz wants to autosave list
    saving list requires userLogin (forsecuritycheck)
    result: error

Thanks: Mirko Vogelsmeier for report, Benjamin Jugl for the fix

Modified:
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java?rev=1848263&r1=1848262&r2=1848263&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppinglist/ShoppingListEvents.java Thu Dec  6 07:24:13 2018
@@ -444,25 +444,24 @@ public class ShoppingListEvents {
         Delegator delegator = (Delegator) request.getAttribute("delegator");
         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
         GenericValue productStore = ProductStoreWorker.getProductStore(request);
-
-        if (!ProductStoreWorker.autoSaveCart(productStore)) {
-            // if auto-save is disabled just return here
-            return "success";
-        }
-
         HttpSession session = request.getSession();
         ShoppingCart cart = ShoppingCartEvents.getCartObject(request);
 
-        // safety check for missing required parameter.
-        if (cart.getWebSiteId() == null) {
-            cart.setWebSiteId(WebSiteWorker.getWebSiteId(request));
-        }
-
         // locate the user's identity
         GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
         if (userLogin == null) {
             userLogin = (GenericValue) session.getAttribute("autoUserLogin");
         }
+        
+        if (!ProductStoreWorker.autoSaveCart(productStore) || userLogin == null) {
+            // if auto-save is disabled or there is still no userLogin just return here
+            return "success";
+        }
+
+        // safety check for missing required parameter.
+        if (cart.getWebSiteId() == null) {
+            cart.setWebSiteId(WebSiteWorker.getWebSiteId(request));
+        }
 
         // find the list ID
         String autoSaveListId = cart.getAutoSaveListId();
@@ -650,7 +649,7 @@ public class ShoppingListEvents {
         }
 
         // clear the auto-save info
-        if (ProductStoreWorker.autoSaveCart(delegator, productStoreId)) {
+        if (userLogin!= null && ProductStoreWorker.autoSaveCart(delegator, productStoreId)) {
             if (UtilValidate.isEmpty(autoSaveListId)) {
                 try {
                     Map<String, Object> listFields = UtilMisc.<String, Object>toMap("userLogin", userLogin, "productStoreId", productStoreId, "shoppingListTypeId", "SLT_SPEC_PURP", "listName", PERSISTANT_LIST_NAME);