📄 checkouthelper.java
字号:
storeResult = dispatcher.runSync("storeOrder", context); orderId = (String) storeResult.get("orderId"); if (orderId != null && orderId.length() > 0) { this.cart.setOrderId(orderId); if (this.cart.getFirstAttemptOrderId() == null) { this.cart.setFirstAttemptOrderId(orderId); } } } catch (GenericServiceException e) { String service = e.getMessage(); Map messageMap = UtilMisc.toMap("service", service); String errMsg = UtilProperties.getMessage(resource, "checkhelper.could_not_create_order_invoking_service", messageMap, (cart != null ? cart.getLocale() : Locale.getDefault())); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } // check for error message(s) if (ServiceUtil.isError(storeResult)) { String errMsg = UtilProperties.getMessage(resource, "checkhelper.did_not_complete_order_following_occurred", (cart != null ? cart.getLocale() : Locale.getDefault())); List resErrorMessages = new LinkedList(); resErrorMessages.add(errMsg); resErrorMessages.add(ServiceUtil.getErrorMessage(storeResult)); return ServiceUtil.returnError(resErrorMessages); } // ---------- // If needed, the production runs are created and linked to the order lines. // Iterator orderItems = ((List)context.get("orderItems")).iterator(); int counter = 0; while (orderItems.hasNext()) { GenericValue orderItem = (GenericValue)orderItems.next(); String productId = orderItem.getString("productId"); if (productId != null) { try { GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator); GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId)); if ("AGGREGATED".equals(product.getString("productTypeId"))) { org.ofbiz.product.config.ProductConfigWrapper config = this.cart.findCartItem(counter).getConfigWrapper(); Map inputMap = new HashMap(); inputMap.put("config", config); inputMap.put("facilityId", productStore.getString("inventoryFacilityId")); inputMap.put("orderId", orderId); inputMap.put("orderItemSeqId", orderItem.getString("orderItemSeqId")); inputMap.put("quantity", orderItem.getDouble("quantity")); inputMap.put("userLogin", userLogin); Map prunResult = dispatcher.runSync("createProductionRunFromConfiguration", inputMap); if (ServiceUtil.isError(prunResult)) { Debug.logError(ServiceUtil.getErrorMessage(prunResult) + " for input:" + inputMap, module); } } } catch (Exception e) { String service = e.getMessage(); Map messageMap = UtilMisc.toMap("service", service); String errMsg = UtilProperties.getMessage(resource, "checkhelper.could_not_create_order_invoking_service", messageMap, (cart != null ? cart.getLocale() : Locale.getDefault())); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } } counter++; } // ---------- // ---------- // The status of the requirement associated to the shopping cart lines is set to "ordered". // Iterator shoppingCartItems = this.cart.items().iterator(); while (shoppingCartItems.hasNext()) { ShoppingCartItem shoppingCartItem = (ShoppingCartItem)shoppingCartItems.next(); String requirementId = shoppingCartItem.getRequirementId(); if (requirementId != null) { try { Map inputMap = UtilMisc.toMap("requirementId", requirementId, "statusId", "REQ_ORDERED"); inputMap.put("userLogin", userLogin); // TODO: check service result for an error return Map outMap = dispatcher.runSync("updateRequirement", inputMap); } catch (Exception e) { String service = e.getMessage(); Map messageMap = UtilMisc.toMap("service", service); String errMsg = UtilProperties.getMessage(resource, "checkhelper.could_not_create_order_invoking_service", messageMap, (cart != null ? cart.getLocale() : Locale.getDefault())); Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } } } // ---------- // set the orderId for use by chained events Map result = ServiceUtil.returnSuccess(); result.put("orderId", orderId); result.put("orderAdditionalEmails", this.cart.getOrderAdditionalEmails()); // save the emails to the order List toBeStored = new LinkedList(); GenericValue party = null; try { party = this.delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId)); } catch (GenericEntityException e) { Debug.logWarning(e, UtilProperties.getMessage(resource_error,"OrderProblemsGettingPartyRecord", cart.getLocale()), module); party = null; } // create order contact mechs for the email address(s) if (party != null) { Iterator emailIter = UtilMisc.toIterator(ContactHelper.getContactMechByType(party, "EMAIL_ADDRESS", false)); while (emailIter != null && emailIter.hasNext()) { GenericValue email = (GenericValue) emailIter.next(); GenericValue orderContactMech = this.delegator.makeValue("OrderContactMech", UtilMisc.toMap("orderId", orderId, "contactMechId", email.getString("contactMechId"), "contactMechPurposeTypeId", "ORDER_EMAIL")); toBeStored.add(orderContactMech); } } // create dummy contact mechs and order contact mechs for the additional emails String additionalEmails = this.cart.getOrderAdditionalEmails(); List emailList = StringUtil.split(additionalEmails, ","); if (emailList == null) emailList = new ArrayList(); Iterator eli = emailList.iterator(); while (eli.hasNext()) { String email = (String) eli.next(); String contactMechId = this.delegator.getNextSeqId("ContactMech").toString(); GenericValue contactMech = this.delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", contactMechId, "contactMechTypeId", "EMAIL_ADDRESS", "infoString", email)); GenericValue orderContactMech = this.delegator.makeValue("OrderContactMech", UtilMisc.toMap("orderId", orderId, "contactMechId", contactMechId, "contactMechPurposeTypeId", "ORDER_EMAIL")); toBeStored.add(contactMech); toBeStored.add(orderContactMech); } if (toBeStored.size() > 0) { try { if (Debug.verboseOn()) Debug.logVerbose("To Be Stored: " + toBeStored, module); this.delegator.storeAll(toBeStored); } catch (GenericEntityException e) { // not a fatal error; so just print a message Debug.logWarning(e, UtilProperties.getMessage(resource_error,"OrderProblemsStoringOrderEmailContactInformation", cart.getLocale()), module); } } return result; } public void calcAndAddTax() throws GeneralException { calcAndAddTax(null); } public void calcAndAddTax(GenericValue shipAddress) throws GeneralException { if (!"SALES_ORDER".equals(cart.getOrderType())) { return; } int shipGroups = this.cart.getShipGroupSize(); for (int i = 0; i < shipGroups; i++) { Map serviceContext = this.makeTaxContext(i, shipAddress); // pass in BigDecimal values instead of Double List taxReturn = this.getTaxAdjustments(dispatcher, "calcTax", serviceContext); if (Debug.verboseOn()) Debug.logVerbose("ReturnList: " + taxReturn, module); ShoppingCart.CartShipInfo csi = cart.getShipInfo(i); List orderAdj = (List) taxReturn.get(0); List itemAdj = (List) taxReturn.get(1); // set the item adjustments if (itemAdj != null) { for (int x = 0; x < itemAdj.size(); x++) { List adjs = (List) itemAdj.get(x); ShoppingCartItem item = (ShoppingCartItem) csi.shipItemInfo.get(x); csi.setItemInfo(item, adjs); Debug.log("Added item adjustments to ship group [" + i + " / " + x + "] - " + adjs, module); } } // need to manually clear the order adjustments csi.shipTaxAdj.clear(); csi.shipTaxAdj.addAll(orderAdj); } } private Map makeTaxContext(int shipGroup, GenericValue shipAddress) throws GeneralException { String productStoreId = cart.getProductStoreId(); String billToPartyId = cart.getBillToCustomerPartyId(); ShoppingCart.CartShipInfo csi = cart.getShipInfo(shipGroup); int totalItems = csi.shipItemInfo.size(); List product = new ArrayList(totalItems); List amount = new ArrayList(totalItems); List price = new ArrayList(totalItems); List shipAmt = new ArrayList(totalItems); for (int i = 0; i < totalItems; i++) { ShoppingCartItem cartItem = (ShoppingCartItem) csi.shipItemInfo.get(i); ShoppingCart.CartShipInfo.CartShipItemInfo itemInfo = csi.getShipItemInfo(cartItem); //Debug.logInfo("In makeTaxContext for item [" + i + "] in ship group [" + shipGroup + "] got cartItem: " + cartItem, module); //Debug.logInfo("In makeTaxContext for item [" + i + "] in ship group [" + shipGroup + "] got itemInfo: " + itemInfo, module); product.add(i, cartItem.getProduct()); amount.add(i, new BigDecimal(cartItem.getItemSubTotal(itemInfo.quantity))); price.add(i, new BigDecimal(cartItem.getBasePrice())); shipAmt.add(i, new BigDecimal("0.00")); // no per item shipping yet } BigDecimal shipAmount = new BigDecimal(csi.shipEstimate); if (shipAddress == null) { shipAddress = cart.getShippingAddress(shipGroup); } // no shipping address; try the billing address if (shipAddress == null) { for (int i = 0; i < cart.selectedPayments(); i++) { ShoppingCart.CartPaymentInfo cpi = cart.getPaymentInfo(i); GenericValue billAddr = cpi.getBillingAddress(delegator); if (billAddr != null) { shipAddress = billAddr; Debug.logInfo("Found address from payment method.", module); } break; } } Map serviceContext = UtilMisc.toMap("productStoreId", productStoreId); serviceContext.put("billToPartyId", billToPartyId); serviceContext.put("itemProductList", product); serviceContext.put("itemAmountList", amount); serviceContext.put("itemPriceList", price); serviceContext.put("itemShippingList", shipAmt); serviceContext.put("orderShippingAmount", shipAmount); serviceContext.put("shippingAddress", shipAddress); return serviceContext; } // Calc the tax adjustments. private List getTaxAdjustments(LocalDispatcher dispatcher, String taxService, Map serviceContext) throws GeneralException { Map serviceResult = null; try { serviceResult = dispatcher.runSync(taxService, serviceContext); } catch (GenericServiceException e) { Debug.logError(e, module); throw new GeneralException("Problem occurred in tax service (" + e.getMessage() + ")", e); } if (ServiceUtil.isError(serviceResult)) { throw new GeneralException(ServiceUtil.getErrorMessage(serviceResult)); } // the adjustments (returned in order) from taxware. List orderAdj = (List) serviceResult.get("orderAdjustments"); List itemAdj = (List) serviceResult.get("itemAdjustments"); return UtilMisc.toList(orderAdj, itemAdj); } public Map processPayment(GenericValue productStore, GenericValue userLogin) throws GeneralException { return processPayment(productStore, userLogin, false, false); } public Map processPayment(GenericValue productStore, GenericValue userLogin, boolean faceToFace) throws GeneralException { return processPayment(productStore, userLogin, faceToFace, false); } public Map processPayment(GenericValue productStore, GenericValue userLogin, boolean faceToFace, boolean manualHold) throws GeneralException { // Get some payment related strings String DECLINE_MESSAGE = productStore.getString("authDeclinedMessage"); String ERROR_MESSAGE = productStore.getString("authErrorMessage"); String RETRY_ON_ERROR = productStore.getString("retryFailedAuths");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -