updated to support non-product items

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@522986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Zeneski
2007-03-27 16:24:50 +00:00
parent 4e84bfb4ea
commit 95d97a67eb
3 changed files with 62 additions and 21 deletions
@@ -192,6 +192,7 @@ public class OrderChangeHelper {
GenericValue orderItem = (GenericValue) oii.next();
String orderItemSeqId = orderItem.getString("orderItemSeqId");
GenericValue product = null;
try {
product = orderItem.getRelatedOne("Product");
} catch (GenericEntityException e) {
@@ -215,6 +216,16 @@ public class OrderChangeHelper {
}
}
}
} else {
String orderItemType = orderItem.getString("orderItemTypeId");
if (!"PRODUCT_ORDER_ITEM".equals(orderItemType)) {
// non-product items don't ship; treat as a digital item
Map digitalStatusFields = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "statusId", digitalItemStatus, "userLogin", userLogin);
Map digitalStatusChange = dispatcher.runSync("changeOrderItemStatus", digitalStatusFields);
if (ModelService.RESPOND_ERROR.equals(digitalStatusChange.get(ModelService.RESPONSE_MESSAGE))) {
Debug.logError("Problems with digital product status change : " + product, module);
}
}
}
}
}
@@ -2637,9 +2637,11 @@ public class OrderServices {
}
}
// find any digital goods
Map digitalProducts = new HashMap();
// find any digital or non-product items
List nonProductItems = new ArrayList();
List digitalItems = new ArrayList();
Map digitalProducts = new HashMap();
if (orderItems != null && orderItems.size() > 0) {
Iterator i = orderItems.iterator();
while (i.hasNext()) {
@@ -2674,26 +2676,36 @@ public class OrderServices {
}
}
}
} else {
String itemType = item.getString("orderItemTypeId");
if (!"PRODUCT_ORDER_ITEM".equals(itemType)) {
nonProductItems.add(item);
}
}
}
}
// now process the digital items
if (digitalItems.size() > 0) {
if (digitalItems.size() > 0 || nonProductItems.size() > 0) {
GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);
boolean invoiceItems = true;
if (productStore != null && productStore.get("autoInvoiceDigitalItems") != null) {
invoiceItems = "Y".equalsIgnoreCase(productStore.getString("autoInvoiceDigitalItems"));
}
// single list with all invoice items
List itemsToInvoice = FastList.newInstance();
itemsToInvoice.addAll(nonProductItems);
itemsToInvoice.addAll(digitalItems);
if (invoiceItems) {
// invoice all APPROVED digital goods
// invoice all APPROVED digital/non-product goods
// do something tricky here: run as a different user that can actually create an invoice, post transaction, etc
Map invoiceResult = null;
try {
GenericValue permUserLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
Map invoiceContext = UtilMisc.toMap("orderId", orderId, "billItems", digitalItems, "userLogin", permUserLogin);
Map invoiceContext = UtilMisc.toMap("orderId", orderId, "billItems", itemsToInvoice, "userLogin", permUserLogin);
invoiceResult = dispatcher.runSync("createInvoiceForOrder", invoiceContext);
} catch (GenericEntityException e) {
Debug.logError(e, "ERROR: Unable to invoice digital items", module);
@@ -2707,11 +2719,12 @@ public class OrderServices {
}
// update the status of digital goods to COMPLETED; leave physical/digital as APPROVED for pick/ship
Iterator dii = digitalItems.iterator();
Iterator dii = itemsToInvoice.iterator();
while (dii.hasNext()) {
GenericValue productType = null;
GenericValue item = (GenericValue) dii.next();
GenericValue product = (GenericValue) digitalProducts.get(item);
boolean markComplete = false;
if (product != null) {
try {
@@ -2719,6 +2732,11 @@ public class OrderServices {
} catch (GenericEntityException e) {
Debug.logError(e, "ERROR: Unable to get ProductType from Product", module);
}
} else {
String itemType = item.getString("orderItemTypeId");
if (!"PRODUCT_ORDER_ITEM".equals(itemType)) {
markComplete = true;
}
}
if (product != null && productType != null) {
@@ -2726,18 +2744,22 @@ public class OrderServices {
String isDigital = productType.getString("isDigital");
// we were set as a digital good; one more check and change status
if ((isDigital != null && "Y".equalsIgnoreCase(isDigital)) && (
isPhysical == null || !"Y".equalsIgnoreCase(isPhysical))) {
Map statusCtx = new HashMap();
statusCtx.put("orderId", item.getString("orderId"));
statusCtx.put("orderItemSeqId", item.getString("orderItemSeqId"));
statusCtx.put("statusId", "ITEM_COMPLETED");
statusCtx.put("userLogin", userLogin);
try {
dispatcher.runSyncIgnore("changeOrderItemStatus", statusCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "ERROR: Problem setting the status to COMPLETED : " + item, module);
}
if ((isDigital != null && "Y".equalsIgnoreCase(isDigital)) &&
(isPhysical == null || !"Y".equalsIgnoreCase(isPhysical))) {
markComplete = true;
}
}
if (markComplete) {
Map statusCtx = new HashMap();
statusCtx.put("orderId", item.getString("orderId"));
statusCtx.put("orderItemSeqId", item.getString("orderItemSeqId"));
statusCtx.put("statusId", "ITEM_COMPLETED");
statusCtx.put("userLogin", userLogin);
try {
dispatcher.runSyncIgnore("changeOrderItemStatus", statusCtx);
} catch (GenericServiceException e) {
Debug.logError(e, "ERROR: Problem setting the status to COMPLETED : " + item, module);
}
}
}
@@ -4012,6 +4034,14 @@ public class OrderServices {
// set the payment method
cart.addPayment(paymentMethodId);
// store the order
CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
Map createResp = coh.createOrder(userLogin);
if (ServiceUtil.isError(createResp)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(createResp));
}
// process the payment
Map procCtx = FastMap.newInstance();
procCtx.put("shoppingCart", cart);
procCtx.put("userLogin", userLogin);
@@ -69,13 +69,13 @@ under the License.
</td>
<#else>
<td valign="top">
<#if productId?exists>
<#if productId?has_content>
<#assign product = orderItem.getRelatedOneCache("Product")>
</#if>
<div class="tabletext">
<#if productId?exists>
${orderItem.productId?default("N/A")} - ${orderItem.itemDescription?if_exists}
<#if product.salesDiscontinuationDate?exists && Static["org.ofbiz.base.util.UtilDateTime"].nowTimestamp().after(product.salesDiscontinuationDate)>
<#if (product.salesDiscontinuationDate)?exists && Static["org.ofbiz.base.util.UtilDateTime"].nowTimestamp().after(product.salesDiscontinuationDate)>
<br/><span style="color: red;">${uiLabelMap.OrderItemDiscontinued}: ${product.salesDiscontinuationDate}</span>
</#if>
<#elseif orderItemType?exists>