This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/release18.12 by this push: new 4d39ab2 Fixed: Order processing issue for dropship only products (OFBIZ-12068) 4d39ab2 is described below commit 4d39ab2f1f09433caa383326c17308a353f8c219 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 Conflicts handled by hand ShoppingCart.java and despite Auto-merging applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutEvents.java CheckOutEvents.java too --- .../order/groovyScripts/entry/CheckoutOptions.groovy | 9 +++++++-- .../ofbiz/order/shoppingcart/CheckOutEvents.java | 14 ++++++++++++-- .../ofbiz/order/shoppingcart/ShoppingCart.java | 20 ++++++++++++++------ 3 files changed, 33 insertions(+), 10 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 61cc749..0948b41 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 @@ -92,7 +92,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); } @@ -764,7 +769,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 60a91d4..b12411b 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 @@ -4233,7 +4233,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; @@ -4245,13 +4245,14 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable { storeRequirementMethodEnumId = productStore.getString("requirementMethodEnumId"); } catch (GenericEntityException gee) { Debug.logError(UtilProperties.getMessage(resource_error,"OrderProblemGettingProductStoreRecords", locale) + gee.getMessage(), module); - return; + return ServiceUtil.returnError( + UtilProperties.getMessage(resource_error, "OrderProblemGettingProductStoreRecords", locale) + gee.getMessage()); } } List<CartShipInfo> shipGroups = getShipGroups(); if (shipGroups == null) { - return; + return ServiceUtil.returnSuccess(); } // Intermediate structure supplierPartyId -> { ShoppingCartItem = { originalShipGroupIndex = dropShipQuantity } } to collect drop-shippable items @@ -4316,7 +4317,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"); @@ -4346,10 +4347,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.checkList(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); @@ -4409,6 +4416,7 @@ public class ShoppingCart implements Iterable<ShoppingCartItem>, Serializable { } } } + return ServiceUtil.returnSuccess(); } static class BasePriceOrderComparator implements Comparator<Object>, Serializable { |
Free forum by Nabble | Edit this page |