Fixed: Unable to add product (of ASSET_USAGE type) in order OFBIZ-10791

Thanks Priya for providing the patch
This commit is contained in:
Sebastian Berg
2021-02-15 17:56:35 +01:00
committed by Michael Brohl
parent dbecce6396
commit 18b83b91c2
3 changed files with 16 additions and 3 deletions
@@ -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)) {
@@ -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 />
@@ -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">