📄 orderreadhelper.java
字号:
}
}
}
}
return billingAddress;
}
public String getCurrentStatusString() {
GenericValue statusItem = null;
try {
statusItem = orderHeader.getRelatedOneCache("StatusItem");
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
if (statusItem != null) {
return statusItem.getString("description");
} else {
return orderHeader.getString("statusId");
}
}
public String getStatusString() {
List orderStatusList = this.getOrderHeaderStatuses();
if (orderStatusList == null) return "";
Iterator orderStatusIter = orderStatusList.iterator();
StringBuffer orderStatusIds = new StringBuffer(50);
boolean statusSet = false;
while (orderStatusIter.hasNext()) {
try {
GenericValue orderStatus = (GenericValue) orderStatusIter.next();
GenericValue statusItem = orderStatus.getRelatedOneCache("StatusItem");
if ( false == statusSet ) {
statusSet = true;
} else {
orderStatusIds.append( "/" );
}
if (statusItem != null) {
orderStatusIds.append(statusItem.getString("description"));
} else {
orderStatusIds.append(orderStatus.getString("statusId"));
}
} catch (GenericEntityException gee) {
Debug.logWarning(gee, module);
}
}
if (false == statusSet) {
orderStatusIds.append("(unspecified)");
}
return orderStatusIds.toString();
}
public GenericValue getBillingAccount() {
GenericValue billingAccount = null;
try {
billingAccount = orderHeader.getRelatedOne("BillingAccount");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
return billingAccount;
}
public GenericValue getBillToPerson() {
GenericDelegator delegator = orderHeader.getDelegator();
try {
GenericEntity billToRole = EntityUtil.getFirst(orderHeader.getRelatedByAnd("OrderRole", UtilMisc.toMap("roleTypeId", "BILL_TO_CUSTOMER")));
if (billToRole != null) {
return delegator.findByPrimaryKey("Person", UtilMisc.toMap("partyId", billToRole.getString("partyId")));
} else {
return null;
}
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
return null;
}
public GenericValue getPlacingParty() {
return this.getPartyFromRole("PLACING_CUSTOMER");
}
public GenericValue getSupplierAgent() {
return this.getPartyFromRole("SUPPLIER_AGENT");
}
public GenericValue getPartyFromRole(String roleTypeId) {
GenericDelegator delegator = orderHeader.getDelegator();
GenericValue partyObject = null;
try {
GenericValue orderRole = EntityUtil.getFirst(orderHeader.getRelatedByAnd("OrderRole", UtilMisc.toMap("roleTypeId", roleTypeId)));
if (orderRole != null) {
partyObject = delegator.findByPrimaryKey("Person", UtilMisc.toMap("partyId", orderRole.getString("partyId")));
if (partyObject == null) {
partyObject = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", orderRole.getString("partyId")));
}
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
return partyObject;
}
public String getDistributorId() {
GenericDelegator delegator = orderHeader.getDelegator();
try {
GenericEntity distributorRole = EntityUtil.getFirst(orderHeader.getRelatedByAnd("OrderRole", UtilMisc.toMap("roleTypeId", "DISTRIBUTOR")));
return distributorRole == null ? null : distributorRole.getString("partyId");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
return null;
}
public String getAffiliateId() {
GenericDelegator delegator = orderHeader.getDelegator();
try {
GenericEntity distributorRole = EntityUtil.getFirst(orderHeader.getRelatedByAnd("OrderRole", UtilMisc.toMap("roleTypeId", "AFFILIATE")));
return distributorRole == null ? null : distributorRole.getString("partyId");
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
}
return null;
}
public double getShippingTotal() {
return OrderReadHelper.calcOrderAdjustments(getOrderHeaderAdjustments(), getOrderItemsSubTotal(), false, false, true);
}
public Map getFeatureIdQtyMap() {
Map featureMap = new HashMap();
List validItems = getValidOrderItems();
if (validItems != null) {
Iterator i = validItems.iterator();
while (i.hasNext()) {
GenericValue item = (GenericValue) i.next();
List featureAppls = null;
if (item.get("productId") != null) {
try {
featureAppls = item.getDelegator().findByAndCache("ProductFeatureAppl", UtilMisc.toMap("productId", item.getString("productId")));
List filterExprs = UtilMisc.toList(new EntityExpr("productFeatureApplTypeId", EntityOperator.EQUALS, "STANDARD_FEATURE"));
filterExprs.add(new EntityExpr("productFeatureApplTypeId", EntityOperator.EQUALS, "REQUIRED_FEATURE"));
featureAppls = EntityUtil.filterByOr(featureAppls, filterExprs);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get ProductFeatureAppl for item : " + item, module);
}
if (featureAppls != null) {
Iterator fai = featureAppls.iterator();
while (fai.hasNext()) {
GenericValue appl = (GenericValue) fai.next();
Double lastQuantity = (Double) featureMap.get(appl.getString("productFeatureId"));
if (lastQuantity == null) {
lastQuantity = new Double(0);
}
Double newQuantity = new Double(lastQuantity.doubleValue() + getOrderItemQuantity(item).doubleValue());
featureMap.put(appl.getString("productFeatureId"), newQuantity);
}
}
}
// get the ADDITIONAL_FEATURE adjustments
List additionalFeatures = null;
try {
additionalFeatures = item.getRelatedByAnd("OrderAdjustment", UtilMisc.toMap("orderAdjustmentTypeId", "ADDITIONAL_FEATURE"));
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get OrderAdjustment from item : " + item, module);
}
if (additionalFeatures != null) {
Iterator afi = additionalFeatures.iterator();
while (afi.hasNext()) {
GenericValue adj = (GenericValue) afi.next();
String featureId = adj.getString("productFeatureId");
if (featureId != null) {
Double lastQuantity = (Double) featureMap.get(featureId);
if (lastQuantity == null) {
lastQuantity = new Double(0);
}
Double newQuantity = new Double(lastQuantity.doubleValue() + getOrderItemQuantity(item).doubleValue());
featureMap.put(featureId, newQuantity);
}
}
}
}
}
return featureMap;
}
public double getShippableTotal() {
double shippableTotal = 0.00;
List validItems = getValidOrderItems();
if (validItems != null) {
Iterator i = validItems.iterator();
while (i.hasNext()) {
GenericValue item = (GenericValue) i.next();
GenericValue product = null;
try {
product = item.getRelatedOne("Product");
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting Product from OrderItem; returning 0", module);
return 0.00;
}
if (product != null) {
if (ProductWorker.shippingApplies(product)) {
shippableTotal += OrderReadHelper.getOrderItemSubTotal(item, getAdjustments(), false, true);
}
}
}
}
return shippableTotal;
}
public double getShippableQuantity() {
double shippableQuantity = 0.00;
List validItems = getValidOrderItems();
if (validItems != null) {
Iterator i = validItems.iterator();
while (i.hasNext()) {
GenericValue item = (GenericValue) i.next();
GenericValue product = null;
try {
product = item.getRelatedOne("Product");
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting Product from OrderItem; returning 0", module);
return 0.00;
}
if (product != null) {
if (ProductWorker.shippingApplies(product)) {
shippableQuantity += getOrderItemQuantity(item).doubleValue();
}
}
}
}
return shippableQuantity;
}
public double getShippableWeight() {
GenericDelegator delegator = orderHeader.getDelegator();
double shippableWeight = 0.00;
List validItems = getValidOrderItems();
if (validItems != null) {
Iterator i = validItems.iterator();
while (i.hasNext()) {
GenericValue item = (GenericValue) i.next();
GenericValue product = null;
try {
product = item.getRelatedOne("Product");
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting Product from OrderItem; returning 0", module);
return 0.00;
}
if (product != null) {
if (ProductWorker.shippingApplies(product)) {
Double weight = product.getDouble("weight");
String isVariant = product.getString("isVariant");
if (weight == null && isVariant != null && "Y".equals(isVariant)) {
// get the virtual product and check its weight
GenericValue virtual = null;
try {
List virtuals = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", product.getString("productId"), "productAssocTypeId", "PRODUCT_VARIENT"), UtilMisc.toList("-fromDate"));
if (virtuals != null) {
virtuals = EntityUtil.filterByDate(virtuals);
}
virtual = EntityUtil.getFirst(virtuals);
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting virtual product");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -