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

📄 shoppingcartservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            orderAdj.put("primaryGeoId", quoteAdj.get("primaryGeoId"));            orderAdj.put("secondaryGeoId", quoteAdj.get("secondaryGeoId"));            orderAdj.put("exemptAmount", quoteAdj.get("exemptAmount"));            orderAdj.put("taxAuthGeoId", quoteAdj.get("taxAuthGeoId"));            orderAdj.put("taxAuthPartyId", quoteAdj.get("taxAuthPartyId"));            orderAdj.put("overrideGlAccountId", quoteAdj.get("overrideGlAccountId"));            orderAdj.put("includeInTax", quoteAdj.get("includeInTax"));            orderAdj.put("includeInShipping", quoteAdj.get("includeInShipping"));            orderAdj.put("createdDate", quoteAdj.get("createdDate"));            orderAdj.put("createdByUserLogin", quoteAdj.get("createdByUserLogin"));            orderAdjs.add(orderAdj);        }        long nextItemSeq = 0;        if (quoteItems != null) {            Iterator i = quoteItems.iterator();            while (i.hasNext()) {                GenericValue item = (GenericValue) i.next();                // get the next item sequence id                String orderItemSeqId = item.getString("quoteItemSeqId");                try {                    long seq = Long.parseLong(orderItemSeqId);                    if (seq > nextItemSeq) {                        nextItemSeq = seq;                    }                } catch (NumberFormatException e) {                    Debug.logError(e, module);                    return ServiceUtil.returnError(e.getMessage());                }                boolean isPromo = item.get("isPromo") != null && "Y".equals(item.getString("isPromo"));                if (isPromo && !applyQuoteAdjustments) {                    // do not include PROMO items                    continue;                }                // not a promo item; go ahead and add it in                Double amount = item.getDouble("selectedAmount");                if (amount == null) {                    amount = new Double(0);                }                Double quantity = item.getDouble("quantity");                if (quantity == null) {                    quantity = new Double(0);                }                Double quoteUnitPrice = item.getDouble("quoteUnitPrice");                if (quoteUnitPrice == null) {                    quoteUnitPrice = new Double(0);                }                if (amount.doubleValue() > 0) {                    // If, in the quote, an amount is set, we need to                    // pass to the cart the quoteUnitPrice/amount value.                    quoteUnitPrice = new Double(quoteUnitPrice.doubleValue() / amount.doubleValue());                }                int itemIndex = -1;                if (item.get("productId") == null) {                    // non-product item                    String desc = item.getString("comments");                    try {                        itemIndex = cart.addNonProductItem(null, desc, null, 0.00, quantity.doubleValue(), null, null, dispatcher);                    } catch (CartItemModifyException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                } else {                    // product item                    String productId = item.getString("productId");                    try {                        itemIndex = cart.addItemToEnd(productId, amount.doubleValue(), quantity.doubleValue(), quoteUnitPrice.doubleValue(), null, null, null, dispatcher, !applyQuoteAdjustments, (quoteUnitPrice.doubleValue() == 0));                    } catch (ItemNotFoundException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    } catch (CartItemModifyException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                }                // flag the item w/ the orderItemSeqId so we can reference it                ShoppingCartItem cartItem = cart.findCartItem(itemIndex);                cartItem.setOrderItemSeqId(orderItemSeqId);                // attach additional item information                cartItem.setItemComment(item.getString("comments"));                cartItem.setQuoteId(item.getString("quoteId"));                cartItem.setQuoteItemSeqId(item.getString("quoteItemSeqId"));                cartItem.setIsPromo(isPromo);                //cartItem.setDesiredDeliveryDate(item.getTimestamp("estimatedDeliveryDate"));                //cartItem.setStatusId(item.getString("statusId"));                //cartItem.setItemType(item.getString("orderItemTypeId"));                //cartItem.setProductCategoryId(item.getString("productCategoryId"));                //cartItem.setShoppingList(item.getString("shoppingListId"), item.getString("shoppingListItemSeqId"));            }        }        // If applyQuoteAdjustments is set to false then standard cart adjustments are used.        if (applyQuoteAdjustments) {            // The cart adjustments, derived from quote adjustments, are added to the cart            List adjs = (List)orderAdjsMap.get(null);            if (adjs != null) {                cart.getAdjustments().addAll(adjs);            }            // The cart item adjustments, derived from quote item adjustments, are added to the cart            if (quoteItems != null) {                Iterator i = cart.iterator();                while (i.hasNext()) {                    ShoppingCartItem item = (ShoppingCartItem) i.next();                    adjs = (List)orderAdjsMap.get(item.getOrderItemSeqId());                    if (adjs != null) {                        item.getAdjustments().addAll(adjs);                    }                }            }        }        // set the item seq in the cart        if (nextItemSeq > 0) {            try {                cart.setNextItemSeq(nextItemSeq);            } catch (GeneralException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }        }        Map result = ServiceUtil.returnSuccess();        result.put("shoppingCart", cart);        return result;    }    public static Map loadCartFromShoppingList(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String shoppingListId = (String) context.get("shoppingListId");        Locale locale = (Locale) context.get("locale");        // get the shopping list header        GenericValue shoppingList = null;        try {            shoppingList = delegator.findByPrimaryKey("ShoppingList", UtilMisc.toMap("shoppingListId", shoppingListId));        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        // initial required cart info        String productStoreId = shoppingList.getString("productStoreId");        String currency = shoppingList.getString("currencyUom");        // create the cart        ShoppingCart cart = new ShoppingCart(delegator, productStoreId, locale, currency);        try {            cart.setUserLogin(userLogin, dispatcher);        } catch (CartItemModifyException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        // set the role information        cart.setOrderPartyId(shoppingList.getString("partyId"));        List shoppingListItems = null;        try {            shoppingListItems = shoppingList.getRelated("ShoppingListItem");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        long nextItemSeq = 0;        if (shoppingListItems != null) {            Iterator i = shoppingListItems.iterator();            while (i.hasNext()) {                GenericValue item = (GenericValue) i.next();                // get the next item sequence id                String orderItemSeqId = item.getString("shoppingListItemSeqId");                try {                    long seq = Long.parseLong(orderItemSeqId);                    if (seq > nextItemSeq) {                        nextItemSeq = seq;                    }                } catch (NumberFormatException e) {                    Debug.logError(e, module);                    return ServiceUtil.returnError(e.getMessage());                }                /*                Double amount = item.getDouble("selectedAmount");                if (amount == null) {                    amount = new Double(0);                }                 */                Double quantity = item.getDouble("quantity");                if (quantity == null) {                    quantity = new Double(0);                }                int itemIndex = -1;                if (item.get("productId") != null) {                    // product item                    String productId = item.getString("productId");                    try {                        itemIndex = cart.addItemToEnd(productId, 0.0, quantity.doubleValue(), null, new HashMap(), null, dispatcher);                    } catch (ItemNotFoundException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    } catch (CartItemModifyException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                }                // flag the item w/ the orderItemSeqId so we can reference it                ShoppingCartItem cartItem = cart.findCartItem(itemIndex);                cartItem.setOrderItemSeqId(orderItemSeqId);                // attach additional item information                cartItem.setShoppingList(item.getString("shoppingListId"), item.getString("shoppingListItemSeqId"));            }        }        // set the item seq in the cart        if (nextItemSeq > 0) {            try {                cart.setNextItemSeq(nextItemSeq);            } catch (GeneralException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }        }        Map result = ServiceUtil.returnSuccess();        result.put("shoppingCart", cart);        return result;    }}

⌨️ 快捷键说明

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