⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkoutevents.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: CheckOutEvents.java 7288 2006-04-13 22:57:27Z sichen $ * *  Copyright (c) 2001, 2002 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.text.DecimalFormat;import java.text.ParseException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Locale;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.GeneralRuntimeException;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.webapp.stats.VisitHandler;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.marketing.tracking.TrackingCodeEvents;import org.ofbiz.product.catalog.CatalogWorker;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;/** * Events used for processing checkout and orders. * * @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: 7288 $ * @since 2.0 */public class CheckOutEvents {    public static final String module = CheckOutEvents.class.getName();    public static final String resource = "OrderUiLabels";    public static final String resource_error = "OrderErrorUiLabels";    public static String cartNotEmpty(HttpServletRequest request, HttpServletResponse response) {        ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");        //Locale locale = UtilHttp.getLocale(request);        String errMsg = null;        if (cart != null && cart.size() > 0) {            return "success";        } else {            errMsg = UtilProperties.getMessage(resource, "checkevents.cart_empty", (cart != null ? cart.getLocale() : Locale.getDefault()));            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }    }    public static String cancelOrderItem(HttpServletRequest request, HttpServletResponse response) {        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");        String orderId = request.getParameter("orderId");        String itemSeqId = request.getParameter("item_seq");        String groupSeqId = request.getParameter("group_seq");        Locale locale = UtilHttp.getLocale(request);        Map fields = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", itemSeqId, "shipGroupSeqId", groupSeqId, "userLogin", userLogin);        Map result = null;        String errMsg = null;        try {            result = dispatcher.runSync("cancelOrderItem", fields);        } catch (GenericServiceException e) {            Debug.logError(e, module);            errMsg = UtilProperties.getMessage(resource, "checkevents.cannot_cancel_item", locale);            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        if (result.containsKey(ModelService.ERROR_MESSAGE)) {            request.setAttribute("_ERROR_MESSAGE_", result.get(ModelService.ERROR_MESSAGE));            return "error";        }         try {            result = dispatcher.runSync("recreateOrderAdjustments", UtilMisc.toMap("userLogin", userLogin, "orderId", orderId));        } catch (GenericServiceException e) {            Debug.logError(e, module);            errMsg = UtilProperties.getMessage(resource, "checkevents.cannot_recalc_adjustments", locale);            request.setAttribute("_ERROR_MESSAGE_", errMsg);            return "error";        }        if (result.containsKey(ModelService.ERROR_MESSAGE)) {            request.setAttribute("_ERROR_MESSAGE_", result.get(ModelService.ERROR_MESSAGE));            return "error";        }        return "success";    }    public static String setCheckOutPages(HttpServletRequest request, HttpServletResponse response) {        if ("error".equals(CheckOutEvents.cartNotEmpty(request, response)) == true) {            return "error";        }                HttpSession session = request.getSession();        //Locale locale = UtilHttp.getLocale(request);        String curPage = request.getParameter("checkoutpage");        Debug.logInfo("CheckoutPage: " + curPage, module);        ShoppingCart cart = (ShoppingCart) session.getAttribute("shoppingCart");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        CheckOutHelper checkOutHelper = new CheckOutHelper(dispatcher, delegator, cart);        GenericValue userLogin = cart.getUserLogin();        if (userLogin == null) userLogin = (GenericValue) session.getAttribute("userLogin");        if ("shippingaddress".equals(curPage) == true) {            // Set the shipping address options            String shippingContactMechId = request.getParameter("shipping_contact_mech_id");            String taxAuthPartyGeoIds = request.getParameter("taxAuthPartyGeoIds");            String partyTaxId = request.getParameter("partyTaxId");            String isExempt = request.getParameter("isExempt");                        // if taxAuthPartyGeoIds is not empty drop that into the database            if (UtilValidate.isNotEmpty(taxAuthPartyGeoIds)) {                try {                    Map createCustomerTaxAuthInfoResult = dispatcher.runSync("createCustomerTaxAuthInfo",                             UtilMisc.toMap("partyId", cart.getPartyId(), "taxAuthPartyGeoIds", taxAuthPartyGeoIds, "partyTaxId", partyTaxId, "isExempt", isExempt, "userLogin", userLogin));                    ServiceUtil.getMessages(request, createCustomerTaxAuthInfoResult, null);                    if (ServiceUtil.isError(createCustomerTaxAuthInfoResult)) {                        return "error";                    }                } catch (GenericServiceException e) {                    String errMsg = "Error setting customer tax info: " + e.toString();                    request.setAttribute("_ERROR_MESSAGE_", errMsg);                    return "error";                }            }                        Map callResult = checkOutHelper.setCheckOutShippingAddress(shippingContactMechId);            ServiceUtil.getMessages(request, callResult, null);            if (!(ServiceUtil.isError(callResult))) {                // No errors so push the user onto the next page                curPage = "shippingoptions";            }        } else if ("shippingoptions".equals(curPage) == true) {            // Set the general shipping options            String shippingMethod = request.getParameter("shipping_method");            String correspondingPoId = request.getParameter("corresponding_po_id");            String shippingInstructions = request.getParameter("shipping_instructions");            String orderAdditionalEmails = request.getParameter("order_additional_emails");            String maySplit = request.getParameter("may_split");            String giftMessage = request.getParameter("gift_message");            String isGift = request.getParameter("is_gift");            String internalCode = request.getParameter("internalCode");            String shipBeforeDate = request.getParameter("shipBeforeDate");            String shipAfterDate = request.getParameter("shipAfterDate");            Map callResult = checkOutHelper.setCheckOutShippingOptions(shippingMethod, correspondingPoId,                    shippingInstructions, orderAdditionalEmails, maySplit, giftMessage, isGift, internalCode, shipBeforeDate, shipAfterDate);            ServiceUtil.getMessages(request, callResult, null);            if (!(callResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR))) {                // No errors so push the user onto the next page                curPage = "payment";            }        } else if ("payment".equals(curPage) == true) {            // get the currency format            String currencyFormat = UtilProperties.getPropertyValue("general.properties", "currency.decimal.format", "##0.00");            DecimalFormat formatter = new DecimalFormat(currencyFormat);            // Set the payment options            Map selectedPaymentMethods = getSelectedPaymentMethods(request);            if (selectedPaymentMethods == null) {                return "error";            }            String billingAccountId = request.getParameter("billingAccountId");            String billingAcctAmtStr = request.getParameter("amount_" + billingAccountId);            Double billingAccountAmt = null;            // parse the amount to a decimal            if (billingAcctAmtStr != null) {                try {                    billingAccountAmt = new Double(formatter.parse(billingAcctAmtStr).doubleValue());                } catch (ParseException e) {                    Debug.logError(e, module);                    Map messageMap = UtilMisc.toMap("billingAccountId", billingAccountId);                    String errMsg = UtilProperties.getMessage(resource, "checkevents.invalid_amount_set_for_billing_account", messageMap, (cart != null ? cart.getLocale() : Locale.getDefault()));                    request.setAttribute("_ERROR_MESSAGE_", errMsg);                    return "error";                }            }            List singleUsePayments = new ArrayList();            // check for gift card not on file            Map params = UtilHttp.getParameterMap(request);            Map gcResult = checkOutHelper.checkGiftCard(params, selectedPaymentMethods);            ServiceUtil.getMessages(request, gcResult, null);            if (gcResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) {                return "error";            } else {                String gcPaymentMethodId = (String) gcResult.get("paymentMethodId");                Double gcAmount = (Double) gcResult.get("amount");                if (gcPaymentMethodId != null) {                    selectedPaymentMethods.put(gcPaymentMethodId, gcAmount);                    if ("Y".equalsIgnoreCase(request.getParameter("singleUseGiftCard"))) {                        singleUsePayments.add(gcPaymentMethodId);                    }                }            }            Map callResult = checkOutHelper.setCheckOutPayment(selectedPaymentMethods, singleUsePayments, billingAccountId, billingAccountAmt);            ServiceUtil.getMessages(request, callResult, null);            if (!(callResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR))) {                // No errors so push the user onto the next page                curPage = "confirm";            }        } else {            curPage = determineInitialCheckOutPage(cart);        }        return curPage;    }    private static final String DEFAULT_INIT_CHECKOUT_PAGE = "shippingaddress";    /**     * Method to determine the initial checkout page based on requirements. This will also set     * any cart variables necessary to satisfy the requirements, such as setting the     * shipment method according to the type of items in the cart.     */    public static String determineInitialCheckOutPage(ShoppingCart cart) {        String page = DEFAULT_INIT_CHECKOUT_PAGE;        if (cart == null) return page;        // if no shipping applies, set the no shipment method and skip to payment        if (!cart.shippingApplies()) {            cart.setShipmentMethodTypeId("NO_SHIPPING");            cart.setCarrierPartyId("_NA_");            page = "payment";        }        return page;    }    public static String setCheckOutError(HttpServletRequest request, HttpServletResponse response) {        String currentPage = request.getParameter("checkoutpage");        if (currentPage == null || currentPage.length() == 0) {            return "error";        } else {            return currentPage;        }    }    public static String setPartialCheckOutOptions(HttpServletRequest request, HttpServletResponse response) {        String resp = setCheckOutOptions(request, response);        request.setAttribute("_ERROR_MESSAGE_", null);        return "success";    }    public static String checkPaymentMethods(HttpServletRequest request, HttpServletResponse response) {        ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -