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

📄 shoppingcartevents.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: ShoppingCartEvents.java 7145 2006-03-31 05:54:20Z jacopo $ * *  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.NumberFormat;import java.util.Iterator;import java.util.LinkedList;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.UtilDateTime;import org.ofbiz.base.util.UtilFormatOut;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.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericPK;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;import org.ofbiz.product.catalog.CatalogWorker;import org.ofbiz.product.config.ProductConfigWorker;import org.ofbiz.product.config.ProductConfigWrapper;import org.ofbiz.product.product.ProductWorker;import org.ofbiz.product.store.ProductStoreSurveyWrapper;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.security.Security;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;import org.ofbiz.webapp.control.RequestHandler;/** * Shopping cart events. * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:tristana@twibble.org">Tristan Austin</a> * @version    $Rev: 7145 $ * @since      2.0 */public class ShoppingCartEvents {    public static String module = ShoppingCartEvents.class.getName();    public static final String resource = "OrderUiLabels";    public static final String resource_error = "OrderErrorUiLabels";    private static final String NO_ERROR = "noerror";    private static final String NON_CRITICAL_ERROR = "noncritical";    private static final String ERROR = "error";    public static String addProductPromoCode(HttpServletRequest request, HttpServletResponse response) {        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCart cart = getCartObject(request);        String productPromoCodeId = request.getParameter("productPromoCodeId");        if (UtilValidate.isNotEmpty(productPromoCodeId)) {            String checkResult = cart.addProductPromoCode(productPromoCodeId, dispatcher);            if (UtilValidate.isNotEmpty(checkResult)) {                request.setAttribute("_ERROR_MESSAGE_", checkResult);                return "error";            }        }        return "success";    }    /** Event to add an item to the shopping cart. */    public static String addToCart(HttpServletRequest request, HttpServletResponse response) {        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCart cart = getCartObject(request);        ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart);        String controlDirective = null;        Map result = null;        String productId = null;        String itemType = null;        String itemDescription = null;        String productCategoryId = null;        String priceStr = null;        double price = 0.00;        String quantityStr = null;        double quantity = 0;        String reservStartStr = null;        String reservEndStr = null;        java.sql.Timestamp reservStart = null;        java.sql.Timestamp reservEnd = null;        String reservLengthStr = null;        double reservLength = 0;        String reservPersonsStr = null;        double reservPersons = 0;        String shipBeforeStr = null;        String shipBeforeDateStr = null;        String shipAfterDateStr = null;        java.sql.Timestamp shipBeforeDate = null;        java.sql.Timestamp shipAfterDate = null;        // not used right now: Map attributes = null;        String catalogId = CatalogWorker.getCurrentCatalogId(request);        Locale locale = UtilHttp.getLocale(request);        NumberFormat nf = NumberFormat.getNumberInstance(locale);        // Get the parameters as a MAP, remove the productId and quantity params.        Map paramMap = UtilHttp.getParameterMap(request);        // Get shoppingList info if passed        String shoppingListId = request.getParameter("shoppingListId");        String shoppingListItemSeqId = request.getParameter("shoppingListItemSeqId");        if (paramMap.containsKey("ADD_PRODUCT_ID")) {            productId = (String) paramMap.remove("ADD_PRODUCT_ID");        } else if (paramMap.containsKey("add_product_id")) {            productId = (String) paramMap.remove("add_product_id");        }        if (paramMap.containsKey("ADD_CATEGORY_ID")) {            productCategoryId = (String) paramMap.remove("ADD_CATEGORY_ID");        } else if (paramMap.containsKey("add_category_id")) {            productCategoryId = (String) paramMap.remove("add_category_id");        }        if (productCategoryId != null && productCategoryId.length() == 0) {            productCategoryId = null;        }        if (productId == null) {            // before returning error; check make sure we aren't adding a special item type            if (paramMap.containsKey("ADD_ITEM_TYPE")) {                itemType = (String) paramMap.remove("ADD_ITEM_TYPE");            } else if (paramMap.containsKey("add_item_type")) {                itemType = (String) paramMap.remove("add_item_type");            } else {                request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource, "cart.addToCart.noProductInfoPassed", locale));                return "success"; // not critical return to same page            }        } else {            try {                String pId = ProductWorker.findProductId(delegator, productId);                if (pId != null) {                    productId = pId;                }            } catch (Throwable e) {                Debug.logWarning(e, module);            }        }        // check for an itemDescription        if (paramMap.containsKey("ADD_ITEM_DESCRIPTION")) {            itemDescription = (String) paramMap.remove("ADD_ITEM_DESCRIPTION");        } else if (paramMap.containsKey("add_item_description")) {            itemDescription = (String) paramMap.remove("add_item_description");        }        if (itemDescription != null && itemDescription.length() == 0) {            itemDescription = null;        }        // Get the ProductConfigWrapper (it's not null only for configurable items)        ProductConfigWrapper configWrapper = null;        configWrapper = ProductConfigWorker.getProductConfigWrapper(productId, cart.getCurrency(), request);        if (configWrapper != null) {            // The choices selected by the user are taken from request and set in the wrapper            ProductConfigWorker.fillProductConfigWrapper(configWrapper, request);            if (!configWrapper.isCompleted()) {                // The configuration is not valid                request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource, "cart.addToCart.productConfigurationIsNotValid", locale));                return "error";            }        }        // get the override price        if (paramMap.containsKey("PRICE")) {            priceStr = (String) paramMap.remove("PRICE");        } else if (paramMap.containsKey("price")) {            priceStr = (String) paramMap.remove("price");        }        if (priceStr == null) {            priceStr = "0";  // default price is 0        }        // get the renting data        if (paramMap.containsKey("reservStart")) {            reservStartStr = (String) paramMap.remove("reservStart");            if (reservStartStr.length() == 10) // only date provided, no time string?                    reservStartStr += " 00:00:00.000000000"; // should have format: yyyy-mm-dd hh:mm:ss.fffffffff            if (reservStartStr.length() >0) {                try {                    reservStart = java.sql.Timestamp.valueOf((String) reservStartStr);                } catch (Exception e) {                    Debug.logWarning(e,"Problems parsing Reservation start string: "                                + reservStartStr, module);                    reservStart = null;                    request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource,"cart.addToCart.rental.startDate", locale));                    return "error";                }            }            else reservStart = null;            if (paramMap.containsKey("reservEnd")) {                reservEndStr = (String) paramMap.remove("reservEnd");                if (reservEndStr.length() == 10) // only date provided, no time string?                        reservEndStr += " 00:00:00.000000000"; // should have format: yyyy-mm-dd hh:mm:ss.fffffffff                if (reservEndStr.length() > 0) {                    try {                        reservEnd = java.sql.Timestamp.valueOf((String) reservEndStr);                    } catch (Exception e) {                        Debug.logWarning(e,"Problems parsing Reservation end string: " + reservEndStr, module);                        reservEnd = null;                        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource,"cart.addToCart.rental.endDate", locale));                        return "error";                    }                }                else reservEnd = null;            }            if (reservStart != null && reservEnd != null)	{            	reservLength = UtilDateTime.getInterval(reservStart,reservEnd)/86400000;            }            if (reservStart != null && paramMap.containsKey("reservLength")) {                reservLengthStr = (String) paramMap.remove("reservLength");                // parse the reservation Length                try {                    reservLength = nf.parse(reservLengthStr).doubleValue();                } catch (Exception e) {                    Debug.logWarning(e,"Problems parsing reservation length string: "                                    + reservLengthStr, module);                    reservLength = 1;                    request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderReservationLengthShouldBeAPositiveNumber", locale));                    return "error";                }            }            if (reservStart != null && paramMap.containsKey("reservPersons")) {                reservPersonsStr = (String) paramMap.remove("reservPersons");                // parse the number of persons                try {                    reservPersons = nf.parse(reservPersonsStr).doubleValue();                } catch (Exception e) {                    Debug.logWarning(e,"Problems parsing reservation number of persons string: " + reservPersonsStr, module);                    reservPersons = 1;                    request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderNumberOfPersonsShouldBeOneOrLarger", locale));                    return "error";                }            }        }

⌨️ 快捷键说明

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