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

📄 shoppingcartevents.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // get the quantity        if (paramMap.containsKey("QUANTITY")) {            quantityStr = (String) paramMap.remove("QUANTITY");        } else if (paramMap.containsKey("quantity")) {            quantityStr = (String) paramMap.remove("quantity");        }        if (quantityStr == null) {            quantityStr = "1";  // default quantity is 1        }        // parse the price        try {            price = nf.parse(priceStr).doubleValue();        } catch (Exception e) {            Debug.logWarning(e, "Problems parsing price string: " + priceStr, module);            price = 0.00;        }        // parse the quantity        try {            quantity = nf.parse(quantityStr).doubleValue();        } catch (Exception e) {            Debug.logWarning(e, "Problems parsing quantity string: " + quantityStr, module);            quantity = 1;        }        // get the selected amount        String selectedAmountStr = "0.00";        if (paramMap.containsKey("ADD_AMOUNT")) {            selectedAmountStr = (String) paramMap.remove("ADD_AMOUNT");        } else if (paramMap.containsKey("add_amount")) {            selectedAmountStr = (String) paramMap.remove("add_amount");        }        // parse the amount        double amount = 0.00;        if (selectedAmountStr != null && selectedAmountStr.length() > 0) {            try {                amount = nf.parse(selectedAmountStr).doubleValue();            } catch (Exception e) {                Debug.logWarning(e, "Problem parsing amount string: " + selectedAmountStr, module);                amount = 0.00;            }        }        // get the ship before date (handles both yyyy-mm-dd input and full timestamp)        shipBeforeDateStr = (String) paramMap.remove("shipBeforeDate");        if (shipBeforeDateStr != null && shipBeforeDateStr.length() > 0) {            if (shipBeforeDateStr.length() == 10) shipBeforeDateStr += " 00:00:00.000";            try {                shipBeforeDate = java.sql.Timestamp.valueOf(shipBeforeDateStr);            } catch (IllegalArgumentException e) {                Debug.logWarning(e, "Bad shipBeforeDate input: " + e.getMessage(), module);                shipBeforeDate = null;            }        }        // get the ship after date (handles both yyyy-mm-dd input and full timestamp)        shipAfterDateStr = (String) paramMap.remove("shipAfterDate");        if (shipAfterDateStr != null && shipAfterDateStr.length() > 0) {            if (shipAfterDateStr.length() == 10) shipAfterDateStr += " 00:00:00.000";            try {                shipAfterDate = java.sql.Timestamp.valueOf(shipAfterDateStr);            } catch (IllegalArgumentException e) {                Debug.logWarning(e, "Bad shipAfterDate input: " + e.getMessage(), module);                shipAfterDate = null;            }        }        // check for an add-to cart survey        List surveyResponses = null;        if (productId != null) {            String productStoreId = ProductStoreWorker.getProductStoreId(request);            List productSurvey = ProductStoreWorker.getProductSurveys(delegator, productStoreId, productId, "CART_ADD");            if (productSurvey != null && productSurvey.size() > 0) {                // TODO: implement multiple survey per product                GenericValue survey = EntityUtil.getFirst(productSurvey);                String surveyResponseId = (String) request.getAttribute("surveyResponseId");                if (surveyResponseId != null) {                    surveyResponses = UtilMisc.toList(surveyResponseId);                } else {                    Map surveyContext = UtilHttp.getParameterMap(request);                    GenericValue userLogin = cart.getUserLogin();                    String partyId = null;                    if (userLogin != null) {                        partyId = userLogin.getString("partyId");                    }                    String formAction = "/additemsurvey";                    String nextPage = RequestHandler.getNextPageUri(request.getPathInfo());                    if (nextPage != null) {                        formAction = formAction + "/" + nextPage;                    }                    ProductStoreSurveyWrapper wrapper = new ProductStoreSurveyWrapper(survey, partyId, surveyContext);                    request.setAttribute("surveyWrapper", wrapper);                    request.setAttribute("surveyAction", formAction); // will be used as the form action of the survey                    return "survey";                }            }        }        if (surveyResponses != null) {            paramMap.put("surveyResponses", surveyResponses);        }        // Translate the parameters and add to the cart        result = cartHelper.addToCart(catalogId, shoppingListId, shoppingListItemSeqId, productId, productCategoryId,                itemType, itemDescription, price, amount, quantity, reservStart, reservLength, reservPersons, shipBeforeDate, shipAfterDate, configWrapper, paramMap);            controlDirective = processResult(result, request);        // Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            if (cart.viewCartOnAdd()) {                return "viewcart";            } else {                return "success";            }        }    }    public static String addToCartFromOrder(HttpServletRequest request, HttpServletResponse response) {        String orderId = request.getParameter("orderId");        String[] itemIds = request.getParameterValues("item_id");        // not used yet: Locale locale = UtilHttp.getLocale(request);        ShoppingCart cart = getCartObject(request);        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart);        String catalogId = CatalogWorker.getCurrentCatalogId(request);        Map result;        String controlDirective;        boolean addAll = ("true".equals(request.getParameter("add_all")));        result = cartHelper.addToCartFromOrder(catalogId, orderId, itemIds, addAll);        controlDirective = processResult(result, request);        //Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            return "success";        }    }    /** Adds all products in a category according to quantity request parameter     * for each; if no parameter for a certain product in the category, or if     * quantity is 0, do not add     */    public static String addToCartBulk(HttpServletRequest request, HttpServletResponse response) {        String categoryId = request.getParameter("category_id");        ShoppingCart cart = getCartObject(request);        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart);        String controlDirective;        Map result;        // not used yet: Locale locale = UtilHttp.getLocale(request);        //Convert the params to a map to pass in        Map paramMap = UtilHttp.getParameterMap(request);        String catalogId = CatalogWorker.getCurrentCatalogId(request);        result = cartHelper.addToCartBulk(catalogId, categoryId, paramMap);        controlDirective = processResult(result, request);        //Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            return "success";        }    }    /** Adds a set of requirements to the cart     */    public static String addToCartBulkRequirements(HttpServletRequest request, HttpServletResponse response) {        ShoppingCart cart = getCartObject(request);        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart);        String controlDirective;        Map result;        // not used yet: Locale locale = UtilHttp.getLocale(request);        //Convert the params to a map to pass in        Map paramMap = UtilHttp.getParameterMap(request);        String catalogId = CatalogWorker.getCurrentCatalogId(request);        result = cartHelper.addToCartBulkRequirements(catalogId, paramMap);        controlDirective = processResult(result, request);        //Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            return "success";        }    }    /** Adds all products in a category according to default quantity on ProductCategoryMember     * for each; if no default for a certain product in the category, or if     * quantity is 0, do not add     */    public static String addCategoryDefaults(HttpServletRequest request, HttpServletResponse response) {        String categoryId = request.getParameter("category_id");        String catalogId = CatalogWorker.getCurrentCatalogId(request);        ShoppingCart cart = getCartObject(request);        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(delegator, dispatcher, cart);        String controlDirective;        Map result;        Double totalQuantity;        Locale locale = UtilHttp.getLocale(request);        result = cartHelper.addCategoryDefaults(catalogId, categoryId);        controlDirective = processResult(result, request);        //Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            totalQuantity = (Double)result.get("totalQuantity");            Map messageMap = UtilMisc.toMap("totalQuantity", UtilFormatOut.formatQuantity(totalQuantity) );            request.setAttribute("_EVENT_MESSAGE_",                                  UtilProperties.getMessage(resource, "cart.add_category_defaults",                                          messageMap, locale ));            return "success";        }    }    /** Delete an item from the shopping cart. */    public static String deleteFromCart(HttpServletRequest request, HttpServletResponse response) {        ShoppingCart cart = getCartObject(request);        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(null, dispatcher, cart);        String controlDirective;        Map result;        Map paramMap = UtilHttp.getParameterMap(request);        // not used yet: Locale locale = UtilHttp.getLocale(request);        //Delegate the cart helper        result = cartHelper.deleteFromCart(paramMap);        controlDirective = processResult(result, request);        //Determine where to send the browser        if (controlDirective.equals(ERROR)) {            return "error";        } else {            return "success";        }    }    /** Update the items in the shopping cart. */    public static String modifyCart(HttpServletRequest request, HttpServletResponse response) {        HttpSession session = request.getSession();        ShoppingCart cart = getCartObject(request);        Locale locale = UtilHttp.getLocale(request);        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        Security security = (Security) request.getAttribute("security");        ShoppingCartHelper cartHelper = new ShoppingCartHelper(null, dispatcher, cart);        String controlDirective;        Map result;        // not used yet: Locale locale = UtilHttp.getLocale(request);        Map paramMap = UtilHttp.getParameterMap(request);        String removeSelectedFlag = request.getParameter("removeSelected");        String selectedItems[] = request.getParameterValues("selectedItem");

⌨️ 快捷键说明

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