📄 productworker.java
字号:
try {
Map serviceContext = new HashMap();
serviceContext.put("productId", productId);
serviceContext.put("facilityId", inventoryFacilityId);
serviceContext.put("orderId", orderId);
serviceContext.put("orderItemSeqId", orderItemSeqId);
serviceContext.put("quantity", quantity);
if (requireInventory) {
serviceContext.put("requireInventory", "Y");
} else {
serviceContext.put("requireInventory", "N");
}
serviceContext.put("reserveOrderEnumId", reserveOrderEnumId);
serviceContext.put("userLogin", userLogin);
Map result = dispatcher.runSync("reserveProductInventoryByFacility", serviceContext);
quantityNotReserved = (Double) result.get("quantityNotReserved");
if (quantityNotReserved == null) {
Debug.logWarning("The reserveProductInventoryByFacility service returned a null quantityNotReserved, the error message was:\n" + result.get(ModelService.ERROR_MESSAGE), module);
return !requireInventory? null: new Double(0.0);
}
} catch (GenericServiceException e) {
Debug.logWarning(e, "Error invoking reserveProductInventoryByFacility service", module);
return !requireInventory? null: new Double(0.0);
}
// whew, finally here: now check to see if we were able to reserve...
if (quantityNotReserved.doubleValue() == 0) {
if (Debug.infoOn()) Debug.logInfo("Inventory IS reserved in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity was " + quantity, module);
return null;
} else {
if (Debug.infoOn()) Debug.logInfo("There is insufficient inventory available in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + ", amount could not reserve is " + quantityNotReserved, module);
return quantityNotReserved;
}
}
public static void getAssociatedProducts(PageContext pageContext, String productAttributeName, String assocPrefix) {
GenericDelegator delegator = (GenericDelegator) pageContext.getRequest().getAttribute("delegator");
GenericValue product = (GenericValue) pageContext.getAttribute(productAttributeName);
if (product == null)
return;
try {
List upgradeProducts = product.getRelatedByAndCache("MainProductAssoc",
UtilMisc.toMap("productAssocTypeId", "PRODUCT_UPGRADE"));
List complementProducts = product.getRelatedByAndCache("MainProductAssoc",
UtilMisc.toMap("productAssocTypeId", "PRODUCT_COMPLEMENT"));
List obsolescenceProducts = product.getRelatedByAndCache("AssocProductAssoc",
UtilMisc.toMap("productAssocTypeId", "PRODUCT_OBSOLESCENCE"));
List obsoleteByProducts = product.getRelatedByAndCache("MainProductAssoc",
UtilMisc.toMap("productAssocTypeId", "PRODUCT_OBSOLESCENCE"));
// since ProductAssoc records have a fromDate and thruDate, we can filter by now so that only assocs in the date range are included
upgradeProducts = EntityUtil.filterByDate(upgradeProducts, true);
complementProducts = EntityUtil.filterByDate(complementProducts, true);
obsolescenceProducts = EntityUtil.filterByDate(obsolescenceProducts, true);
obsoleteByProducts = EntityUtil.filterByDate(obsoleteByProducts, true);
if (upgradeProducts != null && upgradeProducts.size() > 0)
pageContext.setAttribute(assocPrefix + "upgrade", upgradeProducts);
if (complementProducts != null && complementProducts.size() > 0)
pageContext.setAttribute(assocPrefix + "complement", complementProducts);
if (obsolescenceProducts != null && obsolescenceProducts.size() > 0)
pageContext.setAttribute(assocPrefix + "obsolescence", obsolescenceProducts);
if (obsoleteByProducts != null && obsoleteByProducts.size() > 0)
pageContext.setAttribute(assocPrefix + "obsoleteby", obsoleteByProducts);
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
}
public static Map getOptionalProductFeatures(GenericDelegator delegator, String productId) {
Map featureMap = new OrderedMap();
List productFeatureAppls = null;
try {
productFeatureAppls = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "OPTIONAL_FEATURE"), UtilMisc.toList("productFeatureTypeId", "sequenceNum"));
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
if (productFeatureAppls != null) {
Iterator i = productFeatureAppls.iterator();
while (i.hasNext()) {
GenericValue appl = (GenericValue) i.next();
String featureType = appl.getString("productFeatureTypeId");
List features = (List) featureMap.get(featureType);
if (features == null) {
features = new LinkedList();
}
features.add(appl);
featureMap.put(featureType, features);
}
}
return featureMap;
}
// product calc methods
public static double calcOrderAdjustments(List orderHeaderAdjustments, double subTotal, boolean includeOther, boolean includeTax, boolean includeShipping) {
double adjTotal = 0.0;
if (orderHeaderAdjustments != null && orderHeaderAdjustments.size() > 0) {
List filteredAdjs = filterOrderAdjustments(orderHeaderAdjustments, includeOther, includeTax, includeShipping, false, false);
Iterator adjIt = filteredAdjs.iterator();
while (adjIt.hasNext()) {
GenericValue orderAdjustment = (GenericValue) adjIt.next();
adjTotal += calcOrderAdjustment(orderAdjustment, subTotal);
}
}
return adjTotal;
}
public static double calcOrderAdjustment(GenericValue orderAdjustment, double orderSubTotal) {
double adjustment = 0.0;
if (orderAdjustment.get("amount") != null) {
adjustment += orderAdjustment.getDouble("amount").doubleValue();
}
if (orderAdjustment.get("percentage") != null) {
adjustment += (orderAdjustment.getDouble("percentage").doubleValue() * orderSubTotal);
}
return adjustment;
}
public static List filterOrderAdjustments(List adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, boolean forTax, boolean forShipping) {
List newOrderAdjustmentsList = new LinkedList();
if (adjustments != null && adjustments.size() > 0) {
Iterator adjIt = adjustments.iterator();
while (adjIt.hasNext()) {
GenericValue orderAdjustment = (GenericValue) adjIt.next();
boolean includeAdjustment = false;
if ("SALES_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
if (includeTax) includeAdjustment = true;
} else if ("SHIPPING_CHARGES".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
if (includeShipping) includeAdjustment = true;
} else {
if (includeOther) includeAdjustment = true;
}
// default to yes, include for shipping; so only exclude if includeInShipping is N, or false; if Y or null or anything else it will be included
if (forTax && "N".equals(orderAdjustment.getString("includeInTax"))) {
includeAdjustment = false;
}
// default to yes, include for shipping; so only exclude if includeInShipping is N, or false; if Y or null or anything else it will be included
if (forShipping && "N".equals(orderAdjustment.getString("includeInShipping"))) {
includeAdjustment = false;
}
if (includeAdjustment) {
newOrderAdjustmentsList.add(orderAdjustment);
}
}
}
return newOrderAdjustmentsList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -