Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=757091&r1=757090&r2=757091&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Sat Mar 21 23:44:41 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -65,8 +65,8 @@ public static final int taxCalcScale = UtilNumber.getBigDecimalScale("salestax.calc.decimals"); public static final int taxFinalScale = UtilNumber.getBigDecimalScale("salestax.final.decimals"); public static final int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding"); - public static final BigDecimal ZERO = BigDecimal.ZERO; - public static final BigDecimal percentage = new BigDecimal("0.01"); + public static final BigDecimal ZERO = BigDecimal.ZERO; + public static final BigDecimal percentage = new BigDecimal("0.01"); public static final MathContext generalRounding = new MathContext(10); @@ -123,7 +123,7 @@ /** these are defaults for all ship groups */ private Timestamp defaultShipAfterDate = null; private Timestamp defaultShipBeforeDate = null; - + /** Contains a List for each productPromoId (key) containing a productPromoCodeId (or empty string for no code) for each use of the productPromoId */ private List productPromoUseInfoList = new LinkedList(); /** Contains the promo codes entered */ @@ -197,11 +197,11 @@ this.defaultShipAfterDate = cart.getDefaultShipAfterDate(); this.defaultShipBeforeDate = cart.getDefaultShipBeforeDate(); this.cancelBackOrderDate = cart.getCancelBackOrderDate(); - + this.terminalId = cart.getTerminalId(); this.transactionId = cart.getTransactionId(); this.autoOrderShoppingListId = cart.getAutoOrderShoppingListId(); - + // clone the additionalPartyRoleMap this.additionalPartyRole = new HashMap(); Iterator it = cart.additionalPartyRole.entrySet().iterator(); @@ -250,7 +250,7 @@ if (productStore == null) { throw new IllegalArgumentException("Unable to locate ProductStore by ID [" + productStoreId + "]"); } - + String storeViewCartOnAdd = productStore.getString("viewCartOnAdd"); if (storeViewCartOnAdd != null && "Y".equalsIgnoreCase(storeViewCartOnAdd)) { this.viewCartOnAdd = true; @@ -351,7 +351,7 @@ public void setOrderName(String orderName) { this.orderName = orderName; } - + public String getOrderName() { return orderName; } @@ -359,7 +359,7 @@ public void setWorkEffortId(String workEffortId) { this.workEffortId = workEffortId; } - + public String getWorkEffortId() { return workEffortId; } @@ -399,7 +399,7 @@ public Timestamp getOrderDate() { return this.orderDate; } - + /** Sets the currency for the cart. */ public void setCurrency(LocalDispatcher dispatcher, String currencyUom) throws CartItemModifyException { if (isReadOnlyCart()) { @@ -457,35 +457,35 @@ * @return the new/increased item index * @throws CartItemModifyException */ - public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, - Timestamp shipBeforeDate, Timestamp shipAfterDate, Map features, Map attributes, String prodCatalogId, + public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, + Timestamp shipBeforeDate, Timestamp shipAfterDate, Map features, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, String itemType, String itemGroupNumber, String parentProductId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException { - - return addOrIncreaseItem(productId,selectedAmount,quantity,reservStart,reservLength,reservPersons, - null,null,shipBeforeDate,shipAfterDate,features,attributes,prodCatalogId, + + return addOrIncreaseItem(productId,selectedAmount,quantity,reservStart,reservLength,reservPersons, + null,null,shipBeforeDate,shipAfterDate,features,attributes,prodCatalogId, configWrapper,itemType,itemGroupNumber,parentProductId,dispatcher); } - + /** add rental (with accommodation) item to cart */ - public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, + public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId, String accommodationSpotId, - Timestamp shipBeforeDate, Timestamp shipAfterDate, Map features, Map attributes, String prodCatalogId, + Timestamp shipBeforeDate, Timestamp shipAfterDate, Map features, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, String itemType, String itemGroupNumber, String parentProductId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException { if (isReadOnlyCart()) { throw new CartItemModifyException("Cart items cannot be changed"); } - + selectedAmount = selectedAmount == null ? BigDecimal.ZERO : selectedAmount; reservLength = reservLength == null ? BigDecimal.ZERO : reservLength; reservPersons = reservPersons == null ? BigDecimal.ZERO : reservPersons; - + ShoppingCart.ShoppingCartItemGroup itemGroup = this.getItemGroupByNumber(itemGroupNumber); 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, accommodationMapId, accommodationSpotId, features, attributes, prodCatalogId,selectedAmount, configWrapper, itemType, itemGroup, false)) { BigDecimal newQuantity = sci.getQuantity().add(quantity); if (sci.getItemType().equals("RENTAL_ORDER_ITEM")) { @@ -493,12 +493,12 @@ String isAvailable = ShoppingCartItem.checkAvailability(productId, newQuantity, reservStart, reservLength, this); if (isAvailable.compareTo("OK") != 0) { Map messageMap = UtilMisc.toMap("productId", productId, "availableMessage", isAvailable); - String excMsg = UtilProperties.getMessage(ShoppingCartItem.resource, "item.product_not_available", messageMap, this.getLocale() ); + String excMsg = UtilProperties.getMessage(ShoppingCartItem.resource, "item.product_not_available", messageMap, this.getLocale() ); Debug.logInfo(excMsg, module); throw new CartItemModifyException(isAvailable); } } - + if (Debug.verboseOn()) Debug.logVerbose("Found a match for id " + productId + " on line " + i + ", updating quantity to " + newQuantity, module); sci.setQuantity(newQuantity, dispatcher, this); @@ -524,9 +524,9 @@ throw new CartItemModifyException("SupplierProduct not found"); } } else { - return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), productId, selectedAmount, quantity, null, - reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, - features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, + return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), productId, selectedAmount, quantity, null, + reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, + features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, this, Boolean.TRUE, Boolean.TRUE, parentProductId, Boolean.FALSE, Boolean.FALSE)); } } @@ -535,7 +535,7 @@ * @return the new item index * @throws CartItemModifyException */ - public int addNonProductItem(String itemType, String description, String categoryId, BigDecimal price, BigDecimal quantity, + public int addNonProductItem(String itemType, String description, String categoryId, BigDecimal price, BigDecimal quantity, Map attributes, String prodCatalogId, String itemGroupNumber, LocalDispatcher dispatcher) throws CartItemModifyException { ShoppingCart.ShoppingCartItemGroup itemGroup = this.getItemGroupByNumber(itemGroupNumber); return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), itemType, description, categoryId, price, null, quantity, attributes, prodCatalogId, itemGroup, dispatcher, this, Boolean.TRUE)); @@ -578,7 +578,7 @@ /** Add an (rental)item to the shopping cart. */ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules) throws CartItemModifyException, ItemNotFoundException { return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, reservStart, reservLength, reservPersons, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, Boolean.FALSE, Boolean.FALSE)); - } + } /** Add an (rental)item to the shopping cart. */ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException { @@ -593,7 +593,7 @@ /** Add an accommodation(rental )item to the shopping cart. */ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId, String accommodationSpotId, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules) throws CartItemModifyException, ItemNotFoundException { return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, Boolean.FALSE, Boolean.FALSE)); - } + } /** Add an accommodation(rental)item to the shopping cart. */ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId, String accommodationSpotId, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException { @@ -604,7 +604,7 @@ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersonsDbl,String accommodationMapId, String accommodationSpotId, HashMap features, HashMap attributes, String prodCatalogId, ProductConfigWrapper configWrapper, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException { return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, reservStart, reservLength, reservPersonsDbl, accommodationMapId, accommodationSpotId, null, null, features, attributes, prodCatalogId, configWrapper, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, skipInventoryChecks, skipProductChecks)); } - + /** Add an item to the shopping cart. */ public int addItemToEnd(String productId, BigDecimal amount, BigDecimal quantity, BigDecimal unitPrice, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException { return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, null, null, null, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, skipInventoryChecks, skipProductChecks)); @@ -659,7 +659,7 @@ // Check for existing cart item for (ShoppingCartItem cartItem : cartLines) { //Debug.logInfo("Checking cartItem with product [" + cartItem.getProductId() + "] becuase that is in group [" + (cartItem.getItemGroup()==null ? "no group" : cartItem.getItemGroup().getGroupNumber()) + "]", module); - + if (UtilValidate.isNotEmpty(groupNumber) && !cartItem.isInItemGroup(groupNumber)) { //Debug.logInfo("Not using cartItem with product [" + cartItem.getProductId() + "] becuase not in group [" + groupNumber + "]", module); continue; @@ -696,7 +696,7 @@ public void removeExtraItems(List multipleItems, LocalDispatcher dispatcher, int maxItems) throws CartItemModifyException { // if 1 or 0 items, do nothing if (multipleItems.size() <= maxItems) return; - + // remove all except first <maxItems> in list from the cart, first because new cart items are added to the beginning... List localList = FastList.newInstance(); localList.addAll(multipleItems); @@ -718,7 +718,7 @@ } return totalQuantity; } - + public static List getItemsProducts(List cartItems) { List productList = FastList.newInstance(); Iterator localIter = cartItems.iterator(); @@ -731,7 +731,7 @@ } return productList; } - + public void ensureItemsQuantity(List cartItems, LocalDispatcher dispatcher, BigDecimal quantity) throws CartItemModifyException { Iterator localIter = cartItems.iterator(); while (localIter.hasNext()) { @@ -741,7 +741,7 @@ } } } - + public BigDecimal ensureItemsTotalQuantity(List cartItems, LocalDispatcher dispatcher, BigDecimal quantity) throws CartItemModifyException { BigDecimal quantityRemoved = BigDecimal.ZERO; // go through the items and reduce quantityToKeep by the item quantities until it is 0, then remove the remaining... @@ -749,9 +749,9 @@ Iterator localIter = cartItems.iterator(); while (localIter.hasNext()) { ShoppingCartItem item = (ShoppingCartItem) localIter.next(); - + if (quantityToKeep.compareTo(item.getQuantity()) >= 0) { - // quantityToKeep sufficient to keep it all... just reduce quantityToKeep and move on + // quantityToKeep sufficient to keep it all... just reduce quantityToKeep and move on quantityToKeep = quantityToKeep.subtract(item.getQuantity()); } else { // there is more in this than we want to keep, so reduce the quantity, or remove altogether... @@ -769,7 +769,7 @@ } return quantityRemoved; } - + // ============== WorkEffort related methods =============== public boolean containAnyWorkEffortCartItems() { // Check for existing cart item. @@ -792,10 +792,10 @@ } return true; } - - /** - * Check to see if the cart contains only Digital Goods, ie no Finished Goods and no Finished/Digital Goods, et cetera. - * This is determined by making sure no Product has a type where ProductType.isPhysical!=N. + + /** + * Check to see if the cart contains only Digital Goods, ie no Finished Goods and no Finished/Digital Goods, et cetera. + * This is determined by making sure no Product has a type where ProductType.isPhysical!=N. */ public boolean containOnlyDigitalGoods() { for (int i = 0; i < this.cartLines.size(); i++) { @@ -884,7 +884,7 @@ public Iterator iterator() { return cartLines.iterator(); } - + public ShoppingCart.ShoppingCartItemGroup getItemGroupByNumber(String groupNumber) { if (UtilValidate.isEmpty(groupNumber)) return null; return (ShoppingCart.ShoppingCartItemGroup) this.itemGroupByNumberMap.get(groupNumber); @@ -898,7 +898,7 @@ this.itemGroupByNumberMap.put(newGroup.getGroupNumber(), newGroup); return newGroup.getGroupNumber(); } - + public List getCartItemsInNoGroup() { List cartItemList = FastList.newInstance(); for (ShoppingCartItem cartItem : cartLines) { @@ -908,7 +908,7 @@ } return cartItemList; } - + public List getCartItemsInGroup(String groupNumber) { List cartItemList = FastList.newInstance(); ShoppingCart.ShoppingCartItemGroup itemGroup = this.getItemGroupByNumber(groupNumber); @@ -921,7 +921,7 @@ } return cartItemList; } - + public void deleteItemGroup(String groupNumber) { ShoppingCartItemGroup itemGroup = this.getItemGroupByNumber(groupNumber); if (itemGroup != null) { @@ -932,7 +932,7 @@ ShoppingCartItem cartItem = (ShoppingCartItem) cartItemIter.next(); cartItem.setItemGroup(null); } - + // if this is a parent of any set them to this group's parent (or null) Iterator itemGroupIter = this.itemGroupByNumberMap.values().iterator(); while (itemGroupIter.hasNext()) { @@ -941,12 +941,12 @@ otherItemGroup.inheritParentsParent(); } } - + // finally, remove the itemGroup... this.itemGroupByNumberMap.remove(groupNumber); } } - + //======================================================= // Other General Info Maintenance Methods //======================================================= @@ -1111,29 +1111,29 @@ } public void setDefaultShipBeforeDate(Timestamp defaultShipBeforeDate) { - this.defaultShipBeforeDate = defaultShipBeforeDate; + this.defaultShipBeforeDate = defaultShipBeforeDate; } - + public Timestamp getDefaultShipBeforeDate() { return this.defaultShipBeforeDate; } - + public void setDefaultShipAfterDate(Timestamp defaultShipAfterDate) { this.defaultShipAfterDate = defaultShipAfterDate; } - + public void setCancelBackOrderDate(Timestamp cancelBackOrderDate) { - this.cancelBackOrderDate = cancelBackOrderDate; + this.cancelBackOrderDate = cancelBackOrderDate; } - + public Timestamp getCancelBackOrderDate() { return this.cancelBackOrderDate; } - + public Timestamp getDefaultShipAfterDate() { return this.defaultShipAfterDate; } - + public String getOrderPartyId() { return this.orderPartyId != null ? this.orderPartyId : this.getPartyId(); } @@ -1542,7 +1542,7 @@ paymentInfo.remove(inf); } paymentInfo.add(inf); - + return inf; } @@ -1581,7 +1581,7 @@ } return null; } - + /** returns the total payment amounts */ public BigDecimal getPaymentTotal() { BigDecimal total = BigDecimal.ZERO; @@ -1641,14 +1641,14 @@ if (!UtilValidate.isEmpty(declinedPaymentMethods)) { List paymentMethodIdsToRemove = new ArrayList(); for (Iterator iter = declinedPaymentMethods.iterator(); iter.hasNext(); ) { - GenericValue opp = (GenericValue) iter.next(); + GenericValue opp = (GenericValue) iter.next(); paymentMethodIdsToRemove.add(opp.getString("paymentMethodId")); } clearPaymentMethodsById(paymentMethodIdsToRemove); } } catch (GenericEntityException ex) { Debug.logError("Unable to remove declined payment methods from cart due to " + ex.getMessage(), module); - return; + return; } } } @@ -1827,7 +1827,7 @@ public GenericValue getGiftCertSettingFromStore(GenericDelegator delegator) throws GenericEntityException { return delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", getProductStoreId(), "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId)); } - + /** * Determines whether pin numbers are required for gift cards, based on ProductStoreFinActSetting. Default to true. * @return @@ -1850,7 +1850,7 @@ return true; } } - + /** * Returns whether the cart should validate gift cards against FinAccount (ie, internal gift certificates). Defaults to false. * @param delegator @@ -1874,7 +1874,7 @@ return false; } } - + // ======================================================================= // Billing Accounts // ======================================================================= @@ -1986,23 +1986,23 @@ /** * Updates the shipBefore and shipAfterDates of all ship groups that the item belongs to, re-setting * ship group ship before date if item ship before date is before it and ship group ship after date if - * item ship after date is before it. + * item ship after date is before it. * @param item */ public void setShipGroupShipDatesFromItem(ShoppingCartItem item) { Map shipGroups = this.getShipGroups(item); - + if ((shipGroups != null) && (shipGroups.keySet() != null)) { for (Iterator shipGroupKeys = shipGroups.keySet().iterator(); shipGroupKeys.hasNext(); ) { Integer shipGroup = (Integer) shipGroupKeys.next(); CartShipInfo cartShipInfo = this.getShipInfo(shipGroup.intValue()); - + cartShipInfo.resetShipAfterDateIfBefore(item.getShipAfterDate()); cartShipInfo.resetShipBeforeDateIfAfter(item.getShipBeforeDate()); } } } - + public BigDecimal getItemShipGroupEstimate(int idx) { CartShipInfo csi = this.getShipInfo(idx); return csi.shipEstimate; @@ -2029,11 +2029,11 @@ if (quantity.compareTo(item.getQuantity()) > 0) { quantity = item.getQuantity(); } - + // re-set the ship group's before and after dates based on the item's csi.resetShipBeforeDateIfAfter(item.getShipBeforeDate()); csi.resetShipAfterDateIfBefore(item.getShipAfterDate()); - + CartShipInfo.CartShipItemInfo csii = csi.setItemInfo(item, quantity); this.checkShipItemInfo(csi, csii); } @@ -2313,7 +2313,7 @@ public String getProductStoreShipMethId() { return productStoreShipMethId; - } + } public void setProductStoreShipMethId(String productStoreShipMethId) { this.productStoreShipMethId = productStoreShipMethId; @@ -2343,7 +2343,7 @@ CartShipInfo csi = this.getShipInfo(idx); csi.shipGroupSeqId = shipGroupSeqId; } - + public String getShipGroupSeqId(int idx) { CartShipInfo csi = this.getShipInfo(idx); return csi.shipGroupSeqId; @@ -2381,7 +2381,7 @@ public List getInternalOrderNotes() { return this.internalOrderNotes; } - + public List getOrderNotes() { return this.orderNotes; } @@ -2646,7 +2646,7 @@ public int addOrderTerm(String termTypeId, BigDecimal termValue, Long termDays) { return addOrderTerm(termTypeId, termValue, termDays, null); } - + /** Add an orderTerm to the order */ public int addOrderTerm(String termTypeId, BigDecimal termValue, Long termDays, String textValue) { GenericValue orderTerm = GenericValue.create(delegator.getModelEntity("OrderTerm")); @@ -3010,7 +3010,7 @@ public Iterator getProductPromoUseInfoIter() { return productPromoUseInfoList.iterator(); } - + public BigDecimal getProductPromoTotal() { BigDecimal totalDiscount = BigDecimal.ZERO; List cartAdjustments = this.getAdjustments(); @@ -3249,13 +3249,13 @@ // ======================================================================= // Methods used for order creation // ======================================================================= - + /** * Returns the Id of an AGGREGATED_CONF product having exact configId. * If AGGREGATED_CONF product do not exist, creates one, associates it to the AGGREGATED product, and copy its production run template. * @param item * @param dispatcher - */ + */ public String getAggregatedInstanceId (ShoppingCartItem item, LocalDispatcher dispatcher) { if (UtilValidate.isEmpty(item.getConfigWrapper()) || UtilValidate.isEmpty(item.getConfigWrapper().getConfigId())) { return null; @@ -3268,7 +3268,7 @@ if (configId.equals(newProductId)) { return newProductId; } - + //create new product and associate it GenericValue product = item.getProduct(); String productName = product.getString("productName"); @@ -3285,27 +3285,27 @@ serviceContext.put("requirementMethodEnumId", product.getString("requirementMethodEnumId")); } serviceContext.put("userLogin", permUserLogin); - + Map result = dispatcher.runSync("createProduct", serviceContext); if (ServiceUtil.isError(result)) { Debug.logError(ServiceUtil.getErrorMessage(result), module); return null; } - + serviceContext.clear(); newProductId = (String) result.get("productId"); serviceContext.put("productId", item.getProductId()); serviceContext.put("productIdTo", newProductId); serviceContext.put("productAssocTypeId", "PRODUCT_CONF"); serviceContext.put("fromDate", UtilDateTime.nowTimestamp()); - serviceContext.put("userLogin", permUserLogin); + serviceContext.put("userLogin", permUserLogin); result = dispatcher.runSync("createProductAssoc", serviceContext); if (ServiceUtil.isError(result)) { Debug.logError(ServiceUtil.getErrorMessage(result), module); return null; } - + //create a new WorkEffortGoodStandard based on existing one of AGGREGATED product . //Another approach could be to get WorkEffortGoodStandard of the AGGREGATED product while creating production run. List productionRunTemplates = getDelegator().findByAnd("WorkEffortGoodStandard", UtilMisc.toMap("productId", item.getProductId(), "workEffortGoodStdTypeId", "ROU_PROD_TEMPLATE", "statusId", "WEGS_CREATED")); @@ -3324,7 +3324,7 @@ return null; } } - + } catch (Exception e) { Debug.logError(e, module); return null; @@ -3332,7 +3332,7 @@ return newProductId; } - + public List makeOrderItemGroups() { List result = FastList.newInstance(); Iterator groupValueIter = this.itemGroupByNumberMap.values().iterator(); @@ -3365,7 +3365,7 @@ /** * Does an "explode", or "unitize" operation on a list of cart items. * Resulting state for each item with quantity X is X items of quantity 1. - * + * * @param shoppingCartItems * @param dispatcher */ @@ -3463,7 +3463,7 @@ if (fromInventoryItemId != null) { orderItem.set("fromInventoryItemId", fromInventoryItemId); } - + result.add(orderItem); // don't do anything with adjustments here, those will be added below in makeAllAdjustments } @@ -3844,7 +3844,7 @@ } public List makeAllOrderAttributes() { - + return makeAllOrderAttributes(null, ALL); } @@ -4021,20 +4021,20 @@ return; } } - + List shipGroups = getShipGroups(); if (shipGroups == null) return; // Intermediate structure supplierPartyId -> { ShoppingCartItem = { originalShipGroupIndex = dropShipQuantity } } to collect drop-shippable items Map dropShipItems = new HashMap(); - + for (int shipGroupIndex = 0; shipGroupIndex < shipGroups.size(); shipGroupIndex++) { - + CartShipInfo shipInfo = (CartShipInfo) shipGroups.get(shipGroupIndex); - + // Ignore ship groups that are already drop shipped String shipGroupSupplierPartyId = shipInfo.getSupplierPartyId(); - if (UtilValidate.isNotEmpty(shipGroupSupplierPartyId)) { + if (UtilValidate.isNotEmpty(shipGroupSupplierPartyId)) { continue; } @@ -4044,7 +4044,7 @@ Iterator siit = shipItems.iterator(); while (siit.hasNext()) { - + ShoppingCartItem cartItem = (ShoppingCartItem) siit.next(); BigDecimal itemQuantity = cartItem.getQuantity(); @@ -4058,12 +4058,12 @@ String requirementMethodEnumId = product.getString("requirementMethodEnumId"); if ("PRODRQM_DS".equals(requirementMethodEnumId)) { - + // Drop ship the full quantity if the product is marked drop-ship only dropShipQuantity = itemQuantity; - + } else if ("PRODRQM_DSATP".equals(requirementMethodEnumId)) { - + // Drop ship the quantity not available in inventory if the product is marked drop-ship on low inventory try { @@ -4081,19 +4081,19 @@ Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderRunServiceGetInventoryAvailableByFacilityError", locale) + e.getMessage(), module); } } else { - + // Don't drop ship anything if the product isn't so marked dropShipQuantity = BigDecimal.ZERO; } if (dropShipQuantity.compareTo(BigDecimal.ZERO) <= 0) continue; - + // Find a supplier for the product String supplierPartyId = null; try { Map getSuppliersForProductResult = dispatcher.runSync("getSuppliersForProduct", UtilMisc.<String, Object>toMap("productId", productId, "quantity", dropShipQuantity, "canDropShip", "Y", "currencyUomId", getCurrency())); List supplierProducts = (List) getSuppliersForProductResult.get("supplierProducts"); - + // Order suppliers by supplierPrefOrderId so that preferred suppliers are used first supplierProducts = EntityUtil.orderBy(supplierProducts, UtilMisc.toList("supplierPrefOrderId")); GenericValue supplierProduct = EntityUtil.getFirst(supplierProducts); @@ -4103,10 +4103,10 @@ } catch (Exception e) { Debug.logWarning(UtilProperties.getMessage(resource_error,"OrderRunServiceGetSuppliersForProductError", locale) + e.getMessage(), module); } - + // Leave the items untouched if we couldn't find a supplier if (UtilValidate.isEmpty(supplierPartyId)) continue; - + if (! dropShipItems.containsKey(supplierPartyId)) dropShipItems.put(supplierPartyId, new HashMap()); Map supplierCartItems = (Map) dropShipItems.get(supplierPartyId); @@ -4124,7 +4124,7 @@ CartShipInfo shipInfo = null; int newShipGroupIndex = -1 ; - + // Attempt to get the first ship group for the supplierPartyId TreeMap supplierShipGroups = (TreeMap) this.getShipGroupsBySupplier(supplierPartyId); if (! UtilValidate.isEmpty(supplierShipGroups)) { @@ -4153,7 +4153,7 @@ } } } - + static class BasePriceOrderComparator implements Comparator, Serializable { private boolean ascending = false; @@ -4193,36 +4193,36 @@ protected ShoppingCartItemGroup(long groupNumber, String groupName) { this(groupNumber, groupName, null); } - + /** Note that to avoid foreign key issues when the groups are created a parentGroup should have a lower number than the child group. */ protected ShoppingCartItemGroup(long groupNumber, String groupName, ShoppingCartItemGroup parentGroup) { this.groupNumber = groupNumber; this.groupName = groupName; this.parentGroup = parentGroup; } - + protected ShoppingCartItemGroup(ShoppingCartItemGroup itemGroup, ShoppingCartItemGroup parentGroup) { this.groupNumber = itemGroup.groupNumber; this.groupName = itemGroup.groupName; this.parentGroup = parentGroup; } - + public String getGroupNumber() { return UtilFormatOut.formatPaddedNumber(this.groupNumber, 2); } - + public String getGroupName() { return this.groupName; } - + public void setGroupName(String str) { this.groupName = str; } - + public ShoppingCartItemGroup getParentGroup () { return this.parentGroup; } - + protected GenericValue makeOrderItemGroup(GenericDelegator delegator) { GenericValue orderItemGroup = delegator.makeValue("OrderItemGroup"); orderItemGroup.set("orderItemGroupSeqId", this.getGroupNumber()); @@ -4232,13 +4232,13 @@ } return orderItemGroup; } - + public void inheritParentsParent() { if (this.parentGroup != null) { - this.parentGroup = this.parentGroup.getParentGroup(); + this.parentGroup = this.parentGroup.getParentGroup(); } } - + public boolean equals(Object obj) { if (obj == null) return false; ShoppingCartItemGroup that = (ShoppingCartItemGroup) obj; @@ -4311,7 +4311,7 @@ public List makeItemShipGroupAndAssoc(GenericDelegator delegator, ShoppingCart cart, long groupIndex) { shipGroupSeqId = UtilFormatOut.formatPaddedNumber(groupIndex, 5); List values = new LinkedList(); - + // create order contact mech for shipping address if (this.internalContactMechId != null) { GenericValue orderCm = delegator.makeValue("OrderContactMech"); @@ -4334,7 +4334,7 @@ shipGroup.set("shipGroupSeqId", shipGroupSeqId); shipGroup.set("vendorPartyId", vendorPartyId); shipGroup.set("facilityId", facilityId); - + // use the cart's default ship before and after dates here if ((shipBeforeDate == null) && (cart.getDefaultShipBeforeDate() != null)) { shipGroup.set("shipByDate", cart.getDefaultShipBeforeDate()); @@ -4346,7 +4346,7 @@ } else { shipGroup.set("shipAfterDate", shipAfterDate); } - + values.add(shipGroup); //set estimated ship dates @@ -4363,7 +4363,7 @@ Timestamp estimatedShipDate = (Timestamp) estimatedShipDates.getLast(); shipGroup.set("estimatedShipDate", estimatedShipDate); } - + //set estimated delivery dates FastList estimatedDeliveryDates = FastList.newInstance(); for (Map.Entry <Object, Object> entry : shipItemInfo.entrySet()) { @@ -4378,7 +4378,7 @@ Timestamp estimatedDeliveryDate = (Timestamp) estimatedDeliveryDates.getLast(); shipGroup.set("estimatedDeliveryDate", estimatedDeliveryDate); } - + // create the shipping estimate adjustments if (shipEstimate.compareTo(BigDecimal.ZERO) != 0) { GenericValue shipAdj = delegator.makeValue("OrderAdjustment"); @@ -4478,7 +4478,7 @@ } /** - * Reset the ship group's shipBeforeDate if it is after the parameter + * Reset the ship group's shipBeforeDate if it is after the parameter * @param newShipBeforeDate */ public void resetShipBeforeDateIfAfter(Timestamp newShipBeforeDate) { @@ -4488,9 +4488,9 @@ } } } - + /** - * Reset the ship group's shipAfterDate if it is before the parameter + * Reset the ship group's shipAfterDate if it is before the parameter * @param newShipBeforeDate */ public void resetShipAfterDateIfBefore(Timestamp newShipAfterDate) { @@ -4500,7 +4500,7 @@ } } } - + public BigDecimal getTotalTax(ShoppingCart cart) { BigDecimal taxTotal = ZERO; for (int i = 0; i < shipTaxAdj.size(); i++) { @@ -4516,7 +4516,7 @@ return taxTotal; } - + public BigDecimal getTotal() { BigDecimal shipItemTotal = ZERO; Iterator iter = shipItemInfo.values().iterator(); @@ -4547,11 +4547,11 @@ public ShoppingCartItem getItem() { return this.item; } - + public BigDecimal getItemQuantity() { return this.quantity; } - + public BigDecimal getItemSubTotal() { return item.getItemSubTotal(quantity); } @@ -4568,7 +4568,7 @@ public String track2 = null; public BigDecimal amount = null; public boolean singleUse = false; - public boolean isPresent = false; + public boolean isPresent = false; public boolean isSwiped = false; public boolean overflow = false; @@ -4652,7 +4652,7 @@ values.add(orderCm); } } - + GenericValue productStore = null; try { productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", cart.getProductStoreId())); @@ -4672,7 +4672,7 @@ CartShipInfo csi = (CartShipInfo) shipIter.next(); maxAmount = csi.getTotal().add(cart.getOrderOtherAdjustmentTotal().divide(new BigDecimal(cart.getShipGroupSize()), generalRounding)).add(csi.getShipEstimate().add(csi.getTotalTax(cart))); maxAmount = maxAmount.setScale(scale, rounding); - + // create the OrderPaymentPreference record GenericValue opp = delegator.makeValue("OrderPaymentPreference"); opp.set("paymentMethodTypeId", valueObj.getString("paymentMethodTypeId")); @@ -4712,7 +4712,7 @@ } else if ("N".equals(splitPayPrefPerShpGrp)) { maxAmount = maxAmount.add(amount); maxAmount = maxAmount.setScale(scale, rounding); - + // create the OrderPaymentPreference record GenericValue opp = delegator.makeValue("OrderPaymentPreference"); opp.set("paymentMethodTypeId", valueObj.getString("paymentMethodTypeId")); @@ -4763,7 +4763,7 @@ } else if (!this.finAccountId.equals(that.finAccountId)) { return -1; } - + if (this.paymentMethodId != null) { if (that.paymentMethodId == null) { return 1; @@ -4817,7 +4817,7 @@ return "Pm: " + paymentMethodId + " / PmType: " + paymentMethodTypeId + " / Amt: " + amount + " / Ref: " + refNum[0] + "!" + refNum[1]; } } - + protected void finalize() throws Throwable { // DEJ20050518 we should not call clear because it kills the auto-save shopping list and is unnecessary given that when this object is GC'ed it will cause everything it points to that isn't referenced anywhere else to be GC'ed too: this.clear(); super.finalize(); Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=757091&r1=757090&r2=757091&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Sat Mar 21 23:44:41 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -91,7 +91,7 @@ } return "success"; } - + public static String addItemGroup(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); Map parameters = UtilHttp.getParameterMap(request); @@ -101,7 +101,7 @@ request.setAttribute("itemGroupNumber", groupNumber); return "success"; } - + public static String addCartItemToGroup(HttpServletRequest request, HttpServletResponse response) { ShoppingCart cart = getCartObject(request); Map parameters = UtilHttp.getParameterMap(request); @@ -112,7 +112,7 @@ cartItem.setItemGroup(itemGroupNumber, cart); return "success"; } - + /** Event to add an item to the shopping cart. */ public static String addToCart(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); @@ -185,7 +185,7 @@ if (productCategoryId != null && productCategoryId.length() == 0) { productCategoryId = null; } - + if (paramMap.containsKey("ADD_ITEM_TYPE")) { itemType = (String) paramMap.remove("ADD_ITEM_TYPE"); } else if (paramMap.containsKey("add_item_type")) { @@ -230,7 +230,7 @@ } catch (Exception e) { Debug.logWarning(e,"Could not load configuration", module); } - } else { + } else { // The choices selected by the user are taken from request and set in the wrapper ProductConfigWorker.fillProductConfigWrapper(configWrapper, request); } @@ -244,8 +244,8 @@ ProductConfigWorker.storeProductConfigWrapper(configWrapper, delegator); } } - - + + //Check for virtual products if (ProductWorker.isVirtual(delegator, productId)) { @@ -259,7 +259,7 @@ selectedFeatures.add(request.getParameterValues(paramName)[0]); } } - + // check if features are selected if (UtilValidate.isEmpty(selectedFeatures)) { request.setAttribute("product_id", productId); @@ -282,7 +282,7 @@ return "product"; } } - + // get the override price if (paramMap.containsKey("PRICE")) { priceStr = (String) paramMap.remove("PRICE"); @@ -360,7 +360,7 @@ return "error"; } } - + //check for valid rental parameters if (UtilValidate.isEmpty(reservStart) && UtilValidate.isEmpty(reservLength) && UtilValidate.isEmpty(reservPersons)) { request.setAttribute("product_id", productId); @@ -419,14 +419,14 @@ amount = null; } } - + // check for required amount if ((ProductWorker.isAmountRequired(delegator, productId)) && (amount == null || amount.doubleValue() == 0.0)) { request.setAttribute("product_id", productId); request.setAttribute("_EVENT_MESSAGE_",UtilProperties.getMessage(resource_error,"cart.addToCart.enterAmountBeforeAddingToCart",locale)); return "product"; } - + // get the ship before date (handles both yyyy-mm-dd input and full timestamp) shipBeforeDateStr = (String) paramMap.remove("shipBeforeDate"); if (shipBeforeDateStr != null && shipBeforeDateStr.length() > 0) { @@ -484,8 +484,8 @@ if (surveyResponses != null) { paramMap.put("surveyResponses", surveyResponses); } - - GenericValue productStore = ProductStoreWorker.getProductStore(request); + + GenericValue productStore = ProductStoreWorker.getProductStore(request); String addToCartRemoveIncompat = productStore.getString("addToCartRemoveIncompat"); String addToCartReplaceUpsell = productStore.getString("addToCartReplaceUpsell"); try { @@ -508,7 +508,7 @@ productList.add(productAssoc.getString("productId")); continue; } - } + } Iterator sciIter = cart.iterator(); while (sciIter.hasNext()) { ShoppingCartItem sci = (ShoppingCartItem) sciIter.next(); @@ -544,10 +544,10 @@ } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); } - + // Translate the parameters and add to the cart result = cartHelper.addToCart(catalogId, shoppingListId, shoppingListItemSeqId, productId, productCategoryId, - itemType, itemDescription, price, amount, quantity, reservStart, reservLength, reservPersons, + itemType, itemDescription, price, amount, quantity, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, configWrapper, itemGroupNumber, paramMap, parentProductId); controlDirective = processResult(result, request); @@ -642,7 +642,7 @@ } cart.setOrderType("PURCHASE_ORDER"); - + session.setAttribute("shoppingCart", cart); session.setAttribute("productStoreId", cart.getProductStoreId()); session.setAttribute("orderMode", cart.getOrderType()); @@ -784,13 +784,13 @@ // here we want to do a full logout, but not using the normal logout stuff because it saves things in the UserLogin record that we don't want changed for the anonymous user session.invalidate(); session = request.getSession(true); - + // to allow the display of the order confirmation page put the userLogin in the request, but leave it out of the session request.setAttribute("temporaryAnonymousUserLogin", userLogin); - + Debug.logInfo("Doing clearCart for anonymous user, so logging out but put anonymous userLogin in temporaryAnonymousUserLogin request attribute", module); } - + return "success"; } @@ -1128,7 +1128,7 @@ } return "success"; } - + /** * set the order name of the cart based on request. right now will always return "success" * @@ -1292,7 +1292,7 @@ UtilMisc.<String, Object>toMap("orderId", quoteId, "skipProductChecks", Boolean.TRUE, // the products have already been checked in the order, no need to check their validity again "userLogin", userLogin)); - + cart = (ShoppingCart) outMap.get("shoppingCart"); } catch (GenericServiceException exc) { request.setAttribute("_ERROR_MESSAGE_", exc.getMessage()); @@ -1451,7 +1451,7 @@ // set party info String partyId = request.getParameter("supplierPartyId"); cart.setAttribute("supplierPartyId", partyId); - + if (!UtilValidate.isEmpty(request.getParameter("partyId"))) { partyId = request.getParameter("partyId"); } @@ -1634,9 +1634,9 @@ if (quantity.compareTo(BigDecimal.ZERO) > 0) { Debug.logInfo("Attempting to add to cart with productId = " + productId + ", categoryId = " + productCategoryId + ", quantity = " + quantity + ", itemType = " + itemType + " and itemDescription = " + itemDescription, module); - result = cartHelper.addToCart(catalogId, shoppingListId, shoppingListItemSeqId, productId, - productCategoryId, itemType, itemDescription, null, - amount, quantity, null, null, null, null, null, null, + result = cartHelper.addToCart(catalogId, shoppingListId, shoppingListItemSeqId, productId, + productCategoryId, itemType, itemDescription, null, + amount, quantity, null, null, null, null, null, null, itemGroupNumber, itemAttributes,null); // no values for price and paramMap (a context for adding attributes) controlDirective = processResult(result, request); @@ -1673,7 +1673,7 @@ // set the agreement if specified otherwise set the currency if (UtilValidate.isNotEmpty(agreementId)) { result = cartHelper.selectAgreement(agreementId); - } else if (UtilValidate.isNotEmpty(currencyUomId)) { + } else if (UtilValidate.isNotEmpty(currencyUomId)) { result = cartHelper.setCurrency(currencyUomId); } if (ServiceUtil.isError(result)) { @@ -1702,10 +1702,10 @@ // set the order name cart.setOrderName(orderName); - + // set the corresponding purchase order id cart.setPoNumber(correspondingPoId); - + // set the default ship before and after dates if supplied try { if (UtilValidate.isNotEmpty(shipBeforeDateStr)) { @@ -1726,7 +1726,7 @@ } return "success"; } - + public static String getConfigDetailsEvent(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); @@ -1738,16 +1738,16 @@ request.setAttribute("_ERROR_MESSAGE_", "configWrapper is null"); return "error"; } - ProductConfigWorker.fillProductConfigWrapper(configWrapper, request); + ProductConfigWorker.fillProductConfigWrapper(configWrapper, request); if (configWrapper.isCompleted()) { ProductConfigWorker.storeProductConfigWrapper(configWrapper, delegator); request.setAttribute("configId", configWrapper.getConfigId()); - } - + } + request.setAttribute("totalPrice", org.ofbiz.base.util.UtilFormatOut.formatCurrency(configWrapper.getTotalPrice(), currencyUomId, UtilHttp.getLocale(request))); return "success"; } - + public static String bulkAddProductsInApprovedOrder(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); @@ -1755,29 +1755,29 @@ String productId = null; String productCategoryId = null; String quantityStr = null; - String itemDesiredDeliveryDateStr = null; + String itemDesiredDeliveryDateStr = null; BigDecimal quantity = BigDecimal.ZERO; String itemType = null; String itemDescription = ""; String orderId = null; String shipGroupSeqId = null; - - Map paramMap = UtilHttp.getParameterMap(request); + + Map paramMap = UtilHttp.getParameterMap(request); String itemGroupNumber = request.getParameter("itemGroupNumber"); int rowCount = UtilHttp.getMultiFormRowCount(paramMap); if (rowCount < 1) { Debug.logWarning("No rows to process, as rowCount = " + rowCount, module); } else { for (int i = 0; i < rowCount; i++) { - String thisSuffix = UtilHttp.MULTI_ROW_DELIMITER + i; + String thisSuffix = UtilHttp.MULTI_ROW_DELIMITER + i; if (paramMap.containsKey("productId" + thisSuffix)) { productId = (String) paramMap.remove("productId" + thisSuffix); } if (paramMap.containsKey("quantity" + thisSuffix)) { quantityStr = (String) paramMap.remove("quantity" + thisSuffix); } - if ((quantityStr == null) || (quantityStr.equals(""))) { - quantityStr = "0"; + if ((quantityStr == null) || (quantityStr.equals(""))) { + quantityStr = "0"; } try { quantity = new BigDecimal(quantityStr); @@ -1810,7 +1810,7 @@ itemDesiredDeliveryDate = null; request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"shoppingCartEvents.problem_parsing_item_desiredDeliveryDate_string", locale)); } - } + } if (paramMap.containsKey("itemType" + thisSuffix)) { itemType = (String) paramMap.remove("itemType" + thisSuffix); } Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=757091&r1=757090&r2=757091&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Sat Mar 21 23:44:41 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -55,10 +55,10 @@ import org.ofbiz.service.ServiceUtil; /** - * A facade over the + * A facade over the * {@link org.ofbiz.order.shoppingcart.ShoppingCart ShoppingCart} * providing catalog and product services to simplify the interaction - * with the cart directly. + * with the cart directly. */ public class ShoppingCartHelper { @@ -78,7 +78,7 @@ /** * Changes will be made to the cart directly, as opposed * to a copy of the cart provided. - * + * * @param cart The cart to manipulate */ public ShoppingCartHelper(GenericDelegator delegator, LocalDispatcher dispatcher, ShoppingCart cart) { @@ -99,9 +99,9 @@ /** Event to add an item to the shopping cart. */ public Map addToCart(String catalogId, String shoppingListId, String shoppingListItemSeqId, String productId, - String productCategoryId, String itemType, String itemDescription, - BigDecimal price, BigDecimal amount, BigDecimal quantity, - java.sql.Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, + String productCategoryId, String itemType, String itemDescription, + BigDecimal price, BigDecimal amount, BigDecimal quantity, + java.sql.Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, java.sql.Timestamp shipBeforeDate, java.sql.Timestamp shipAfterDate, ProductConfigWrapper configWrapper, String itemGroupNumber, Map context, String parentProductId) { @@ -110,12 +110,12 @@ reservStart,reservLength,reservPersons,null,null,shipBeforeDate,shipAfterDate, configWrapper,itemGroupNumber,context,parentProductId); } - + /** Event to add an item to the shopping cart with accommodation. */ public Map addToCart(String catalogId, String shoppingListId, String shoppingListItemSeqId, String productId, - String productCategoryId, String itemType, String itemDescription, - BigDecimal price, BigDecimal amount, BigDecimal quantity, - java.sql.Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId,String accommodationSpotId, + String productCategoryId, String itemType, String itemDescription, + BigDecimal price, BigDecimal amount, BigDecimal quantity, + java.sql.Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons, String accommodationMapId,String accommodationSpotId, java.sql.Timestamp shipBeforeDate, java.sql.Timestamp shipAfterDate, ProductConfigWrapper configWrapper, String itemGroupNumber, Map context, String parentProductId) { Map result = null; @@ -201,7 +201,7 @@ Debug.logInfo("parent productid " + pProductId,module); //if (product != null && !"Y".equals(product.getString("isVariant"))) // pProductId = null; - + } // Get the additional features selected for the product (if any) @@ -227,16 +227,16 @@ additionalFeaturesMap.put(selectedFeatureType, productFeatureAndAppl); } } - - // add or increase the item to the cart + + // add or increase the item to the cart try { int itemId = -1; if (productId != null) { - - itemId = cart.addOrIncreaseItem(productId, amount, quantity, reservStart, reservLength, - reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, additionalFeaturesMap, attributes, + + itemId = cart.addOrIncreaseItem(productId, amount, quantity, reservStart, reservLength, + reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, additionalFeaturesMap, attributes, catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher); - + } else { itemId = cart.addNonProductItem(itemType, itemDescription, productCategoryId, price, quantity, attributes, catalogId, itemGroupNumber, dispatcher); } @@ -259,7 +259,7 @@ result = ServiceUtil.returnError(e.getMessage()); return result; } - + // Indicate there were no critical errors result = ServiceUtil.returnSuccess(); return result; @@ -290,7 +290,7 @@ if (UtilValidate.isNotEmpty(itemIdList)) { itemIter = itemIdList.iterator(); } - + String orderItemTypeId = null; String productId = null; if (itemIter != null && itemIter.hasNext()) { @@ -306,7 +306,7 @@ orderItemTypeId = orderItem.getString("orderItemTypeId"); productId = orderItem.getString("productId"); // do not store rental items - if (orderItemTypeId.equals("RENTAL_ORDER_ITEM")) + if (orderItemTypeId.equals("RENTAL_ORDER_ITEM")) continue; // never read: int itemId = -1; if (UtilValidate.isNotEmpty(productId) && orderItem.get("quantity") != null) { @@ -322,7 +322,7 @@ } catch (GenericEntityException e) { errorMsgs.add(e.getMessage()); } - + } try { this.cart.addOrIncreaseItem(UtilValidate.isNotEmpty(aggregatedProdId) ? aggregatedProdId : productId, amount, orderItem.getBigDecimal("quantity"), @@ -354,26 +354,26 @@ return result; } - /** + /** * Adds all products in a category according to quantity request parameter * for each; if no parameter for a certain product in the category, or if - * quantity is 0, do not add. + * quantity is 0, do not add. * If a _ign_${itemGroupNumber} is appended to the name it will be put in that group instead of the default in the request parameter in itemGroupNumber - * + * * There are 2 options for the syntax: * - name="quantity_${productId}" value="${quantity} * - name="product_${whatever}" value="${productId}" (note: quantity is always 1) */ public Map addToCartBulk(String catalogId, String categoryId, Map context) { String itemGroupNumber = (String) context.get("itemGroupNumber"); - // use this prefix for the main structure such as a checkbox or a text input where name="quantity_${productId}" value="${quantity}" + // use this prefix for the main structure such as a checkbox or a text input where name="quantity_${productId}" value="${quantity}" String keyPrefix = "quantity_"; - // use this prefix for a different structure, useful for radio buttons; can have any suffix, name="product_${whatever}" value="${productId}" and quantity is always 1 + // use this prefix for a different structure, useful for radio buttons; can have any suffix, name="product_${whatever}" value="${productId}" and quantity is always 1 String productQuantityKeyPrefix = "product_"; - + // If a _ign_${itemGroupNumber} is appended to the name it will be put in that group instead of the default in the request parameter in itemGroupNumber String ignSeparator = "_ign_"; - + // iterate through the context and find all keys that start with "quantity_" Iterator entryIter = context.entrySet().iterator(); while (entryIter.hasNext()) { @@ -390,7 +390,7 @@ itemGroupNumberToUse = key.substring(ignIndex + ignSeparator.length()); key = key.substring(0, ignIndex); } - + if (key.startsWith(keyPrefix)) { productId = key.substring(keyPrefix.length()); quantStr = (String) entry.getValue(); @@ -429,20 +429,20 @@ return ServiceUtil.returnSuccess(); } - /** + /** * Adds a set of requirements to the cart. */ public Map addToCartBulkRequirements(String catalogId, Map context) { NumberFormat nf = NumberFormat.getNumberInstance(this.cart.getLocale()); String itemGroupNumber = (String) context.get("itemGroupNumber"); // check if we are using per row submit - boolean useRowSubmit = (!context.containsKey("_useRowSubmit"))? false : + boolean useRowSubmit = (!context.containsKey("_useRowSubmit"))? false : "Y".equalsIgnoreCase((String)context.get("_useRowSubmit")); - - // check if we are to also look in a global scope (no delimiter) + + // check if we are to also look in a global scope (no delimiter) //boolean checkGlobalScope = (!context.containsKey("_checkGlobalScope"))? false : // "Y".equalsIgnoreCase((String)context.get("_checkGlobalScope")); - + // The number of multi form rows is retrieved int rowCount = UtilHttp.getMultiFormRowCount(context); @@ -451,7 +451,7 @@ if (UtilValidate.isNotEmpty(facilityId)) { cart.setFacilityId(facilityId); } - + // now loop throw the rows and prepare/invoke the service for each for (int i = 0; i < rowCount; i++) { String productId = null; @@ -460,12 +460,12 @@ String thisSuffix = UtilHttp.MULTI_ROW_DELIMITER + i; boolean rowSelected = (!context.containsKey("_rowSubmit" + thisSuffix))? false : "Y".equalsIgnoreCase((String)context.get("_rowSubmit" + thisSuffix)); - + // make sure we are to process this row - if (useRowSubmit && !rowSelected) { + if (useRowSubmit && !rowSelected) { continue; } - + // build the context if (context.containsKey("productId" + thisSuffix)) { productId = (String) context.get("productId" + thisSuffix); @@ -564,8 +564,8 @@ if (quantity != null && quantity.compareTo(BigDecimal.ZERO) > 0) { try { - this.cart.addOrIncreaseItem(productCategoryMember.getString("productId"), - null, quantity, null, null, null, null, null, null, null, + this.cart.addOrIncreaseItem(productCategoryMember.getString("productId"), + null, quantity, null, null, null, null, null, null, null, catalogId, null, null, itemGroupNumber, null, dispatcher); totalQuantity = totalQuantity.add(quantity); } catch (CartItemModifyException e) { @@ -679,10 +679,10 @@ itemDescription = quantString; // the quantString is actually the description if the field name starts with DESCRIPTION } else if (parameterName.startsWith("reservStart")) { if (quantString.length() ==0) { - // should have format: yyyy-mm-dd hh:mm:ss.fffffffff + // should have format: yyyy-mm-dd hh:mm:ss.fffffffff quantString += " 00:00:00.000000000"; } - if (item != null) { + if (item != null) { Timestamp reservStart = Timestamp.valueOf(quantString); item.setReservStart(reservStart); } @@ -724,7 +724,7 @@ } else if (parameterName.startsWith("itemType")) { if (item != null && quantString.length() > 0) { item.setItemType(quantString); - } + } } else { quantity = new BigDecimal(nf.parse(quantString).doubleValue()); if (quantity.compareTo(BigDecimal.ZERO) < 0) { @@ -802,7 +802,7 @@ if (security.hasEntityPermission("ORDERMGR", "_CREATE", userLogin)) { if (item != null) { item.setBasePrice(quantity); // this is quantity because the parsed number variable is the same as quantity - item.setDisplayPrice(quantity); // or the amount shown the cart items page won't be right + item.setDisplayPrice(quantity); // or the amount shown the cart items page won't be right item.setIsModifiedPrice(true); // flag as a modified price } } |
Free forum by Nabble | Edit this page |