📄 shoppingcartitem.java
字号:
this.prodCatalogId = prodCatalogId; this.attributes = (attributes == null? FastMap.newInstance(): attributes); this.delegator = _product.getDelegator(); this.delegatorName = _product.getDelegator().getDelegatorName(); this.addAllProductFeatureAndAppls(additionalProductFeatureAndAppls); this.locale = locale; this.configWrapper = configWrapper; } /** Creates new ShopingCartItem object. */ protected ShoppingCartItem(GenericDelegator delegator, String itemTypeId, String description, String categoryId, double basePrice, Map attributes, String prodCatalogId, Locale locale) { this.delegator = delegator; this.itemType = itemTypeId; this.itemDescription = description; this.productCategoryId = categoryId; this.setBasePrice(basePrice); this.setDisplayPrice(basePrice); this.attributes = attributes; this.prodCatalogId = prodCatalogId; this.delegatorName = delegator.getDelegatorName(); this.locale = locale; } public String getProdCatalogId() { return this.prodCatalogId; } /** Sets the user selected amount */ public void setSelectedAmount(double selectedAmount) { this.selectedAmount = selectedAmount; } /** Returns the user selected amount */ public double getSelectedAmount() { return this.selectedAmount; } /** Sets the base price for the item; use with caution */ public void setBasePrice(double basePrice) { this.basePrice = basePrice; } /** Sets the display price for the item; use with caution */ public void setDisplayPrice(double displayPrice) { this.displayPrice = new Double(displayPrice); } public void setSpecialPromoPrice(Double specialPromoPrice) { this.specialPromoPrice = specialPromoPrice; } /** Sets the extra % for second person */ public void setReserv2ndPPPerc(double reserv2ndPPPerc) { this.reserv2ndPPPerc = reserv2ndPPPerc; } /** Sets the extra % for third and following person */ public void setReservNthPPPerc(double reservNthPPPerc) { this.reservNthPPPerc = reservNthPPPerc; } /** Sets the reservation start date */ public void setReservStart(Timestamp reservStart) { this.reservStart = reservStart; } /** Sets the reservation length */ public void setReservLength(double reservLength) { this.reservLength = reservLength; } /** Sets number of persons using the reservation */ public void setReservPersons(double reservPersons) { this.reservPersons = reservPersons; } /** Sets the quantity for the item and validates the change in quantity, etc */ public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart) throws CartItemModifyException { this.setQuantity(quantity, dispatcher, cart, true); } /** Sets the quantity for the item and validates the change in quantity, etc */ public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps) throws CartItemModifyException { this.setQuantity(quantity, dispatcher, cart, triggerExternalOps, true); } /** Sets the quantity for the item and validates the change in quantity, etc */ public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws CartItemModifyException { this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, true); } /** Sets the quantity for the item and validates the change in quantity, etc */ public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup, boolean updateProductPrice) throws CartItemModifyException { this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, updateProductPrice); } /** returns "OK" when the product can be booked or returns a string with the dates the related fixed Asset is not available */ public static String checkAvailability(String productId, double quantity, Timestamp reservStart, double reservLength, ShoppingCart cart) { GenericDelegator delegator = cart.getDelegator(); // find related fixedAsset List selFixedAssetProduct = null; GenericValue fixedAssetProduct = null; try { List allFixedAssetProduct = delegator.findByAnd("FixedAssetProduct", UtilMisc.toMap("productId", productId, "fixedAssetProductTypeId", "FAPT_USE")); selFixedAssetProduct = EntityUtil.filterByDate(allFixedAssetProduct, UtilDateTime.nowTimestamp(), "fromDate", "thruDate", true); } catch (GenericEntityException e) { return "Could not find a related Fixed Asset for the product: " + productId; } if (selFixedAssetProduct != null && selFixedAssetProduct.size() > 0) { Iterator firstOne = selFixedAssetProduct.iterator(); fixedAssetProduct = (GenericValue) firstOne.next(); } else { return "Could not find a related Fixed Asset for the product: " + productId; } // find the fixed asset itself GenericValue fixedAsset = null; try { fixedAsset = fixedAssetProduct.getRelatedOne("FixedAsset"); } catch (GenericEntityException e) { return "fixed_Asset_not_found. Fixed AssetId: " + fixedAssetProduct.getString("fixedAssetId"); } if (fixedAsset == null) { return "fixed_Asset_not_found. Fixed AssetId: " + fixedAssetProduct.getString("fixedAssetId"); } //Debug.logInfo("Checking availability for product: " + productId.toString() + " and related FixedAsset: " + fixedAssetProduct.getString("fixedAssetId"),module); // see if this fixed asset has a calendar, when no create one and attach to fixed asset // DEJ20050725 this isn't being used anywhere, commenting out for now and not assigning from the getRelatedOne: GenericValue techDataCalendar = null; try { fixedAsset.getRelatedOne("TechDataCalendar"); } catch (GenericEntityException e) { // no calendar ok, when not more that total capacity if (fixedAsset.getDouble("productionCapacity").doubleValue() >= quantity) { return "OK"; } else { return "Quantity requested: " + quantity + " Quantity available: " + fixedAsset.getString("productionCapacity"); } } // now find all the dates and check the availabilty for each date // please note that calendarId is the same for (TechData)Calendar, CalendarExcDay and CalendarExWeek long dayCount = 0; String resultMessage = ""; while (dayCount < (long) reservLength) { GenericValue techDataCalendarExcDay = null; // find an existing Day exception record Timestamp exceptionDateStartTime = new Timestamp((long) (reservStart.getTime() + (dayCount++ * 86400000))); try { techDataCalendarExcDay = delegator.findByPrimaryKey("TechDataCalendarExcDay", UtilMisc.toMap("calendarId", fixedAsset.get("calendarId"), "exceptionDateStartTime", exceptionDateStartTime)); } catch (GenericEntityException e) { if (fixedAsset.get("productionCapacity") != null) { //Debug.logInfo(" No exception day record found, available: " + fixedAsset.getString("productionCapacity") + " Requested now: " + quantity, module); if (fixedAsset.getDouble("productionCapacity").doubleValue() < quantity) resultMessage = resultMessage.concat(exceptionDateStartTime.toString().substring(0, 10) + ", "); } } if (techDataCalendarExcDay != null) { // see if we can get the number of assets available // first try techDataCalendarExcDay(exceptionCapacity) and then FixedAsset(productionCapacity) // if still zero, do not check availability double exceptionCapacity = 0.00; if (techDataCalendarExcDay.get("exceptionCapacity") != null) exceptionCapacity = techDataCalendarExcDay.getDouble("exceptionCapacity").doubleValue(); if (exceptionCapacity == 0.00 && fixedAsset.get("productionCapacity") != null) exceptionCapacity = fixedAsset.getDouble("productionCapacity").doubleValue(); if (exceptionCapacity != 0.00) { double usedCapacity = 0.00; if (techDataCalendarExcDay.get("usedCapacity") != null) usedCapacity = techDataCalendarExcDay.getDouble("usedCapacity").doubleValue(); if (exceptionCapacity < (quantity + usedCapacity)) { resultMessage = resultMessage.concat(exceptionDateStartTime.toString().substring(0, 10) + ", "); Debug.logInfo("No rental fixed Asset available: " + exceptionCapacity + " already used: " + usedCapacity + " Requested now: " + quantity, module); } } } } if (resultMessage.compareTo("") == 0) return "OK"; else return "I am sorry, not available at these dates: " + resultMessage + "item not added to the shopping cart....."; } protected void setQuantity(int quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup, boolean updateProductPrice) throws CartItemModifyException { if (this.quantity == quantity) { return; } if (this.isPromo) { throw new CartItemModifyException("Sorry, you can't change the quantity on the promotion item " + this.getName() + " (product ID: " + productId + "), not setting quantity."); } // needed for inventory checking and auto-save String productStoreId = cart.getProductStoreId(); if (!"PURCHASE_ORDER".equals(cart.getOrderType())) { // check inventory if new quantity is greater than old quantity; don't worry about inventory getting pulled out from under, that will be handled at checkout time if (_product != null && quantity > this.quantity) { try { Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", productId, "product", this.getProduct(), "quantity", new Double(quantity))); if (ServiceUtil.isError(invReqResult)) { Debug.logError("Error calling isStoreInventoryAvailableOrNotRequired service, result is: " + invReqResult, module); throw new CartItemModifyException((String) invReqResult.get(ModelService.ERROR_MESSAGE)); } else if (!"Y".equals((String) invReqResult.get("availableOrNotRequired"))) { String excMsg = "Sorry, we do not have enough (you tried " + UtilFormatOut.formatQuantity(quantity) + ") of the product " + this.getName() + " (product ID: " + productId + ") in stock, not adding to cart. Please try a lower quantity, try again later, or call customer service for more information."; Debug.logWarning(excMsg, module); throw new CartItemModifyException(excMsg); } } catch (GenericServiceException e) { String errMsg = "Fatal error calling inventory checking services: " + e.toString(); Debug.logError(e, errMsg, module); throw new CartItemModifyException(errMsg); } } } // set quantity before promos so order total, etc will be updated this.quantity = quantity; if (updateProductPrice) { this.updatePrice(dispatcher, cart); } // apply/unapply promotions if (triggerExternalOps) { ProductPromoWorker.doPromotions(cart, dispatcher); } if (!"PURCHASE_ORDER".equals(cart.getOrderType())) { // store the auto-save cart if (triggerExternalOps && ProductStoreWorker.autoSaveCart(delegator, productStoreId)) { try { ShoppingListEvents.fillAutoSaveList(cart, dispatcher); } catch (GeneralException e) { Debug.logWarning(e, UtilProperties.getMessage(resource_error,"OrderUnableToStoreAutoSaveCart", locale));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -