FEATURE: In makeItem(), move the production validation code to a separate helper method.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1482505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adam Heath
2013-05-14 18:09:08 +00:00
parent de328403ab
commit ff32c8ebda
@@ -415,58 +415,7 @@ public class ShoppingCartItem implements java.io.Serializable {
java.sql.Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
if (!skipProductChecks.booleanValue()) {
// check to see if introductionDate hasn't passed yet
if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_not_yet_available",
messageMap , cart.getLocale());
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
// check to see if salesDiscontinuationDate has passed
if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_no_longer_available",
messageMap , cart.getLocale());
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
/*
if (product.get("salesDiscWhenNotAvail") != null && "Y".equals(product.getString("salesDiscWhenNotAvail"))) {
// check atp and if <= 0 then the product is no more available because
// all the units in warehouse are reserved by other sales orders and no new purchase orders will be done
// for this product.
if (!newItem.isInventoryAvailableOrNotRequired(quantity, cart.getProductStoreId(), dispatcher)) {
Map messageMap = UtilMisc.toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_no_longer_available",
messageMap , cart.getLocale());
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
}
*/
// check to see if the product is fully configured
if ("AGGREGATED".equals(product.getString("productTypeId"))|| "AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) {
if (configWrapper == null || !configWrapper.isCompleted()) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_not_configured_correctly",
messageMap , cart.getLocale());
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
}
isValidCartProduct(configWrapper, product, nowTimestamp, cart.getLocale());
}
// check to see if the product is a rental item
@@ -592,6 +541,61 @@ public class ShoppingCartItem implements java.io.Serializable {
return product;
}
public static void isValidCartProduct(ProductConfigWrapper configWrapper, GenericValue product, Timestamp nowTimestamp, Locale locale) throws CartItemModifyException {
// check to see if introductionDate hasn't passed yet
if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_not_yet_available",
messageMap , locale);
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
// check to see if salesDiscontinuationDate has passed
if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_no_longer_available",
messageMap , locale);
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
/*
if (product.get("salesDiscWhenNotAvail") != null && "Y".equals(product.getString("salesDiscWhenNotAvail"))) {
// check atp and if <= 0 then the product is no more available because
// all the units in warehouse are reserved by other sales orders and no new purchase orders will be done
// for this product.
if (!newItem.isInventoryAvailableOrNotRequired(quantity, cart.getProductStoreId(), dispatcher)) {
Map messageMap = UtilMisc.toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_no_longer_available",
messageMap , locale);
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
}
*/
// check to see if the product is fully configured
if ("AGGREGATED".equals(product.getString("productTypeId"))|| "AGGREGATED_SERVICE".equals(product.getString("productTypeId"))) {
if (configWrapper == null || !configWrapper.isCompleted()) {
Map<String, Object> messageMap = UtilMisc.<String, Object>toMap("productName", product.getString("productName"),
"productId", product.getString("productId"));
String excMsg = UtilProperties.getMessage(resource_error, "item.cannot_add_product_not_configured_correctly",
messageMap , locale);
Debug.logWarning(excMsg, module);
throw new CartItemModifyException(excMsg);
}
}
}
/**
* Makes a non-product ShoppingCartItem and adds it to the cart.
* NOTE: This is only for non-product items; items without a product entity (work items, bulk items, etc)