[ofbiz-framework] branch release17.12 updated: Fixed: Unnecessary ship groups in orders. (OFBIZ-10489)

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

[ofbiz-framework] branch release17.12 updated: Fixed: Unnecessary ship groups in orders. (OFBIZ-10489)

akashjain
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/release17.12 by this push:
     new 8de770f  Fixed: Unnecessary ship groups in orders. (OFBIZ-10489)
8de770f is described below

commit 8de770f701189522d8910f5f6592c5cf94c4fd12
Author: akash <[hidden email]>
AuthorDate: Fri Feb 7 18:41:10 2020 +0530

    Fixed: Unnecessary ship groups in orders.
    (OFBIZ-10489)
   
    Thanks, Oleg Andreyev and Mohammad Kathawala for your contribution.
---
 .../order/shoppingcart/ShoppingCartHelper.java     | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java
index 8571758..4d919e7 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartHelper.java
@@ -840,7 +840,16 @@ public class ShoppingCartHelper {
                                         BigDecimal minQuantity = ShoppingCart.getMinimumOrderQuantity(delegator, item.getBasePrice(), item.getProductId());
                                         oldQuantity = item.getQuantity();
                                         if (oldQuantity.compareTo(quantity) != 0) {
-                                            cart.setShipmentMethodTypeId(index, null);
+                                            GenericValue product = item.getProduct();
+                                            //Reset shipment method information in cart only if shipping applies on product.
+                                            if (UtilValidate.isNotEmpty(product) && ProductWorker.shippingApplies(product)) {
+                                                for (int shipGroupIndex = 0; shipGroupIndex < cart.getShipGroupSize(); shipGroupIndex++) {
+                                                    String shipContactMechId = cart.getShippingContactMechId(shipGroupIndex);
+                                                    if (UtilValidate.isNotEmpty(shipContactMechId)) {
+                                                        cart.setShipmentMethodTypeId(shipGroupIndex, null);
+                                                    }
+                                                }
+                                            }
                                         }
                                         if (quantity.compareTo(minQuantity) < 0) {
                                             quantity = minQuantity;
@@ -924,7 +933,17 @@ public class ShoppingCartHelper {
             }
             try {
                 this.cart.removeCartItem(itemIndex, dispatcher);
-                cart.setShipmentMethodTypeId(itemIndex, null);
+                GenericValue product = item.getProduct();
+                //Reset shipment method information in cart only if shipping applies on product.
+                if (UtilValidate.isNotEmpty(product) && ProductWorker.shippingApplies(product)) {
+                    for (int shipGroupIndex = 0; shipGroupIndex < cart.getShipGroupSize(); shipGroupIndex++) {
+                        String shipContactMechId = cart.getShippingContactMechId(shipGroupIndex);
+                        if (UtilValidate.isNotEmpty(shipContactMechId)) {
+                            cart.setShipmentMethodTypeId(shipGroupIndex, null);
+                        }
+                    }
+                }
+
             } catch (CartItemModifyException e) {
                 result = ServiceUtil.returnError(new ArrayList<String>());
                 errorMsgs.add(e.getMessage());