📄 orderservices.java
字号:
}
// create the order status record
String orderStatusSeqId = delegator.getNextSeqId("OrderStatus").toString();
GenericValue orderStatus = delegator.makeValue("OrderStatus", UtilMisc.toMap("orderStatusId", orderStatusSeqId));
orderStatus.set("orderId", orderId);
orderStatus.set("statusId", order.getString("statusId"));
orderStatus.set("statusDatetime", nowTimestamp);
toBeStored.add(orderStatus);
// set the orderId on all adjustments; this list will include order and item adjustments...
List orderAdjustments = (List) context.get("orderAdjustments");
if (orderAdjustments != null && orderAdjustments.size() > 0) {
Iterator iter = orderAdjustments.iterator();
while (iter.hasNext()) {
GenericValue orderAdjustment = (GenericValue) iter.next();
Long adjSeqId = delegator.getNextSeqId("OrderAdjustment");
if (adjSeqId == null) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not get next sequence id for OrderAdjustment, cannot create order.");
return result;
}
orderAdjustment.set("orderAdjustmentId", adjSeqId.toString());
orderAdjustment.set("orderId", orderId);
if (orderAdjustment.get("orderItemSeqId") == null || orderAdjustment.getString("orderItemSeqId").length() == 0) {
orderAdjustment.set("orderItemSeqId", DataModelConstants.SEQ_ID_NA); // set the orderItemSeqId to _NA_ if not alredy set...
}
toBeStored.add(orderAdjustment);
}
}
// set the order contact mechs
List orderContactMechs = (List) context.get("orderContactMechs");
if (orderContactMechs != null && orderContactMechs.size() > 0) {
Iterator ocmi = orderContactMechs.iterator();
while (ocmi.hasNext()) {
GenericValue ocm = (GenericValue) ocmi.next();
ocm.set("orderId", orderId);
toBeStored.add(ocm);
}
}
// set the order item contact mechs
List orderItemContactMechs = (List) context.get("orderItemContactMechs");
if (orderItemContactMechs != null && orderItemContactMechs.size() > 0) {
Iterator oicmi = orderItemContactMechs.iterator();
while (oicmi.hasNext()) {
GenericValue oicm = (GenericValue) oicmi.next();
oicm.set("orderId", orderId);
toBeStored.add(oicm);
}
}
// set the shipment preferences
List orderShipmentPreferences = (List) context.get("orderShipmentPreferences");
if (orderShipmentPreferences != null && orderShipmentPreferences.size() > 0) {
Iterator oshprefs = orderShipmentPreferences.iterator();
while (oshprefs.hasNext()) {
GenericValue orderShipmentPreference = (GenericValue) oshprefs.next();
orderShipmentPreference.set("orderId", orderId);
orderShipmentPreference.set("carrierRoleTypeId", "CARRIER");
if (orderShipmentPreference.get("orderItemSeqId") == null || orderShipmentPreference.getString("orderItemSeqId").length() == 0) {
orderShipmentPreference.set("orderItemSeqId", DataModelConstants.SEQ_ID_NA); // set the orderItemSeqId to _NA_ if not alredy set...
}
toBeStored.add(orderShipmentPreference);
}
}
// set the order items
Iterator oi = orderItems.iterator();
while (oi.hasNext()) {
GenericValue orderItem = (GenericValue) oi.next();
orderItem.set("orderId", orderId);
toBeStored.add(orderItem);
// create the item status record
String itemStatusId = delegator.getNextSeqId("OrderStatus").toString();
GenericValue itemStatus = delegator.makeValue("OrderStatus", UtilMisc.toMap("orderStatusId", itemStatusId));
itemStatus.put("statusId", orderItem.get("statusId"));
itemStatus.put("orderId", orderId);
itemStatus.put("orderItemSeqId", orderItem.get("orderItemSeqId"));
itemStatus.put("statusDatetime", nowTimestamp);
toBeStored.add(itemStatus);
}
// set the item survey responses
List surveyResponses = (List) context.get("orderItemSurveyResponses");
if (surveyResponses != null && surveyResponses.size() > 0) {
Iterator oisr = surveyResponses.iterator();
while (oisr.hasNext()) {
GenericValue surveyResponse = (GenericValue) oisr.next();
surveyResponse.set("orderId", orderId);
toBeStored.add(surveyResponse);
}
}
// set the item price info; NOTE: this must be after the orderItems are stored for referential integrity
List orderItemPriceInfo = (List) context.get("orderItemPriceInfos");
if (orderItemPriceInfo != null && orderItemPriceInfo.size() > 0) {
Iterator oipii = orderItemPriceInfo.iterator();
while (oipii.hasNext()) {
GenericValue oipi = (GenericValue) oipii.next();
Long oipiSeqId = delegator.getNextSeqId("OrderItemPriceInfo");
if (oipiSeqId == null) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not get next sequence id for OrderItemPriceInfo, cannot create order.");
return result;
}
oipi.set("orderItemPriceInfoId", oipiSeqId.toString());
oipi.set("orderId", orderId);
toBeStored.add(oipi);
}
}
// store the orderProductPromoUseInfos
List orderProductPromoUses = (List) context.get("orderProductPromoUses");
if (orderProductPromoUses != null && orderProductPromoUses.size() > 0) {
Iterator orderProductPromoUseIter = orderProductPromoUses.iterator();
while (orderProductPromoUseIter.hasNext()) {
GenericValue productPromoUse = (GenericValue) orderProductPromoUseIter.next();
productPromoUse.set("orderId", orderId);
toBeStored.add(productPromoUse);
}
}
// define the roles for the order
List userOrderRoleTypes = null;
if ("SALES_ORDER".equals(orderTypeId)) {
userOrderRoleTypes = UtilMisc.toList("END_USER_CUSTOMER", "SHIP_TO_CUSTOMER", "BILL_TO_CUSTOMER", "PLACING_CUSTOMER");
} else if ("PURCHASE_ORDER".equals(orderTypeId)) {
userOrderRoleTypes = UtilMisc.toList("SHIP_FROM_VENDOR", "BILL_FROM_VENDOR", "SUPPLIER_AGENT");
} else if ("WORK_ORDER".equals(orderTypeId)) {
// TODO: set the work order roles
} else {
// TODO: some default behavior
}
// now add the roles
if (userOrderRoleTypes != null) {
Iterator i = userOrderRoleTypes.iterator();
while (i.hasNext()) {
String roleType = (String) i.next();
String thisParty = partyId;
if (thisParty == null) {
thisParty = "_NA_"; // will always set these roles so we can query
}
// make sure the party is in the role before adding
toBeStored.add(delegator.makeValue("PartyRole", UtilMisc.toMap("partyId", partyId, "roleTypeId", roleType)));
toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleType)));
}
}
// set the affiliate -- This is going to be removed...
String affiliateId = (String) context.get("affiliateId");
if (UtilValidate.isNotEmpty(affiliateId)) {
toBeStored.add(delegator.makeValue("OrderRole",
UtilMisc.toMap("orderId", orderId, "partyId", affiliateId, "roleTypeId", "AFFILIATE")));
}
// set the distributor
String distributorId = (String) context.get("distributorId");
if (UtilValidate.isNotEmpty(distributorId)) {
toBeStored.add(delegator.makeValue("OrderRole",
UtilMisc.toMap("orderId", orderId, "partyId", distributorId, "roleTypeId", "DISTRIBUTOR")));
}
// find all parties in role VENDOR associated with WebSite OR ProductStore (where WebSite overrides, if specified), associated first valid with the Order
if (UtilValidate.isNotEmpty((String) context.get("productStoreId"))) {
try {
List productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("roleTypeId", "VENDOR", "productStoreId", context.get("productStoreId")), UtilMisc.toList("-fromDate"));
productStoreRoles = EntityUtil.filterByDate(productStoreRoles, true);
GenericValue productStoreRole = EntityUtil.getFirst(productStoreRoles);
if (productStoreRole != null) {
toBeStored.add(delegator.makeValue("OrderRole",
UtilMisc.toMap("orderId", orderId, "partyId", productStoreRole.get("partyId"), "roleTypeId", "VENDOR")));
}
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up Vendor for the current Product Store", module);
}
}
if (UtilValidate.isNotEmpty((String) context.get("webSiteId"))) {
try {
List webSiteRoles = delegator.findByAnd("WebSiteRole", UtilMisc.toMap("roleTypeId", "VENDOR", "webSiteId", context.get("webSiteId")), UtilMisc.toList("-fromDate"));
webSiteRoles = EntityUtil.filterByDate(webSiteRoles, true);
GenericValue webSiteRole = EntityUtil.getFirst(webSiteRoles);
if (webSiteRole != null) {
toBeStored.add(delegator.makeValue("OrderRole",
UtilMisc.toMap("orderId", orderId, "partyId", webSiteRole.get("partyId"), "roleTypeId", "VENDOR")));
}
} catch (GenericEntityException e) {
Debug.logError(e, "Error looking up Vendor for the current Web Site", module);
}
}
// set the order payment preferences
List paymentPreferences = (List) context.get("orderPaymentPreferences");
if (paymentPreferences != null && paymentPreferences.size() > 0) {
Iterator oppIter = paymentPreferences.iterator();
while (oppIter.hasNext()) {
GenericValue paymentPreference = (GenericValue) oppIter.next();
if (paymentPreference.get("orderPaymentPreferenceId") == null)
paymentPreference.set("orderPaymentPreferenceId", delegator.getNextSeqId("OrderPaymentPreference").toString());
if (paymentPreference.get("statusId") == null)
paymentPreference.set("statusId", "PAYMENT_NOT_RECEIVED");
paymentPreference.set("orderId", orderId);
toBeStored.add(paymentPreference);
}
}
// store the trackingCodeOrder entities
List trackingCodeOrders = (List) context.get("trackingCodeOrders");
if (trackingCodeOrders != null && trackingCodeOrders.size() > 0) {
Iterator tkcdordIter = trackingCodeOrders.iterator();
while (tkcdordIter.hasNext()) {
GenericValue trackingCodeOrder = (GenericValue) tkcdordIter.next();
trackingCodeOrder.set("orderId", orderId);
toBeStored.add(trackingCodeOrder);
}
}
try {
// store line items, etc so that they will be there for the foreign key checks
delegator.storeAll(toBeStored);
if ("SALES_ORDER".equals(orderTypeId) || "WORK_ORDER".equals(orderTypeId)) {
// START inventory reservation
// decrement inventory available for each item, within the same transaction
List resErrorMessages = new LinkedList();
Iterator invDecItemIter = orderItems.iterator();
while (invDecItemIter.hasNext()) {
GenericValue orderItem = (GenericValue) invDecItemIter.next();
if (orderItem.get("productId") != null) {
// only reserve product items; ignore non-product items
Double inventoryNotReserved = ProductStoreWorker.reserveStoreInventory(productStoreId,
orderItem.getString("productId"), orderItem.getDouble("quantity"),
orderItem.getString("orderId"), orderItem.getString("orderItemSeqId"),
userLogin, delegator, dispatcher);
if (inventoryNotReserved != null) {
// if inventoryNotReserved is not 0.0 then that is the amount that it couldn't reserve
GenericValue product = null;
try {
product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", orderItem.getString("productId")));
} catch (GenericEntityException e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -