📄 checkouthelper.java
字号:
/* * $Id: CheckOutHelper.java 7287 2006-04-13 18:37:16Z sichen $ * * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.order.shoppingcart;import java.math.BigDecimal;import java.sql.Timestamp;import java.text.DecimalFormat;import java.text.ParseException;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import org.ofbiz.base.util.*;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityFieldValue;import org.ofbiz.entity.condition.EntityFunction;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.order.finaccount.FinAccountHelper;import org.ofbiz.order.order.OrderChangeHelper;import org.ofbiz.party.contact.ContactHelper;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;/** * A facade over the ShoppingCart to simplify the relatively complex * processing required to create an order in the system. * * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author <a href="mailto:cnelson@einnovation.com">Chris Nelson</a> * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author <a href="mailto:tristana@twibble.org">Tristan Austin</a> * @version $Rev: 7287 $ * @since 2.0 */public class CheckOutHelper { public static final String module = CheckOutHelper.class.getName(); public static final String resource = "OrderUiLabels"; public static final String resource_error = "OrderErrorUiLabels"; protected LocalDispatcher dispatcher = null; protected GenericDelegator delegator = null; protected ShoppingCart cart = null; public CheckOutHelper(LocalDispatcher dispatcher, GenericDelegator delegator, ShoppingCart cart) { this.delegator = delegator; this.dispatcher = dispatcher; this.cart = cart; } public Map setCheckOutShippingAddress(String shippingContactMechId) { List errorMessages = new ArrayList(); Map result; String errMsg = null; if (this.cart != null && this.cart.size() > 0) { errorMessages.addAll(setCheckOutShippingAddressInternal(shippingContactMechId)); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.no_items_in_cart", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } if (errorMessages.size() == 1) { result = ServiceUtil.returnError(errorMessages.get(0).toString()); } else if (errorMessages.size() > 0) { result = ServiceUtil.returnError(errorMessages); } else { result = ServiceUtil.returnSuccess(); } return result; } private List setCheckOutShippingAddressInternal(String shippingContactMechId) { List errorMessages = new ArrayList(); String errMsg = null; // set the shipping address if (UtilValidate.isNotEmpty(shippingContactMechId)) { this.cart.setShippingContactMechId(shippingContactMechId); } else if (cart.shippingApplies()) { // only return an error if shipping is required for this purchase errMsg = UtilProperties.getMessage(resource,"checkhelper.select_shipping_destination", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } return errorMessages; } public Map setCheckOutShippingOptions(String shippingMethod, String correspondingPoId, String shippingInstructions, String orderAdditionalEmails, String maySplit, String giftMessage, String isGift, String internalCode, String shipBeforeDate, String shipAfterDate ) { List errorMessages = new ArrayList(); Map result; String errMsg = null; if (this.cart != null && this.cart.size() > 0) { errorMessages.addAll(setCheckOutShippingOptionsInternal(shippingMethod, correspondingPoId, shippingInstructions, orderAdditionalEmails, maySplit, giftMessage, isGift, internalCode, shipBeforeDate, shipAfterDate)); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.no_items_in_cart", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } if (errorMessages.size() == 1) { result = ServiceUtil.returnError(errorMessages.get(0).toString()); } else if (errorMessages.size() > 0) { result = ServiceUtil.returnError(errorMessages); } else { result = ServiceUtil.returnSuccess(); } return result; } private List setCheckOutShippingOptionsInternal(String shippingMethod, String correspondingPoId, String shippingInstructions, String orderAdditionalEmails, String maySplit, String giftMessage, String isGift, String internalCode, String shipBeforeDate, String shipAfterDate ) { List errorMessages = new ArrayList(); String errMsg = null; // set the general shipping options if (UtilValidate.isNotEmpty(shippingMethod)) { int delimiterPos = shippingMethod.indexOf('@'); String shipmentMethodTypeId = null; String carrierPartyId = null; if (delimiterPos > 0) { shipmentMethodTypeId = shippingMethod.substring(0, delimiterPos); carrierPartyId = shippingMethod.substring(delimiterPos + 1); } this.cart.setShipmentMethodTypeId(shipmentMethodTypeId); this.cart.setCarrierPartyId(carrierPartyId); } else if (cart.shippingApplies()) { // only return an error if shipping is required for this purchase errMsg = UtilProperties.getMessage(resource,"checkhelper.select_shipping_method", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } // set the shipping instructions this.cart.setShippingInstructions(shippingInstructions); if (UtilValidate.isNotEmpty(maySplit)) { cart.setMaySplit(Boolean.valueOf(maySplit)); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.select_splitting_preference", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } // set the gift message this.cart.setGiftMessage(giftMessage); if (UtilValidate.isNotEmpty(isGift)) { cart.setIsGift(Boolean.valueOf(isGift)); } else { errMsg = UtilProperties.getMessage(resource, "checkhelper.specify_if_order_is_gift", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } // interal code this.cart.setInternalCode(internalCode); if (shipBeforeDate != null && shipBeforeDate.length() > 0) { if (UtilValidate.isDate(shipBeforeDate)) { cart.setShipBeforeDate(UtilDateTime.toTimestamp(shipBeforeDate)); } else { errMsg = UtilProperties.getMessage(resource, "checkhelper.specify_if_shipBeforeDate_is_date", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } } if (shipAfterDate != null && shipAfterDate.length() > 0) { if (UtilValidate.isDate(shipAfterDate)) { cart.setShipAfterDate(UtilDateTime.toTimestamp(shipAfterDate)); } else { errMsg = UtilProperties.getMessage(resource, "checkhelper.specify_if_shipAfterDate_is_date", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } } // set any additional notification emails this.cart.setOrderAdditionalEmails(orderAdditionalEmails); // set the PO number if (UtilValidate.isNotEmpty(correspondingPoId)) { this.cart.setPoNumber(correspondingPoId); } else { this.cart.setPoNumber(null); } return errorMessages; } public Map setCheckOutPayment(Map selectedPaymentMethods, List singleUsePayments, String billingAccountId, Double billingAccountAmt) { List errorMessages = new ArrayList(); Map result; String errMsg = null; if (this.cart != null && this.cart.size() > 0) { errorMessages.addAll(setCheckOutPaymentInternal(selectedPaymentMethods, singleUsePayments, billingAccountId, billingAccountAmt)); } else { errMsg = UtilProperties.getMessage(resource,"checkhelper.no_items_in_cart", (cart != null ? cart.getLocale() : Locale.getDefault())); errorMessages.add(errMsg); } if (errorMessages.size() == 1) { result = ServiceUtil.returnError(errorMessages.get(0).toString()); } else if (errorMessages.size() > 0) { result = ServiceUtil.returnError(errorMessages); } else { result = ServiceUtil.returnSuccess(); } return result; } private List setCheckOutPaymentInternal(Map selectedPaymentMethods, List singleUsePayments, String billingAccountId, Double billingAccountAmt) { List errorMessages = new ArrayList(); String errMsg = null; if (singleUsePayments == null) { singleUsePayments = new ArrayList(); } // set the billing account amount if (billingAccountId != null && billingAccountAmt != null && !billingAccountId.equals("_NA_")) { cart.setBillingAccount(billingAccountId, billingAccountAmt.doubleValue()); } else { cart.setBillingAccount(null, 0.00); } // set the payment method option if (selectedPaymentMethods != null && selectedPaymentMethods.size() > 0) { // clear out the old payments cart.clearPayments(); // if we are EXT_BILLACT (billing account only) then we need to make sure we have enough credit if (selectedPaymentMethods.containsKey("EXT_BILLACT")) { double accountCredit = this.availableAccountBalance(cart.getBillingAccountId());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -