diff --git a/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java b/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java index 7208077fad..0823b64557 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java +++ b/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java @@ -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); + } + } } } } diff --git a/applications/order/src/org/ofbiz/order/order/OrderServices.java b/applications/order/src/org/ofbiz/order/order/OrderServices.java index 3b7d3bf58a..f52b28c440 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderServices.java @@ -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); diff --git a/applications/order/webapp/ordermgr/order/orderitems.ftl b/applications/order/webapp/ordermgr/order/orderitems.ftl index 03d1b7fb15..6b5af2283b 100644 --- a/applications/order/webapp/ordermgr/order/orderitems.ftl +++ b/applications/order/webapp/ordermgr/order/orderitems.ftl @@ -69,13 +69,13 @@ under the License. <#else> - <#if productId?exists> + <#if productId?has_content> <#assign product = orderItem.getRelatedOneCache("Product")>
<#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)>
${uiLabelMap.OrderItemDiscontinued}: ${product.salesDiscontinuationDate} <#elseif orderItemType?exists>