[ofbiz-framework] branch trunk 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 trunk 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 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 18b83b9  Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791
18b83b9 is described below

commit 18b83b91c200dbdefc0d8dfba45412d492cdc8bb
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 cc13dc0..2089845 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
@@ -1817,6 +1817,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);
@@ -1855,7 +1856,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.
@@ -1874,7 +1874,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 c0a8f21..84126d2 100644
--- a/applications/order/template/entry/catalog/ProductDetail.ftl
+++ b/applications/order/template/entry/catalog/ProductDetail.ftl
@@ -491,7 +491,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>
@@ -534,7 +534,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 df18ed1..1240087 100644
--- a/applications/order/webapp/ordermgr/WEB-INF/controller.xml
+++ b/applications/order/webapp/ordermgr/WEB-INF/controller.xml
@@ -710,6 +710,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">