public static Map<String, Object> assembleCrmsfaOrderFormMergeContext( Delegator delegator, String orderId) { Map<String, Object> templateContext = new HashMap<String, Object>(); if (UtilValidate.isNotEmpty(orderId)) { try { OrderReadHelper orh = new OrderReadHelper(delegator, orderId); templateContext.put("orderId", orderId); templateContext.put("externalOrderId", orh.getOrderHeader().get("externalId")); templateContext.put("orderDate", orh.getOrderHeader().getTimestamp("orderDate")); GenericValue billingParty = orh.getBillToParty(); if (UtilValidate.isNotEmpty(billingParty)) { if ("Person".equalsIgnoreCase(billingParty.getEntityName())) { templateContext.put("orderBillingFirstName", billingParty.get("firstName")); templateContext.put("orderBillingLastName", billingParty.get("lastName")); } templateContext.put("orderPartyId", billingParty.get("partyId")); templateContext.put( "orderBillingFullName", org.ofbiz.party.party.PartyHelper.getPartyName(billingParty, false)); } templateContext.put("orderSubtotal", orh.getOrderItemsSubTotal()); templateContext.put("orderTaxTotal", orh.getTaxTotal()); templateContext.put("orderShippingTotal", orh.getShippingTotal()); templateContext.put("orderGrandTotal", orh.getOrderGrandTotal()); templateContext.put( "orderPaymentTotal", orh.getOrderGrandTotal().subtract(UtilOrder.getOrderOpenAmount(orh))); GenericValue shippingParty = orh.getShipToParty(); if (UtilValidate.isNotEmpty(shippingParty)) { if ("Person".equalsIgnoreCase(shippingParty.getEntityName())) { templateContext.put("orderShippingFirstName", shippingParty.get("firstName")); templateContext.put("orderShippingLastName", shippingParty.get("lastName")); } else { templateContext.put("orderShippingCompanyName", shippingParty.get("groupName")); } templateContext.put( "orderShippingFullName", org.ofbiz.party.party.PartyHelper.getPartyName(shippingParty, false)); } List<GenericValue> orderItemVals = orh.getOrderItems(); List<Map<String, Object>> orderItems = new ArrayList<Map<String, Object>>(); for (GenericValue orderItemVal : orderItemVals) { Map<String, Object> orderItem = orderItemVal.getAllFields(); GenericValue product = orderItemVal.getRelatedOne("Product"); if (UtilValidate.isEmpty(product)) { continue; } for (String fieldName : (Set<String>) product.keySet()) { orderItem.put(fieldName, product.get(fieldName)); } orderItems.add(orderItem); } templateContext.put("orderItems", orderItems); } catch (GenericEntityException e) { Debug.logError(e, MODULE); } } return templateContext; }