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

📄 shoppingcart.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /** Creates new empty ShoppingCart object. */    public ShoppingCart(GenericDelegator delegator, String productStoreId, String webSiteId, Locale locale, String currencyUom) {        this(delegator, productStoreId, webSiteId, locale, currencyUom, null, null);    }    /** Creates a new empty ShoppingCart object. */    public ShoppingCart(GenericDelegator delegator, String productStoreId, Locale locale, String currencyUom) {        this(delegator, productStoreId, null, locale, currencyUom);    }    public GenericDelegator getDelegator() {        if (delegator == null) {            delegator = GenericDelegator.getGenericDelegator(delegatorName);        }        return delegator;    }    public String getProductStoreId() {        return this.productStoreId;    }    /**     * This is somewhat of a dangerous method, changing the productStoreId changes a lot of stuff including:     * - some items in the cart may not be valid in any catalog in the new store     * - promotions need to be recalculated for the products that remain     * - what else? lots of settings on the ProductStore...     *     * So for now this can only be called if the cart is empty... otherwise it wil throw an exception     *     */    public void setProductStoreId(String productStoreId) {        if ((productStoreId == null && this.productStoreId == null) || (productStoreId != null && productStoreId.equals(this.productStoreId))) {            return;        }        if (this.size() == 0) {            this.productStoreId = productStoreId;        } else {            throw new IllegalArgumentException("Cannot set productStoreId when the cart is not empty; cart size is " + this.size());        }    }    public String getTransactionId() {        return this.transactionId;    }    public void setTransactionId(String transactionId) {        this.transactionId = transactionId;    }    public String getTerminalId() {        return this.terminalId;    }    public void setTerminalId(String terminalId) {        this.terminalId = terminalId;    }    public String getFacilityId() {        return this.facilityId;    }    public void setFacilityId(String facilityId) {        this.facilityId = facilityId;    }    public Locale getLocale() {        return locale;    }    public void setLocale(Locale locale) {        this.locale = locale;    }    public void setAttribute(String name, Object value) {        this.attributes.put(name, value);    }    public Object getAttribute(String name) {        return this.attributes.get(name);    }    public void removeOrderAttribute(String name) {        this.orderAttributes.remove(name);    }    public void setOrderAttribute(String name, String value) {        this.orderAttributes.put(name, value);    }    public String getOrderAttribute(String name) {        return (String) this.orderAttributes.get(name);    }    public void setHoldOrder(boolean b) {        this.holdOrder = b;    }    public boolean getHoldOrder() {        return this.holdOrder;    }    public void setOrderDate(Timestamp t) {        this.orderDate = t;    }    public Timestamp getOrderDate() {        return this.orderDate;    }        /** Sets the currency for the cart. */    public void setCurrency(LocalDispatcher dispatcher, String currencyUom) throws CartItemModifyException {        if (isReadOnlyCart()) {           throw new CartItemModifyException("Cart items cannot be changed");        }        String previousCurrency = this.currencyUom;        this.currencyUom = currencyUom;        if (!previousCurrency.equals(this.currencyUom)) {            Iterator itemIterator = this.iterator();            while (itemIterator.hasNext()) {                ShoppingCartItem item = (ShoppingCartItem) itemIterator.next();                item.updatePrice(dispatcher, this);            }        }    }    /** Get the current currency setting. */    public String getCurrency() {        if (this.currencyUom != null) {            return this.currencyUom;        } else {            // uh oh, not good, should always be passed in on init, we can't really do anything without it, so throw an exception            throw new IllegalStateException("The Currency UOM is not set in the shopping cart, this is not a valid state, it should always be passed in when the cart is created.");        }    }    public Timestamp getCartCreatedTime() {        return this.cartCreatedTs;    }    private GenericValue getSupplierProduct(String productId, double quantity, LocalDispatcher dispatcher) {        GenericValue supplierProduct = null;        Map params = UtilMisc.toMap("productId", productId,                                    "partyId", this.getPartyId(),                                    "currencyUomId", this.getCurrency(),                                    "quantity", new Double(quantity));        try {            Map result = dispatcher.runSync("getSuppliersForProduct", params);            List productSuppliers = (List)result.get("supplierProducts");            if ((productSuppliers != null) && (productSuppliers.size() > 0)) {                supplierProduct = (GenericValue) productSuppliers.get(0);            }            //} catch (GenericServiceException e) {        } catch (Exception e) {        	Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderRunServiceGetSuppliersForProductError", locale) + e.getMessage(), module);        }        return supplierProduct;    }    // =======================================================================    // Methods for cart items    // =======================================================================    /** Add an item to the shopping cart, or if already there, increase the quantity.     * @return the new/increased item index     * @throws CartItemModifyException     */    public int addOrIncreaseItem(String productId, double selectedAmount, double quantity, Timestamp reservStart, double reservLength, double reservPersons, Timestamp shipBeforeDate, Timestamp shipAfterDate, Map features, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        if (isReadOnlyCart()) {           throw new CartItemModifyException("Cart items cannot be changed");        }                GenericValue supplierProduct = null;        // Check for existing cart item.        for (int i = 0; i < this.cartLines.size(); i++) {            ShoppingCartItem sci = (ShoppingCartItem) cartLines.get(i);            if (sci.equals(productId, reservStart, reservLength, reservPersons, features, attributes, prodCatalogId, configWrapper, selectedAmount)) {                double newQuantity = sci.getQuantity() + quantity;                if (Debug.verboseOn()) Debug.logVerbose("Found a match for id " + productId + " on line " + i + ", updating quantity to " + newQuantity, module);                sci.setQuantity(newQuantity, dispatcher, this);                if (getOrderType().equals("PURCHASE_ORDER")) {                    supplierProduct = getSupplierProduct(productId, newQuantity, dispatcher);                    if (supplierProduct != null && supplierProduct.getDouble("lastPrice") != null) {                        sci.setBasePrice(supplierProduct.getDouble("lastPrice").doubleValue());                        sci.setName(ShoppingCartItem.getPurchaseOrderItemDescription(sci.getProduct(), supplierProduct, this.getLocale()));                    } else {                       throw new CartItemModifyException("SupplierProduct not found");                    }                 }                return i;            }        }        // Add the new item to the shopping cart if it wasn't found.        if (getOrderType().equals("PURCHASE_ORDER")) {            //GenericValue productSupplier = null;            supplierProduct = getSupplierProduct(productId, quantity, dispatcher);            if (supplierProduct != null || "_NA_".equals(this.getPartyId())) {                 return this.addItem(0, ShoppingCartItem.makePurchaseOrderItem(new Integer(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, dispatcher, this, supplierProduct, shipBeforeDate, shipAfterDate));            } else {                throw new CartItemModifyException("SupplierProduct not found");            }        } else {            return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), productId, selectedAmount, quantity, reservStart, reservLength, reservPersons, shipBeforeDate, shipAfterDate, features, attributes, prodCatalogId, configWrapper, dispatcher, this));        }    }    public int addOrIncreaseItem(String productId, double selectedAmount, double quantity, Map features, Map attributes, String prodCatalogId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        return addOrIncreaseItem(productId, 0.00, quantity, null, 0.00 ,0.00, null, null, features, attributes, prodCatalogId, null, dispatcher);    }    public int addOrIncreaseItem(String productId, double quantity, Map features, Map attributes, String prodCatalogId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        return addOrIncreaseItem(productId, 0.00, quantity, null, 0.00 ,0.00, null, null, features, attributes, prodCatalogId, null, dispatcher);    }    public int addOrIncreaseItem(String productId, double quantity, Timestamp reservStart, double reservLength, double reservPersons, Map features, Map attributes, String prodCatalogId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        return addOrIncreaseItem(productId, 0.00, quantity, reservStart, reservLength, reservPersons,  null, null, features, attributes, prodCatalogId, null, dispatcher);    }    public int addOrIncreaseItem(String productId, double quantity, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        return addOrIncreaseItem(productId, quantity, null, null, null, dispatcher);    }    /** Add a non-product item to the shopping cart.     * @return the new item index     * @throws CartItemModifyException     */    public int addNonProductItem(String itemType, String description, String categoryId, double price, double quantity, Map attributes, String prodCatalogId, LocalDispatcher dispatcher) throws CartItemModifyException {        return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), itemType, description, categoryId, price, 0.00, quantity, attributes, prodCatalogId, dispatcher, this, true));    }    /** Add an item to the shopping cart. */    public int addItem(int index, ShoppingCartItem item) throws CartItemModifyException {        if (isReadOnlyCart()) {           throw new CartItemModifyException("Cart items cannot be changed");        }        if (!cartLines.contains(item)) {            cartLines.add(index, item);            return index;        } else {            return this.getItemIndex(item);        }    }    /** Add an item to the shopping cart. */    public int addItemToEnd(String productId, double amount, double quantity,  HashMap features, HashMap attributes, String prodCatalogId, LocalDispatcher dispatcher, boolean triggerExternalOps) throws CartItemModifyException, ItemNotFoundException {        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, features, attributes, prodCatalogId, null, dispatcher, this, triggerExternalOps));    }    /** Add an item to the shopping cart. */    public int addItemToEnd(String productId, double amount, double quantity,  double unitPrice, HashMap features, HashMap attributes, String prodCatalogId, LocalDispatcher dispatcher, boolean triggerExternalOps, boolean triggerPriceRules) throws CartItemModifyException, ItemNotFoundException {        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, null, 0.00, 0.00, null, null, features, attributes, prodCatalogId, null, dispatcher, this, triggerExternalOps, triggerPriceRules));    }    /** Add an item to the shopping cart. */    public int addItemToEnd(String productId, double amount, double quantity,  HashMap features, HashMap attributes, String prodCatalogId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, features, attributes, prodCatalogId, dispatcher, this));    }    /** Add an item to the shopping cart. */    public int addItemToEnd(ShoppingCartItem item) throws CartItemModifyException {        if (isReadOnlyCart()) {           throw new CartItemModifyException("Cart items cannot be changed");        }        if (!cartLines.contains(item)) {            cartLines.add(item);            return cartLines.size() - 1;        } else {            return this.getItemIndex(item);        }    }    /** Get a ShoppingCartItem from the cart object. */    public ShoppingCartItem findCartItem(String productId, Map features, Map attributes, String prodCatalogId, double selectedAmount) {        // Check for existing cart item.        for (int i = 0; i < this.cartLines.size(); i++) {            ShoppingCartItem cartItem = (ShoppingCartItem) cartLines.get(i);            if (cartItem.equals(productId, features, attributes, prodCatalogId, selectedAmount)) {                return cartItem;            }        }        return null;    }    /** Get all ShoppingCartItems from the cart object with the given productId. */    public List findAllCartItems(String productId) {        if (productId == null) return new LinkedList(this.cartLines);        List itemsToReturn = new LinkedList();        // Check for existing cart item.        for (int i = 0; i < this.cartLines.size(); i++) {            ShoppingCartItem cartItem = (ShoppingCartItem) cartLines.get(i);            if (productId.equals(cartItem.getProductId())) {                itemsToReturn.add(cartItem);            }        }        return itemsToReturn;    }    /** Remove quantity 0 ShoppingCartItems from the cart object. */    public void removeEmptyCartItems() {        // Check for existing cart item.        for (int i = 0; i < this.cartLines.size();) {            ShoppingCartItem cartItem = (ShoppingCartItem) cartLines.get(i);            if (cartItem.getQuantity() == 0.0) {                this.clearItemShipInfo(cartItem);                cartLines.remove(i);            } else {                i++;            }        }    }    public boolean containAnyWorkEffortCartItems() {        // Check for existing cart item.        for (int i = 0; i < this.cartLines.size();) {            ShoppingCartItem cartItem = (ShoppingCartItem) cartLines.get(i);            if (cartItem.getItemType().equals("RENTAL_ORDER_ITEM")) {  // create workeffort items?                return true;

⌨️ 快捷键说明

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