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

📄 shoppingcarthelper.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            return result;        }        if (prodCatMemberCol == null) {            Map messageMap = UtilMisc.toMap("categoryId", categoryId);            errMsg = UtilProperties.getMessage(resource,"cart.could_not_get_products_in_category", messageMap, this.cart.getLocale());            result = ServiceUtil.returnError(errMsg);            return result;        }        double totalQuantity = 0;        Iterator pcmIter = prodCatMemberCol.iterator();        while (pcmIter.hasNext()) {            GenericValue productCategoryMember = (GenericValue) pcmIter.next();            Double quantity = productCategoryMember.getDouble("quantity");            if (quantity != null && quantity.doubleValue() > 0.0) {                try {                    this.cart.addOrIncreaseItem(productCategoryMember.getString("productId"),                             0.00, quantity.doubleValue(), null, null, catalogId, dispatcher);                    totalQuantity += quantity.doubleValue();                } catch (CartItemModifyException e) {                    errorMsgs.add(e.getMessage());                } catch (ItemNotFoundException e) {                    errorMsgs.add(e.getMessage());                }            }        }        if (errorMsgs.size() > 0) {            result = ServiceUtil.returnError(errorMsgs);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            return result; // don't return error because this is a non-critical error and should go back to the same page        }        result = ServiceUtil.returnSuccess();        result.put("totalQuantity", new Double(totalQuantity));        return result;    }    /** Delete an item from the shopping cart. */    public Map deleteFromCart(Map context) {        Map result = null;        Set names = context.keySet();        Iterator i = names.iterator();        ArrayList errorMsgs = new ArrayList();        while (i.hasNext()) {            String o = (String) i.next();            if (o.toUpperCase().startsWith("DELETE")) {                try {                    String indexStr = o.substring(o.lastIndexOf('_') + 1);                    int index = Integer.parseInt(indexStr);                    try {                        this.cart.removeCartItem(index, dispatcher);                    } catch (CartItemModifyException e) {                        errorMsgs.add(e.getMessage());                    }                } catch (NumberFormatException nfe) {}            }        }        if (errorMsgs.size() > 0) {            result = ServiceUtil.returnError(errorMsgs);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);            return result; // don't return error because this is a non-critical error and should go back to the same page        }        result = ServiceUtil.returnSuccess();        return result;    }    /** Update the items in the shopping cart. */    public Map modifyCart(Security security, GenericValue userLogin, Map context, boolean removeSelected, String[] selectedItems, Locale locale) {        Map result = null;        if (locale == null) {            locale = this.cart.getLocale();        }        NumberFormat nf = NumberFormat.getNumberInstance(locale);        ArrayList deleteList = new ArrayList();        ArrayList errorMsgs = new ArrayList();        Set names = context.keySet();        Iterator i = names.iterator();        double oldQuantity = -1;        String oldDescription = "";        double oldPrice = -1;        if (this.cart.isReadOnlyCart()) {            String errMsg = UtilProperties.getMessage(resource, "cart.cart_is_in_read_only_mode", this.cart.getLocale());            errorMsgs.add(errMsg);            result = ServiceUtil.returnError(errorMsgs);            return result;        }        // TODO: This should be refactored to use UtilHttp.parseMultiFormData(parameters)        while (i.hasNext()) {            String o = (String) i.next();            int underscorePos = o.lastIndexOf('_');            if (underscorePos >= 0) {                try {                    String indexStr = o.substring(underscorePos + 1);                    int index = Integer.parseInt(indexStr);                    String quantString = (String) context.get(o);                    double quantity = -1;                    String itemDescription="";                    if (quantString != null) quantString = quantString.trim();                    // get the cart item                    ShoppingCartItem item = this.cart.findCartItem(index);                    if (o.toUpperCase().startsWith("OPTION")) {                        if (quantString.toUpperCase().startsWith("NO^")) {                            if (quantString.length() > 2) { // the length of the prefix                                String featureTypeId = this.getRemoveFeatureTypeId(o);                                if (featureTypeId != null) {                                    item.removeAdditionalProductFeatureAndAppl(featureTypeId);                                }                            }                        } else {                            GenericValue featureAppl = this.getFeatureAppl(item.getProductId(), o, quantString);                            if (featureAppl != null) {                                item.putAdditionalProductFeatureAndAppl(featureAppl);                            }                        }                    } else if (o.toUpperCase().startsWith("DESCRIPTION")) {                        itemDescription = quantString;  // the quantString is actually the description if the field name starts with DESCRIPTION                    } else if (o.startsWith("reservStart")) {                        // should have format: yyyy-mm-dd hh:mm:ss.fffffffff                        quantString += " 00:00:00.000000000";                         if (item != null) {                                Timestamp reservStart = Timestamp.valueOf((String) quantString);                                item.setReservStart(reservStart);                        }                    } else if (o.startsWith("reservLength")) {                        if (item != null) {                                double reservLength = nf.parse(quantString).doubleValue();                                item.setReservLength(reservLength);                        }                    } else if (o.startsWith("reservPersons")) {                        if (item != null) {                                double reservPersons = nf.parse(quantString).doubleValue();                                item.setReservPersons(reservPersons);                        }                    } else if (o.startsWith("shipBeforeDate")) {                        if (item != null && quantString.length() > 0) {                            // input is either yyyy-mm-dd or a full timestamp                            if (quantString.length() == 10)                                quantString += " 00:00:00.000";                             item.setShipBeforeDate(Timestamp.valueOf(quantString));                        }                    } else if (o.startsWith("shipAfterDate")) {                        if (item != null && quantString.length() > 0) {                            // input is either yyyy-mm-dd or a full timestamp                            if (quantString.length() == 10)                                quantString += " 00:00:00.000";                             item.setShipAfterDate(Timestamp.valueOf(quantString));                        }                    } else {                        quantity = nf.parse(quantString).doubleValue();                        if (quantity < 0) {                            throw new CartItemModifyException("Quantity must be a positive number.");                        }                    }                    // perhaps we need to reset the ship groups' before and after dates based on new dates for the items                    if (o.startsWith("shipAfterDate") || o.startsWith("shipBeforeDate")) {                        this.cart.setShipGroupShipDatesFromItem(item);                    }                                        if (o.toUpperCase().startsWith("UPDATE")) {                        if (quantity == 0.0) {                            deleteList.add(item);                        } else {                            if (item != null) {                                try {                                    // if, on a purchase order, the quantity has changed, get the new SupplierProduct entity for this quantity level.                                    if (cart.getOrderType().equals("PURCHASE_ORDER")) {                                        oldQuantity = item.getQuantity();                                        if (oldQuantity != quantity) {                                            // save the old description and price, in case the user wants to change those as well                                            oldDescription = item.getName();                                            oldPrice = item.getBasePrice();                                            GenericValue productSupplier = this.getProductSupplier(item.getProductId(), new Double(quantity), cart.getCurrency());                                            if (productSupplier == null) {                                                if ("_NA_".equals(cart.getPartyId())) {                                                    // no supplier does not require the supplier product                                                    item.setQuantity(quantity, dispatcher, this.cart);                                                    item.setName(item.getProduct().getString("internalName"));                                                } else {                                                    // in this case, the user wanted to purchase a quantity which is not available (probably below minimum)                                                    String errMsg = UtilProperties.getMessage(resource, "cart.product_not_valid_for_supplier", this.cart.getLocale());                                                    errMsg = errMsg + " (" + item.getProductId() + ", " + quantity + ", " + cart.getCurrency() + ")";                                                    errorMsgs.add(errMsg);                                                }                                            } else {                                                item.setQuantity(quantity, dispatcher, this.cart);                                                item.setBasePrice(productSupplier.getDouble("lastPrice").doubleValue());                                                item.setName(ShoppingCartItem.getPurchaseOrderItemDescription(item.getProduct(), productSupplier, cart.getLocale()));                                            }                                        }                                    } else {                                       item.setQuantity(quantity, dispatcher, this.cart);                                    }                                } catch (CartItemModifyException e) {                                    errorMsgs.add(e.getMessage());                                }                            }                        }                    }                    if (o.toUpperCase().startsWith("DESCRIPTION")) {                       if (!oldDescription.equals(itemDescription)){                           if (security.hasEntityPermission("ORDERMGR", "_CREATE", userLogin)) {                               if (item != null) {                                  item.setName(itemDescription);                               }                           }                       }                    }                    if (o.toUpperCase().startsWith("PRICE")) {                      NumberFormat pf = NumberFormat.getCurrencyInstance(locale);                      String tmpQuantity = pf.format(quantity);                      String tmpOldPrice = pf.format(oldPrice);                      if (!tmpOldPrice.equals(tmpQuantity)) {                        if (security.hasEntityPermission("ORDERMGR", "_CREATE", userLogin)) {                            if (item != null) {                               item.setBasePrice(quantity); // this is quantity because the parsed number variable is the same as quantity                             }                            }                        }                    }                    if (o.toUpperCase().startsWith("DELETE")) {                        deleteList.add(this.cart.findCartItem(index));                    }

⌨️ 快捷键说明

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