[ofbiz-framework] branch release18.12 updated: Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791

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

[ofbiz-framework] branch release18.12 updated: Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791

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

mbrohl 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 f9fc00a  Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791
f9fc00a is described below

commit f9fc00ad3b556e14c812ffa7033fe5be65884519
Author: Sebastian Berg <[hidden email]>
AuthorDate: Mon Feb 15 15:57:28 2021 +0100

    Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791
   
    Thanks Priya for providing the patch
---
 .../apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java | 13 +++++++++++--
 applications/order/template/entry/catalog/ProductDetail.ftl |  5 ++++-
 applications/order/webapp/ordermgr/WEB-INF/controller.xml   |  1 +
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java
index 4550011..b041394 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartEvents.java
@@ -1804,6 +1804,7 @@ public class ShoppingCartEvents {
         String catalogId = CatalogWorker.getCurrentCatalogId(request);
         String itemType = null;
         String itemDescription = "";
+        Locale locale = UtilHttp.getLocale(request);
 
         // Get the parameters as a MAP, remove the productId and quantity params.
         Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
@@ -1842,7 +1843,6 @@ public class ShoppingCartEvents {
                     Debug.logWarning(e, "Problems parsing quantity string: " + quantityStr, module);
                     quantity = BigDecimal.ZERO;
                 }
-
                 try {
                     //For quantity we should test if we allow to add decimal quantity for this product an productStore :
                     // if not and if quantity is in decimal format then return error.
@@ -1861,7 +1861,16 @@ public class ShoppingCartEvents {
                     Debug.logWarning(e.getMessage(), module);
                     quantity = BigDecimal.ONE;
                 }
-
+                // get the renting data if the product quanity is more than 0
+                if (quantity.compareTo(BigDecimal.ZERO) > 0) {
+                    if ("ASSET_USAGE".equals(ProductWorker.getProductTypeId(delegator, productId))
+                            || "ASSET_USAGE_OUT_IN".equals(ProductWorker.getProductTypeId(delegator, productId))) {
+                        request.setAttribute("product_id", productId);
+                        request.setAttribute("_EVENT_MESSAGE_",
+                                UtilProperties.getMessage(RES_ERROR, "cart.addToCart.enterBookingInforamtionBeforeAddingToCart", locale));
+                        return "product";
+                    }
+                }
                 // get the selected amount
                 String selectedAmountStr = null;
                 if (paramMap.containsKey("amount" + thisSuffix)) {
diff --git a/applications/order/template/entry/catalog/ProductDetail.ftl b/applications/order/template/entry/catalog/ProductDetail.ftl
index 0471364..f32fb00 100644
--- a/applications/order/template/entry/catalog/ProductDetail.ftl
+++ b/applications/order/template/entry/catalog/ProductDetail.ftl
@@ -493,7 +493,7 @@ ${variantInfoJavaScript!}
             </#if>
           </#if>
         </#if>
-      </td></tr><tr><td colspan="2" align="right">
+      <div>
         <#-- check to see if introductionDate hasnt passed yet -->
         <#if product.introductionDate?? && nowTimestamp.before(product.introductionDate)>
         <p>&nbsp;</p>
@@ -536,7 +536,10 @@ ${variantInfoJavaScript!}
             <input type="hidden" name="category_id" value="${requestParameters.category_id}"/>
           </#if>
         </#if>
+      </div>
       </form>
+      </td></tr>
+      <tr><td colspan="2" align="right">
     <div>
       <#if sessionAttributes.userLogin?has_content && sessionAttributes.userLogin.userLoginId != "anonymous">
         <hr />
diff --git a/applications/order/webapp/ordermgr/WEB-INF/controller.xml b/applications/order/webapp/ordermgr/WEB-INF/controller.xml
index 21b490f..28272ea 100644
--- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml
+++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml
@@ -704,6 +704,7 @@ under the License.
         <event type="java" path="org.apache.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="bulkAddProducts"/>
         <response name="success" type="request" value="orderentry"/>
         <response name="error" type="request" value="orderentry"/>
+        <response name="product" type="view" value="product"/>
     </request-map>
 
     <request-map uri="bulkAddProductsInApprovedOrder">