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

📄 shoppingcartitem.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                // check to see if salesDiscontinuationDate has passed        if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) {            String excMsg = "Tried to add the Product " + product.getString("productName") +                " (productId: " + product.getString("productId") + ") to the cart. This product is no longer available for sale, so not adding.";            Debug.logWarning(excMsg, module);            throw new CartItemModifyException(excMsg);        }        // check to see if the product is a rental item        if ("ASSET_USAGE".equals(product.getString("productTypeId"))) {            if (reservStart == null)    {                String excMsg = "The starting date of the reservation is missing....";                throw new CartItemModifyException(excMsg);            }            if (reservStart.before(UtilDateTime.nowTimestamp()))    {                String excMsg = "You can only make reservation starting tomorrow....";                throw new CartItemModifyException(excMsg);            }            newItem.setReservStart(reservStart);            if (reservLength < 1)    {                String excMsg = "Please enter a number of days, 1, or more....";                throw new CartItemModifyException(excMsg);            }            newItem.setReservLength(reservLength);            if (product.get("reservMaxPersons") != null) {                 double reservMaxPersons = product.getDouble("reservMaxPersons").doubleValue();                 if (reservMaxPersons < reservPersons)    {                     String excMsg = "The maximum number of persons renting this object is " + product.getString("reservMaxPersons") + " however you have requested: " + reservPersons + " !";                     Debug.logInfo(excMsg,module);                     throw new CartItemModifyException(excMsg);                 }             }             newItem.setReservPersons(reservPersons);             if (product.get("reserv2ndPPPerc") != null)                 newItem.setReserv2ndPPPerc(product.getDouble("reserv2ndPPPerc").doubleValue());             if (product.get("reservNthPPPerc") != null)                 newItem.setReservNthPPPerc(product.getDouble("reservNthPPPerc").doubleValue());            // check to see if the related fixed asset is available for rent            String isAvailable = checkAvailability(product.getString("productId"), quantity, reservStart, reservLength, cart);            if(isAvailable.compareTo("OK") != 0) {                String excMsg = "Product not available, ProductId:" + product.getString("productId") + " message:" + isAvailable.toString();                Debug.logInfo(excMsg, module);                throw new CartItemModifyException(isAvailable);            }        }                // check to see if the product is fully configured        if ("AGGREGATED".equals(product.getString("productTypeId"))) {            if (configWrapper == null || !configWrapper.isCompleted()) {                String excMsg = "Tried to add the Product " + product.getString("productName") +                    " (productId: " + product.getString("productId") + ") to the cart, not adding: the product is not configured correctly.";                Debug.logWarning(excMsg, module);                throw new CartItemModifyException(excMsg);            }        }                // set the ship before and after dates (defaults to cart ship before/after dates)        newItem.setShipBeforeDate(shipBeforeDate != null ? shipBeforeDate : cart.getDefaultShipBeforeDate());        newItem.setShipAfterDate(shipAfterDate != null ? shipAfterDate : cart.getDefaultShipAfterDate());                // set the product unit price as base price        // if triggerPriceRules is true this price will be overriden        newItem.setBasePrice(unitPrice);        // add to cart before setting quantity so that we can get order total, etc        if (cartLocation == null) {            cart.addItemToEnd(newItem);        } else {            cart.addItem(cartLocation.intValue(), newItem);        }        // We have to set the selectedAmount before calling setQuantity because        // selectedAmount changes the item's base price (used in the updatePrice        // method called inside the setQuantity method)        if (selectedAmount > 0) {            newItem.setSelectedAmount(selectedAmount);        }        try {            newItem.setQuantity(quantity, dispatcher, cart, triggerExternalOps, true, triggerPriceRules);        } catch (CartItemModifyException e) {            Debug.logWarning(e.getMessage(), module);            cart.removeCartItem(cart.getItemIndex(newItem), dispatcher);            cart.clearItemShipInfo(newItem);            cart.removeEmptyCartItems();            throw e;        }        return newItem;    }    // Calls makeItem(...) setting a default value, 0.00, for the selectedAmount    public static ShoppingCartItem makeItem(Integer cartLocation, GenericValue product, double quantity, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException {        return makeItem(cartLocation, product, 0.00, quantity, additionalProductFeatureAndAppls, attributes, prodCatalogId, dispatcher, cart, triggerExternalOps);    }    // Calls makeItem(...) setting a default value, 0.00, for unitPrice and setting the triggerProductPrice to true;    // in this way, the prices and price rules are automatically set by the updatePrice(...) method    public static ShoppingCartItem makeItem(Integer cartLocation, GenericValue product, double selectedAmount, double quantity, Timestamp reservStart, double reservLength, double reservPersons, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException {        return makeItem(cartLocation, product, selectedAmount, quantity, 0.0, reservStart, reservLength, reservPersons, null, null, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, dispatcher, cart, triggerExternalOps, true);    }    /**     * Makes a non-product ShoppingCartItem and adds it to the cart.     * NOTE: This is only for non-product items; items without a product entity (work items, bulk items, etc)     *     * @param cartLocation The location to place this item; null will place at the end     * @param itemType The OrderItemTypeId for the item being added     * @param itemDescription The optional description of the item     * @param productCategoryId The optional category the product *will* go in     * @param basePrice The price for this item     * @param selectedAmount     * @param quantity The quantity to add     * @param attributes All unique attributes for this item (NOT features)     * @param prodCatalogId The catalog this item was added from     * @param dispatcher LocalDispatcher object for doing promotions, etc     * @param cart The parent shopping cart object this item will belong to     * @param triggerExternalOps Indicates if we should run external operations (promotions, auto-save, etc)     * @return a new ShoppingCartItem object     * @throws CartItemModifyException     */    public static ShoppingCartItem makeItem(Integer cartLocation, String itemType, String itemDescription, String productCategoryId, double basePrice, double selectedAmount, double quantity, Map attributes, String prodCatalogId, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException {        GenericDelegator delegator = cart.getDelegator();        ShoppingCartItem newItem = new ShoppingCartItem(delegator, itemType, itemDescription, productCategoryId, basePrice, attributes, prodCatalogId, cart.getLocale());        // add to cart before setting quantity so that we can get order total, etc        if (cartLocation == null) {            cart.addItemToEnd(newItem);        } else {            cart.addItem(cartLocation.intValue(), newItem);        }        try {            newItem.setQuantity(quantity, dispatcher, cart, triggerExternalOps);        } catch (CartItemModifyException e) {            cart.removeEmptyCartItems();            throw e;        }        if (selectedAmount > 0) {            newItem.setSelectedAmount(selectedAmount);        }        return newItem;    }    /** Clone an item. */    public ShoppingCartItem(ShoppingCartItem item) {        try {            this._product = item.getProduct();        } catch (IllegalStateException e) {            this._product = null;        }        this.delegator = item.getDelegator();        this.delegatorName = item.delegatorName;        this.prodCatalogId = item.getProdCatalogId();        this.productId = item.getProductId();        this.itemType = item.getItemType();        this.productCategoryId = item.getProductCategoryId();        this.quantity = item.getQuantity();        this.reservStart = item.getReservStart();        this.reservLength = item.getReservLength();        this.reservPersons = item.getReservPersons();        this.selectedAmount = item.getSelectedAmount();        this.setBasePrice(item.getBasePrice());        this.setDisplayPrice(item.getDisplayPrice());        this.listPrice = item.getListPrice();        this.reserv2ndPPPerc = item.getReserv2ndPPPerc();        this.reservNthPPPerc = item.getReservNthPPPerc();        this.requirementId = item.getRequirementId();        this.quoteId = item.getQuoteId();        this.quoteItemSeqId = item.getQuoteItemSeqId();        this.isPromo = item.getIsPromo();        this.promoQuantityUsed = item.promoQuantityUsed;        this.locale = item.locale;        this.quantityUsedPerPromoCandidate = new HashMap(item.quantityUsedPerPromoCandidate);        this.quantityUsedPerPromoFailed = new HashMap(item.quantityUsedPerPromoFailed);        this.quantityUsedPerPromoActual = new HashMap(item.quantityUsedPerPromoActual);        this.orderItemSeqId = item.getOrderItemSeqId();        this.additionalProductFeatureAndAppls = item.getAdditionalProductFeatureAndAppls() == null ?                null : new HashMap(item.getAdditionalProductFeatureAndAppls());        this.attributes = item.getAttributes() == null ? new HashMap() : new HashMap(item.getAttributes());        this.contactMechIdsMap = item.getOrderItemContactMechIds() == null ? null : new HashMap(item.getOrderItemContactMechIds());        this.orderItemPriceInfos = item.getOrderItemPriceInfos() == null ? null : new LinkedList(item.getOrderItemPriceInfos());        this.itemAdjustments = item.getAdjustments() == null ? null : new LinkedList(item.getAdjustments());        if (this._product == null) {            this.itemDescription = item.getName();        }        if (item.configWrapper != null) {            this.configWrapper = new ProductConfigWrapper(item.configWrapper);        }    }    /** Cannot create shopping cart item with no parameters */    protected ShoppingCartItem() {}    /** Creates new ShoppingCartItem object. */    protected ShoppingCartItem(GenericValue product, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, Locale locale) {        this(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, null, locale);         if (product != null) {            String productName = ProductContentWrapper.getProductContentAsText(product, "PRODUCT_NAME", this.locale);            // if the productName is null or empty, see if there is an associated virtual product and get the productName of that product            if (UtilValidate.isEmpty(productName)) {                GenericValue parentProduct = this.getParentProduct();                if (parentProduct != null) {                    productName = ProductContentWrapper.getProductContentAsText(parentProduct, "PRODUCT_NAME", this.locale);                }            }            if (productName == null) {                this.itemDescription= "";            } else {                this.itemDescription= productName;            }        }    }    /** Creates new ShoppingCartItem object. */    protected ShoppingCartItem(GenericValue product, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, Locale locale) {        this._product = product;        this.productId = _product.getString("productId");        if (_product.getString("productTypeId").equals("ASSET_USAGE")) {            this.itemType = "RENTAL_ORDER_ITEM";  // will create additional workeffort/asset usage records        } else {            this.itemType = "PRODUCT_ORDER_ITEM";        }

⌨️ 快捷键说明

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