[ofbiz-framework] branch trunk updated: Fixed: Order processing issue for dropship only products (OFBIZ-12068)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Fixed: Order processing issue for dropship only products (OFBIZ-12068)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new afacb3a  Fixed: Order processing issue for dropship only products (OFBIZ-12068)
afacb3a is described below

commit afacb3ab43ef68e54c95f4242d7e4aef44dc9ee4
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Tue Apr 27 12:07:49 2021 +0200

    Fixed: Order processing issue for dropship only products (OFBIZ-12068)
   
    When a dropship only (or dropship on low ATP) product with no qualified supplier
    added to shopping cart and cart converted to sales order. System should return
    errors and should not create sales order.
   
    Thanks: Amit Gadaley
---
 .../order/groovyScripts/entry/CheckoutOptions.groovy   |  9 +++++++--
 .../ofbiz/order/shoppingcart/CheckOutEvents.java       | 14 ++++++++++++--
 .../apache/ofbiz/order/shoppingcart/ShoppingCart.java  | 18 +++++++++++++-----
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/applications/order/groovyScripts/entry/CheckoutOptions.groovy b/applications/order/groovyScripts/entry/CheckoutOptions.groovy
index 280148a..e018ea3 100644
--- a/applications/order/groovyScripts/entry/CheckoutOptions.groovy
+++ b/applications/order/groovyScripts/entry/CheckoutOptions.groovy
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
+import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.party.contact.ContactHelper;
 import org.apache.ofbiz.product.store.ProductStoreWorker
 import org.apache.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper;
@@ -33,7 +33,12 @@ if (shoppingCart) {
     context.shippingEstWpr = shippingEstWpr
     context.carrierShipmentMethodList = shippingEstWpr.getShippingMethods()
     // Reassign items requiring drop-shipping to new or existing drop-ship groups
-    shoppingCart.createDropShipGroups(dispatcher)
+    Map<String, Object> createDropShipGroupResult = shoppingCart.createDropShipGroups(dispatcher)
+    if ("error".equals(createDropShipGroupResult.get("responseMessage"))) {
+        Debug.logError((String)createDropShipGroupResult.get("errorMessage"), module)
+        request.setAttribute("_ERROR_MESSAGE_", (String)createDropShipGroupResult.get("errorMessage"))
+        return "error"
+    }
 }
 
 profiledefs = from("PartyProfileDefault").where("partyId", userLogin.partyId, "productStoreId", productStoreId).queryOne()
diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java
index 2671ea3..d51273f 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java
@@ -93,7 +93,12 @@ public class CheckOutEvents {
         }
         if (curPage == null) {
             try {
-                cart.createDropShipGroups(dispatcher);
+                Map<String, Object> createDropShipGroupResult = cart.createDropShipGroups(dispatcher);
+                if ("error".equals(createDropShipGroupResult.get("responseMessage"))) {
+                    Debug.logError((String) createDropShipGroupResult.get("errorMessage"), MODULE);
+                    request.setAttribute("_ERROR_MESSAGE_", (String) createDropShipGroupResult.get("errorMessage"));
+                    return "error";
+                }
             } catch (CartItemModifyException e) {
                 Debug.logError(e, MODULE);
             }
@@ -778,7 +783,12 @@ public class CheckOutEvents {
         // Reassign items requiring drop-shipping to new or existing drop-ship groups
         if ("init".equals(mode) || "default".equals(mode)) {
             try {
-                cart.createDropShipGroups(dispatcher);
+                Map<String, Object> createDropShipGroupResult = cart.createDropShipGroups(dispatcher);
+                if ("error".equals(createDropShipGroupResult.get("responseMessage"))) {
+                    Debug.logError((String) createDropShipGroupResult.get("errorMessage"), MODULE);
+                    request.setAttribute("_ERROR_MESSAGE_", (String) createDropShipGroupResult.get("errorMessage"));
+                    return "error";
+                }
             } catch (CartItemModifyException e) {
                 Debug.logError(e, MODULE);
             }
diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
index d0fad01..d8e9885 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
@@ -4878,7 +4878,7 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable {
      * @param dispatcher
      * @throws CartItemModifyException
      */
-    public void createDropShipGroups(LocalDispatcher dispatcher) throws CartItemModifyException {
+    public Map<String, Object> createDropShipGroups(LocalDispatcher dispatcher) throws CartItemModifyException {
 
         // Retrieve the facilityId from the cart's productStoreId because ShoppingCart.setFacilityId() doesn't seem to be used anywhere
         String facilityId = null;
@@ -4891,13 +4891,14 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable {
                 storeRequirementMethodEnumId = productStore.getString("requirementMethodEnumId");
             } catch (GenericEntityException gee) {
                 Debug.logError(UtilProperties.getMessage(RES_ERROR, "OrderProblemGettingProductStoreRecords", locale) + gee.getMessage(), MODULE);
-                return;
+                return ServiceUtil.returnError(
+                    UtilProperties.getMessage(RES_ERROR, "OrderProblemGettingProductStoreRecords", locale) + gee.getMessage());
             }
         }
 
         List<CartShipInfo> shipGroups = getShipGroups();
         if (shipGroups == null) {
-            return;
+            return ServiceUtil.returnSuccess();
         }
 
         // Intermediate structure supplierPartyId -> { ShoppingCartItem = { originalShipGroupIndex = dropShipQuantity } }
@@ -4965,7 +4966,7 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable {
                         if (ServiceUtil.isError(getProductInventoryAvailableResult)) {
                             String errorMessage = ServiceUtil.getErrorMessage(getProductInventoryAvailableResult);
                             Debug.logError(errorMessage, MODULE);
-                            return;
+                            return ServiceUtil.returnError(errorMessage);
                         }
                         BigDecimal availableToPromise = (BigDecimal) getProductInventoryAvailableResult.get("availableToPromiseTotal");
 
@@ -4998,10 +4999,16 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable {
                     if (ServiceUtil.isError(getSuppliersForProductResult)) {
                         String errorMessage = ServiceUtil.getErrorMessage(getSuppliersForProductResult);
                         Debug.logError(errorMessage, MODULE);
-                        return;
+                        return ServiceUtil.returnError(errorMessage);
                     }
+
                     List<GenericValue> supplierProducts = UtilGenerics.cast(getSuppliersForProductResult.get("supplierProducts"));
 
+                    if (supplierProducts.isEmpty()) {
+                        return ServiceUtil.returnError(
+                            "Sorry! No supplier available to droship product #" + productId + " with quantity "
+                            + dropShipQuantity + " and currency " + getCurrency());
+                    }
                     // Order suppliers by supplierPrefOrderId so that preferred suppliers are used first
                     supplierProducts = EntityUtil.orderBy(supplierProducts, UtilMisc.toList("supplierPrefOrderId"));
                     GenericValue supplierProduct = EntityUtil.getFirst(supplierProducts);
@@ -5062,6 +5069,7 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable {
                 }
             }
         }
+        return ServiceUtil.returnSuccess();
     }
 
     static class BasePriceOrderComparator implements Comparator<Object>, Serializable {