📄 shoppingcartitem.java
字号:
* @param additionalProductFeatureAndAppls Product feature/appls map * @param attributes All unique attributes for this item (NOT features) * @param prodCatalogId The catalog this item was added from * @param configWrapper The product configuration wrapper (null if the product is not configurable) * @param dispatcher LocalDispatcher object for doing promotions, etc * @param cart The parent shopping cart object this item will belong to * @return a new ShoppingCartItem object * @throws CartItemModifyException */ public static ShoppingCartItem makeItem(Integer cartLocation, String productId, double selectedAmount, double quantity, double unitPrice, Timestamp reservStart, double reservLength, double reservPersons, Timestamp shipBeforeDate, Timestamp shipAfterDate, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean triggerProductPrice) throws CartItemModifyException, ItemNotFoundException { GenericDelegator delegator = cart.getDelegator(); GenericValue product = null; try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); // first see if there is a purchase allow category and if this product is in it or not String purchaseProductCategoryId = CatalogWorker.getCatalogPurchaseAllowCategoryId(delegator, prodCatalogId); if (purchaseProductCategoryId != null) { if (!CategoryWorker.isProductInCategory(delegator, product.getString("productId"), purchaseProductCategoryId)) { // a Purchase allow productCategoryId was found, but the product is not in the category, axe it... product = null; } } } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); product = null; } if (product == null) { Map messageMap = UtilMisc.toMap("productId", productId ); String excMsg = UtilProperties.getMessage(resource, "item.product_not_found", messageMap , cart.getLocale() ); Debug.logWarning(excMsg, module); throw new ItemNotFoundException(excMsg); } return makeItem(cartLocation, product, selectedAmount, quantity, unitPrice, reservStart, reservLength, reservPersons, shipBeforeDate, shipAfterDate, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, dispatcher, cart, triggerExternalOps, triggerProductPrice); } /** * Makes a ShoppingCartItem for a purchase order item and adds it to the cart. * NOTE: This method will get the product entity and check to make sure it can be purchased. * * @param cartLocation The location to place this item; null will place at the end * @param productId The primary key of the product being added * @param quantity The quantity to add * @param additionalProductFeatureAndAppls Product feature/appls map * @param attributes All unique attributes for this item (NOT features) * @param prodCatalogId The catalog this item was added from * @param configWrapper The product configuration wrapper (null if the product is not configurable) * @param dispatcher LocalDispatcher object for doing promotions, etc * @param cart The parent shopping cart object this item will belong to * @param supplierProduct GenericValue of SupplierProduct entity, containing product description and prices * @param shipBeforeDate Request that the shipment be made before this date * @param shipAfterDate Request that the shipment be made after this date * @return a new ShoppingCartItem object * @throws CartItemModifyException */ public static ShoppingCartItem makePurchaseOrderItem(Integer cartLocation, String productId, double selectedAmount, double quantity, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher, ShoppingCart cart, GenericValue supplierProduct, Timestamp shipBeforeDate, Timestamp shipAfterDate) throws CartItemModifyException, ItemNotFoundException { GenericDelegator delegator = cart.getDelegator(); GenericValue product = null; try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); product = null; } if (product == null) { Map messageMap = UtilMisc.toMap("productId", productId ); String excMsg = UtilProperties.getMessage(resource, "item.product_not_found", messageMap , cart.getLocale() ); Debug.logWarning(excMsg, module); throw new ItemNotFoundException(excMsg); } ShoppingCartItem newItem = new ShoppingCartItem(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, cart.getLocale()); // check to see if product is virtual if ("Y".equals(product.getString("isVirtual"))) { String excMsg = "Tried to add the Virtual Product " + product.getString("productName") + " (productId: " + product.getString("productId") + ") to the cart, not adding."; Debug.logWarning(excMsg, module); throw new CartItemModifyException(excMsg); } // Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); // 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); } } // 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); } if (selectedAmount > 0) { newItem.setSelectedAmount(selectedAmount); } // set the ship before/after dates. this needs to happen before setQuantity because setQuantity causes the ship group's dates to be // checked versus the cart item's newItem.setShipBeforeDate(shipBeforeDate != null ? shipBeforeDate : cart.getDefaultShipBeforeDate()); newItem.setShipAfterDate(shipAfterDate != null ? shipAfterDate : cart.getDefaultShipAfterDate()); try { newItem.setQuantity(quantity, dispatcher, cart, true); } catch (CartItemModifyException e) { cart.removeCartItem(cart.getItemIndex(newItem), dispatcher); cart.clearItemShipInfo(newItem); cart.removeEmptyCartItems(); throw e; } // specific for purchase orders - description is set to supplierProductId + supplierProductName, price set to lastPrice of SupplierProduct // if supplierProduct has no supplierProductName, use the regular supplierProductId if (supplierProduct != null) { newItem.setName(getPurchaseOrderItemDescription(product, supplierProduct, cart.getLocale())); newItem.setBasePrice(supplierProduct.getDouble("lastPrice").doubleValue()); } else { newItem.setName(product.getString("internalName")); } return newItem; } /** * Makes a ShoppingCartItem and adds it to the cart. * WARNING: This method does not check if the product is in a purchase category. * * @param cartLocation The location to place this item; null will place at the end * @param product The product entity relating to the product being added * @param quantity The quantity to add * @param additionalProductFeatureAndAppls Product feature/appls map * @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, GenericValue product, double selectedAmount, double quantity, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException { return ShoppingCartItem.makeItem(cartLocation, product, selectedAmount, quantity, additionalProductFeatureAndAppls, attributes, prodCatalogId, null, dispatcher, cart, triggerExternalOps); } /** * Makes a ShoppingCartItem and adds it to the cart. * WARNING: This method does not check if the product is in a purchase category. * * @param cartLocation The location to place this item; null will place at the end * @param product The product entity relating to the product being added * @param quantity The quantity to add * @param additionalProductFeatureAndAppls Product feature/appls map * @param attributes All unique attributes for this item (NOT features) * @param prodCatalogId The catalog this item was added from * @param configWrapper The product configuration wrapper (null if the product is not configurable) * @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, GenericValue product, double selectedAmount, double quantity, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException { return ShoppingCartItem.makeItem(cartLocation, product, selectedAmount, quantity, null, 0.00, 0.00, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, dispatcher, cart, triggerExternalOps); } /** * Makes a ShoppingCartItem and adds it to the cart. * WARNING: This method does not check if the product is in a purchase category. * rental fields were added. * * @param cartLocation The location to place this item; null will place at the end * @param product The product entity relating to the product being added * @param quantity The quantity to add * @param reservStart the start of the reservation * @param reservLength the reservation length * @param reservPersons the number of persons using the reservation * @param shipBeforeDate The date to ship the order by * @param shipAfterDate Wait until this date to ship * @param additionalProductFeatureAndAppls Product feature/appls map * @param attributes All unique attributes for this item (NOT features) * @param prodCatalogId The catalog this item was added from * @param configWrapper The product configuration wrapper (null if the product is not configurable) * @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, 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 { public static ShoppingCartItem makeItem(Integer cartLocation, GenericValue product, double selectedAmount, double quantity, double unitPrice, Timestamp reservStart, double reservLength, double reservPersons, Timestamp shipBeforeDate, Timestamp shipAfterDate, Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean triggerPriceRules) throws CartItemModifyException { ShoppingCartItem newItem = new ShoppingCartItem(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, cart.getLocale()); // check to see if product is virtual if ("Y".equals(product.getString("isVirtual"))) { String excMsg = "Tried to add the Virtual Product " + product.getString("productName") + " (productId: " + product.getString("productId") + ") to the cart, not adding."; Debug.logWarning(excMsg, module); throw new CartItemModifyException(excMsg); } java.sql.Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); // check to see if introductionDate hasn't passed yet if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) { String excMsg = "Tried to add the Product " + product.getString("productName") + " (productId: " + product.getString("productId") + ") to the cart. This product has not yet been made available for sale, so not adding."; Debug.logWarning(excMsg, module); throw new CartItemModifyException(excMsg); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -