You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by er...@apache.org on 2012/03/26 22:56:30 UTC
svn commit: r1305581 [12/36] - in /ofbiz/branches/20111205EmailHandling: ./
applications/accounting/config/ applications/accounting/data/
applications/accounting/entitydef/
applications/accounting/script/org/ofbiz/accounting/finaccount/
applications/ac...
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/quote/QuoteServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/quote/QuoteServices.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/quote/QuoteServices.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/quote/QuoteServices.java Mon Mar 26 20:56:02 2012
@@ -19,7 +19,6 @@
package org.ofbiz.order.quote;
import java.sql.Timestamp;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -192,9 +191,7 @@ public class QuoteServices {
// create Quote Items
if (UtilValidate.isNotEmpty(quoteItems)) {
- Iterator<GenericValue> quoteIt = quoteItems.iterator();
- while (quoteIt.hasNext()) {
- GenericValue quoteItem = quoteIt.next();
+ for(GenericValue quoteItem : quoteItems) {
quoteItem.set("quoteId", quoteId);
Map<String, Object> quoteItemIn = quoteItem.getAllFields();
quoteItemIn.put("userLogin", userLogin);
@@ -205,9 +202,7 @@ public class QuoteServices {
// create Quote Attributes
if (UtilValidate.isNotEmpty(quoteAttributes)) {
- Iterator<GenericValue> quoteAttrIt = quoteAttributes.iterator();
- while (quoteAttrIt.hasNext()) {
- GenericValue quoteAttr = quoteAttrIt.next();
+ for(GenericValue quoteAttr : quoteAttributes) {
quoteAttr.set("quoteId", quoteId);
Map<String, Object> quoteAttrIn = quoteAttr.getAllFields();
quoteAttrIn.put("userLogin", userLogin);
@@ -218,9 +213,7 @@ public class QuoteServices {
// create Quote Coefficients
if (UtilValidate.isNotEmpty(quoteCoefficients)) {
- Iterator<GenericValue> quoteCoefficientIt = quoteCoefficients.iterator();
- while (quoteCoefficientIt.hasNext()) {
- GenericValue quoteCoefficient = quoteCoefficientIt.next();
+ for(GenericValue quoteCoefficient : quoteCoefficients) {
quoteCoefficient.set("quoteId", quoteId);
Map<String, Object> quoteCoefficientIn = quoteCoefficient.getAllFields();
quoteCoefficientIn.put("userLogin", userLogin);
@@ -231,9 +224,7 @@ public class QuoteServices {
// create Quote Roles
if (UtilValidate.isNotEmpty(quoteRoles)) {
- Iterator<GenericValue> quoteRoleIt = quoteRoles.iterator();
- while (quoteRoleIt.hasNext()) {
- GenericValue quoteRole = quoteRoleIt.next();
+ for(GenericValue quoteRole : quoteRoles) {
quoteRole.set("quoteId", quoteId);
Map<String, Object> quoteRoleIn = quoteRole.getAllFields();
quoteRoleIn.put("userLogin", userLogin);
@@ -244,9 +235,7 @@ public class QuoteServices {
// create Quote WorkEfforts
if (UtilValidate.isNotEmpty(quoteWorkEfforts)) {
- Iterator<GenericValue> quoteWorkEffortIt = quoteWorkEfforts.iterator();
- while (quoteWorkEffortIt.hasNext()) {
- GenericValue quoteWorkEffort = quoteWorkEffortIt.next();
+ for(GenericValue quoteWorkEffort : quoteWorkEfforts) {
quoteWorkEffort.set("quoteId", quoteId);
Map<String, Object> quoteWorkEffortIn = quoteWorkEffort.getAllFields();
quoteWorkEffortIn.put("userLogin", userLogin);
@@ -257,9 +246,7 @@ public class QuoteServices {
// create Quote Adjustments
if (UtilValidate.isNotEmpty(quoteAdjustments)) {
- Iterator<GenericValue> quoteAdjustmentIt = quoteAdjustments.iterator();
- while (quoteAdjustmentIt.hasNext()) {
- GenericValue quoteAdjustment = quoteAdjustmentIt.next();
+ for(GenericValue quoteAdjustment : quoteAdjustments) {
quoteAdjustment.set("quoteId", quoteId);
Map<String, Object> quoteAdjustmentIn = quoteAdjustment.getAllFields();
quoteAdjustmentIn.put("userLogin", userLogin);
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Mon Mar 26 20:56:02 2012
@@ -99,9 +99,8 @@ public class RequirementServices {
// join in fields with extra data about the suppliers and products
List<Map<String, Object>> requirements = FastList.newInstance();
- for (Iterator<GenericValue> iter = requirementAndRoles.iterator(); iter.hasNext();) {
+ for(GenericValue requirement : requirementAndRoles) {
Map<String, Object> union = FastMap.newInstance();
- GenericValue requirement = iter.next();
String productId = requirement.getString("productId");
partyId = requirement.getString("partyId");
String facilityId = requirement.getString("facilityId");
@@ -217,8 +216,7 @@ public class RequirementServices {
}
String facilityId = productStore.getString("inventoryFacilityId");
List<GenericValue> orderItems = order.getRelated("OrderItem");
- for (Iterator<GenericValue> iter = orderItems.iterator(); iter.hasNext();) {
- GenericValue item = iter.next();
+ for(GenericValue item : orderItems) {
GenericValue product = item.getRelatedOne("Product");
if (product == null) continue;
if ((!"PRODRQM_AUTO".equals(product.get("requirementMethodEnumId")) &&
@@ -277,8 +275,7 @@ public class RequirementServices {
}
String facilityId = productStore.getString("inventoryFacilityId");
List<GenericValue> orderItems = order.getRelated("OrderItem");
- for (Iterator<GenericValue> iter = orderItems.iterator(); iter.hasNext();) {
- GenericValue item = iter.next();
+ for(GenericValue item : orderItems) {
GenericValue product = item.getRelatedOne("Product");
if (product == null) continue;
@@ -312,8 +309,7 @@ public class RequirementServices {
EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "REQ_REJECTED")),
EntityOperator.AND);
List<GenericValue> requirements = delegator.findList("Requirement", ecl, null, null, null, false);
- for (Iterator<GenericValue> riter = requirements.iterator(); riter.hasNext();) {
- GenericValue requirement = riter.next();
+ for(GenericValue requirement : requirements) {
pendingRequirements = pendingRequirements.add(requirement.get("quantity") == null ? BigDecimal.ZERO : requirement.getBigDecimal("quantity"));
}
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java Mon Mar 26 20:56:02 2012
@@ -18,8 +18,6 @@
*******************************************************************************/
package org.ofbiz.order.shoppingcart;
-import java.util.Iterator;
-
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@@ -78,10 +76,8 @@ public class CartEventListener implement
}
Debug.logInfo("Saving abandoned cart", module);
- Iterator<ShoppingCartItem> cartItems = cart.iterator();
int seqId = 1;
- while (cartItems.hasNext()) {
- ShoppingCartItem cartItem = cartItems.next();
+ for(ShoppingCartItem cartItem : cart) {
GenericValue cartAbandonedLine = delegator.makeValue("CartAbandonedLine");
cartAbandonedLine.set("visitId", visit.get("visitId"));
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java Mon Mar 26 20:56:02 2012
@@ -862,7 +862,7 @@ public class CheckOutEvents {
// payment option; if offline we skip the payment screen
methodType = request.getParameter("paymentMethodType");
if ("offline".equals(methodType)) {
- Debug.log("Changing mode from->to: " + mode + "->payment", module);
+ Debug.logInfo("Changing mode from->to: " + mode + "->payment", module);
mode = "payment";
}
//FIXME can be removed ?
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Mon Mar 26 20:56:02 2012
@@ -48,6 +48,7 @@ import org.ofbiz.entity.condition.Entity
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityFunction;
import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityTypeUtil;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.order.finaccount.FinAccountHelper;
import org.ofbiz.order.order.OrderChangeHelper;
@@ -265,9 +266,7 @@ public class CheckOutHelper {
try {
List<GenericValue> billingAccountTerms = delegator.findByAnd("BillingAccountTerm", UtilMisc.toMap("billingAccountId", billingAccountId));
if (UtilValidate.isNotEmpty(billingAccountTerms)) {
- Iterator<GenericValue> billingAccountTermsIt = billingAccountTerms.iterator();
- while (billingAccountTermsIt.hasNext()) {
- GenericValue billingAccountTerm = billingAccountTermsIt.next();
+ for(GenericValue billingAccountTerm : billingAccountTerms) {
// the term is not copied if in the cart a term of the same type is already set
if (!cart.hasOrderTerm(billingAccountTerm.getString("termTypeId"))) {
cart.addOrderTerm(billingAccountTerm.getString("termTypeId"), billingAccountTerm.getBigDecimal("termValue"), billingAccountTerm.getLong("termDays"));
@@ -317,10 +316,7 @@ public class CheckOutHelper {
}
}
- Set<String> paymentMethods = selectedPaymentMethods.keySet();
- Iterator<String> i = paymentMethods.iterator();
- while (i.hasNext()) {
- String checkOutPaymentId = i.next();
+ for(String checkOutPaymentId : selectedPaymentMethods.keySet()) {
String finAccountId = null;
if (checkOutPaymentId.indexOf("|") > -1) {
@@ -632,10 +628,8 @@ public class CheckOutHelper {
// If needed, the production runs are created and linked to the order lines.
//
List<GenericValue> orderItems = UtilGenerics.checkList(context.get("orderItems"));
- Iterator<GenericValue> orderItemsIt = orderItems.iterator();
int counter = 0;
- while (orderItemsIt.hasNext()) {
- GenericValue orderItem = orderItemsIt.next();
+ for(GenericValue orderItem : orderItems) {
String productId = orderItem.getString("productId");
if (productId != null) {
try {
@@ -644,7 +638,7 @@ public class CheckOutHelper {
GenericValue permUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator);
GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
- if ("AGGREGATED_CONF".equals(product.getString("productTypeId"))) {
+ if (EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "AGGREGATED")) {
org.ofbiz.product.config.ProductConfigWrapper config = this.cart.findCartItem(counter).getConfigWrapper();
Map<String, Object> inputMap = new HashMap<String, Object>();
inputMap.put("config", config);
@@ -674,9 +668,7 @@ public class CheckOutHelper {
// ----------
// The status of the requirement associated to the shopping cart lines is set to "ordered".
//
- Iterator<ShoppingCartItem> shoppingCartItems = this.cart.items().iterator();
- while (shoppingCartItems.hasNext()) {
- ShoppingCartItem shoppingCartItem = shoppingCartItems.next();
+ for(ShoppingCartItem shoppingCartItem : this.cart.items()) {
String requirementId = shoppingCartItem.getRequirementId();
if (requirementId != null) {
try {
@@ -730,9 +722,7 @@ public class CheckOutHelper {
String additionalEmails = this.cart.getOrderAdditionalEmails();
List<String> emailList = StringUtil.split(additionalEmails, ",");
if (emailList == null) emailList = new ArrayList<String>();
- Iterator<String> eli = emailList.iterator();
- while (eli.hasNext()) {
- String email = eli.next();
+ for(String email : emailList) {
String contactMechId = this.delegator.getNextSeqId("ContactMech");
GenericValue contactMech = this.delegator.makeValue("ContactMech",
UtilMisc.toMap("contactMechId", contactMechId, "contactMechTypeId", "EMAIL_ADDRESS", "infoString", email));
@@ -955,9 +945,7 @@ public class CheckOutHelper {
List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("manualRefNum", EntityOperator.NOT_EQUAL, null));
List<GenericValue> manualRefPaymentPrefs = EntityUtil.filterByAnd(allPaymentPreferences, exprs);
if (UtilValidate.isNotEmpty(manualRefPaymentPrefs)) {
- Iterator<GenericValue> i = manualRefPaymentPrefs.iterator();
- while (i.hasNext()) {
- GenericValue opp = i.next();
+ for(GenericValue opp : manualRefPaymentPrefs) {
Map<String, Object> authCtx = new HashMap<String, Object>();
authCtx.put("orderPaymentPreference", opp);
if (opp.get("paymentMethodId") == null) {
@@ -1175,9 +1163,7 @@ public class CheckOutHelper {
public static void adjustFaceToFacePayment(String orderId, BigDecimal cartTotal, List<GenericValue> allPaymentPrefs, GenericValue userLogin, Delegator delegator) throws GeneralException {
BigDecimal prefTotal = BigDecimal.ZERO;
if (allPaymentPrefs != null) {
- Iterator<GenericValue> i = allPaymentPrefs.iterator();
- while (i.hasNext()) {
- GenericValue pref = i.next();
+ for(GenericValue pref : allPaymentPrefs) {
BigDecimal maxAmount = pref.getBigDecimal("maxAmount");
if (maxAmount == null) maxAmount = BigDecimal.ZERO;
prefTotal = prefTotal.add(maxAmount);
@@ -1216,9 +1202,7 @@ public class CheckOutHelper {
String errMsg=null;
List<GenericValue> paymentMethods = this.cart.getPaymentMethods();
- Iterator<GenericValue> i = paymentMethods.iterator();
- while (i.hasNext()) {
- GenericValue paymentMethod = i.next();
+ for(GenericValue paymentMethod : paymentMethods) {
if ((paymentMethod != null) && ("CREDIT_CARD".equals(paymentMethod.getString("paymentMethodTypeId")))) {
GenericValue creditCard = null;
GenericValue billingAddress = null;
@@ -1517,9 +1501,7 @@ public class CheckOutHelper {
public Map<String, BigDecimal> makeBillingAccountMap(List<GenericValue> paymentPrefs) {
Map<String, BigDecimal> accountMap = new HashMap<String, BigDecimal>();
if (paymentPrefs != null) {
- Iterator<GenericValue> i = paymentPrefs.iterator();
- while (i.hasNext()) {
- GenericValue pp = i.next();
+ for(GenericValue pp : paymentPrefs) {
if (pp.get("billingAccountId") != null) {
accountMap.put(pp.getString("billingAccountId"), pp.getBigDecimal("maxAmount"));
}
@@ -1556,18 +1538,14 @@ public class CheckOutHelper {
// update the selected payment methods amount with valid numbers
if (paymentMethods != null) {
List<String> nullPaymentIds = new ArrayList<String>();
- Iterator<String> i = paymentMethods.iterator();
- while (i.hasNext()) {
- String paymentMethodId = i.next();
+ for(String paymentMethodId : paymentMethods) {
BigDecimal paymentAmount = cart.getPaymentAmount(paymentMethodId);
if (paymentAmount == null || paymentAmount.compareTo(BigDecimal.ZERO) == 0) {
if (Debug.verboseOn()) Debug.logVerbose("Found null paymentMethodId - " + paymentMethodId, module);
nullPaymentIds.add(paymentMethodId);
}
}
- Iterator<String> npi = nullPaymentIds.iterator();
- while (npi.hasNext()) {
- String paymentMethodId = npi.next();
+ for(String paymentMethodId : nullPaymentIds) {
BigDecimal selectedPaymentTotal = cart.getPaymentTotal();
BigDecimal requiredAmount = cart.getGrandTotal();
BigDecimal newAmount = requiredAmount.subtract(selectedPaymentTotal);
@@ -1635,9 +1613,7 @@ public class CheckOutHelper {
String balanceField = null;
// get the gift card objects to check
- Iterator<GenericValue> i = cart.getGiftCards().iterator();
- while (i.hasNext()) {
- GenericValue gc = i.next();
+ for(GenericValue gc : cart.getGiftCards()) {
Map<String, Object> gcBalanceMap = null;
BigDecimal gcBalance = BigDecimal.ZERO;
try {
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Mon Mar 26 20:56:02 2012
@@ -20,6 +20,7 @@ package org.ofbiz.order.shoppingcart;
import javolution.util.FastList;
import javolution.util.FastMap;
+
import org.ofbiz.base.util.*;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.DelegatorFactory;
@@ -30,6 +31,7 @@ import org.ofbiz.entity.condition.Entity
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.entity.util.EntityUtilProperties;
import org.ofbiz.order.finaccount.FinAccountHelper;
import org.ofbiz.order.order.OrderReadHelper;
import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;
@@ -49,6 +51,7 @@ import java.math.BigDecimal;
import java.math.MathContext;
import java.sql.Timestamp;
import java.util.*;
+import java.util.Map.Entry;
/**
* Shopping Cart Object
@@ -215,9 +218,7 @@ public class ShoppingCart implements Ite
}
// clone the groups
- Iterator<ShoppingCartItemGroup> groupIt = cart.itemGroupByNumberMap.values().iterator();
- while (groupIt.hasNext()) {
- ShoppingCartItemGroup itemGroup = groupIt.next();
+ for(ShoppingCartItemGroup itemGroup : cart.itemGroupByNumberMap.values()) {
// get the new parent group by number from the existing set; as before the parent must come before all children to work...
ShoppingCartItemGroup parentGroup = null;
if (itemGroup.getParentGroup() != null) parentGroup = this.getItemGroupByNumber(itemGroup.getParentGroup().getGroupNumber());
@@ -226,12 +227,10 @@ public class ShoppingCart implements Ite
}
// clone the items
- List<ShoppingCartItem> items = cart.items();
- Iterator<ShoppingCartItem> itIt = items.iterator();
- while (itIt.hasNext()) {
- cartLines.add(new ShoppingCartItem(itIt.next()));
+ for(ShoppingCartItem item : cart.items()) {
+ cartLines.add(new ShoppingCartItem(item));
}
-
+
this.facilityId = cart.facilityId;
this.webSiteId = cart.webSiteId;
}
@@ -244,7 +243,7 @@ public class ShoppingCart implements Ite
this.productStoreId = productStoreId;
this.webSiteId = webSiteId;
this.locale = (locale != null) ? locale : Locale.getDefault();
- this.currencyUom = (currencyUom != null) ? currencyUom : UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");
+ this.currencyUom = (currencyUom != null) ? currencyUom : EntityUtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD", delegator);
this.billToCustomerPartyId = billToCustomerPartyId;
this.billFromVendorPartyId = billFromVendorPartyId;
@@ -426,9 +425,7 @@ public class ShoppingCart implements Ite
String previousCurrency = this.currencyUom;
this.currencyUom = currencyUom;
if (!previousCurrency.equals(this.currencyUom)) {
- Iterator<ShoppingCartItem> itemIterator = this.iterator();
- while (itemIterator.hasNext()) {
- ShoppingCartItem item = itemIterator.next();
+ for(ShoppingCartItem item : this) {
item.updatePrice(dispatcher, this);
}
}
@@ -489,6 +486,14 @@ public class ShoppingCart implements Ite
String accommodationMapId, String accommodationSpotId,
Timestamp shipBeforeDate, Timestamp shipAfterDate, Map<String, GenericValue> features, Map<String, Object> attributes, String prodCatalogId,
ProductConfigWrapper configWrapper, String itemType, String itemGroupNumber, String parentProductId, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {
+ return addOrIncreaseItem(productId, selectedAmount, quantity, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, features, attributes, null, prodCatalogId, configWrapper, itemType, itemGroupNumber, parentProductId, dispatcher);
+ }
+
+ /** add rental (with accommodation) item to cart and order item attributes*/
+ public int addOrIncreaseItem(String productId, BigDecimal selectedAmount, BigDecimal quantity, Timestamp reservStart, BigDecimal reservLength, BigDecimal reservPersons,
+ String accommodationMapId, String accommodationSpotId,
+ Timestamp shipBeforeDate, Timestamp shipAfterDate, Map<String, GenericValue> features, Map<String, Object> attributes, Map<String, String> orderItemAttributes, 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");
}
@@ -504,7 +509,7 @@ public class ShoppingCart implements Ite
ShoppingCartItem sci = cartLines.get(i);
- if (sci.equals(productId, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, features, attributes, prodCatalogId,selectedAmount, configWrapper, itemType, itemGroup, false)) {
+ if (sci.equals(productId, reservStart, reservLength, reservPersons, accommodationMapId, accommodationSpotId, features, attributes, orderItemAttributes, prodCatalogId,selectedAmount, configWrapper, itemType, itemGroup, false)) {
BigDecimal newQuantity = sci.getQuantity().add(quantity);
try {
BigDecimal minQuantity = getMinimumOrderQuantity(getDelegator(),sci.getBasePrice(), productId);
@@ -542,11 +547,12 @@ public class ShoppingCart implements Ite
}
}
// Add the new item to the shopping cart if it wasn't found.
+ ShoppingCartItem item = null;
if (getOrderType().equals("PURCHASE_ORDER")) {
//GenericValue productSupplier = null;
supplierProduct = getSupplierProduct(productId, quantity, dispatcher);
if (supplierProduct != null || "_NA_".equals(this.getPartyId())) {
- return this.addItem(0, ShoppingCartItem.makePurchaseOrderItem(Integer.valueOf(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, this, supplierProduct, shipBeforeDate, shipAfterDate, cancelBackOrderDate));
+ item = ShoppingCartItem.makePurchaseOrderItem(Integer.valueOf(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, this, supplierProduct, shipBeforeDate, shipAfterDate, cancelBackOrderDate);
} else {
throw new CartItemModifyException("SupplierProduct not found");
}
@@ -559,11 +565,20 @@ public class ShoppingCart implements Ite
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
- return this.addItem(0, ShoppingCartItem.makeItem(Integer.valueOf(0), productId, selectedAmount, quantity, null,
+ item = ShoppingCartItem.makeItem(Integer.valueOf(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));
+ this, Boolean.TRUE, Boolean.TRUE, parentProductId, Boolean.FALSE, Boolean.FALSE);
}
+ // add order item attributes
+ if (UtilValidate.isNotEmpty(orderItemAttributes)) {
+ for (Entry<String, String> entry : orderItemAttributes.entrySet()) {
+ item.setOrderItemAttribute(entry.getKey(), entry.getValue());
+ }
+ }
+
+ return this.addItem(0, item);
+
}
/** Add a non-product item to the shopping cart.
@@ -737,18 +752,14 @@ public class ShoppingCart implements Ite
localList.addAll(multipleItems);
// the ones to keep...
for (int i=0; i<maxItems; i++) localList.remove(0);
- Iterator<ShoppingCartItem> localIter = localList.iterator();
- while (localIter.hasNext()) {
- ShoppingCartItem item = localIter.next();
+ for(ShoppingCartItem item : localList) {
this.removeCartItem(item, dispatcher);
}
}
public static BigDecimal getItemsTotalQuantity(List<ShoppingCartItem> cartItems) {
BigDecimal totalQuantity = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> localIter = cartItems.iterator();
- while (localIter.hasNext()) {
- ShoppingCartItem item = localIter.next();
+ for(ShoppingCartItem item : cartItems) {
totalQuantity = totalQuantity.add(item.getQuantity());
}
return totalQuantity;
@@ -756,9 +767,7 @@ public class ShoppingCart implements Ite
public static List<GenericValue> getItemsProducts(List<ShoppingCartItem> cartItems) {
List<GenericValue> productList = FastList.newInstance();
- Iterator<ShoppingCartItem> localIter = cartItems.iterator();
- while (localIter.hasNext()) {
- ShoppingCartItem item = localIter.next();
+ for(ShoppingCartItem item : cartItems) {
GenericValue product = item.getProduct();
if (product != null) {
productList.add(product);
@@ -768,9 +777,7 @@ public class ShoppingCart implements Ite
}
public void ensureItemsQuantity(List<ShoppingCartItem> cartItems, LocalDispatcher dispatcher, BigDecimal quantity) throws CartItemModifyException {
- Iterator<ShoppingCartItem> localIter = cartItems.iterator();
- while (localIter.hasNext()) {
- ShoppingCartItem item = localIter.next();
+ for(ShoppingCartItem item : cartItems) {
if (item.getQuantity() != quantity) {
item.setQuantity(quantity, dispatcher, this);
}
@@ -781,10 +788,7 @@ public class ShoppingCart implements Ite
BigDecimal quantityRemoved = BigDecimal.ZERO;
// go through the items and reduce quantityToKeep by the item quantities until it is 0, then remove the remaining...
BigDecimal quantityToKeep = quantity;
- Iterator<ShoppingCartItem> localIter = cartItems.iterator();
- while (localIter.hasNext()) {
- ShoppingCartItem item = localIter.next();
-
+ for(ShoppingCartItem item : cartItems) {
if (quantityToKeep.compareTo(item.getQuantity()) >= 0) {
// quantityToKeep sufficient to keep it all... just reduce quantityToKeep and move on
quantityToKeep = quantityToKeep.subtract(item.getQuantity());
@@ -808,8 +812,7 @@ public class ShoppingCart implements Ite
// ============== WorkEffort related methods ===============
public boolean containAnyWorkEffortCartItems() {
// Check for existing cart item.
- for (int i = 0; i < this.cartLines.size(); i++) {
- ShoppingCartItem cartItem = cartLines.get(i);
+ for(ShoppingCartItem cartItem : this.cartLines) {
if (cartItem.getItemType().equals("RENTAL_ORDER_ITEM")) { // create workeffort items?
return true;
}
@@ -819,8 +822,7 @@ public class ShoppingCart implements Ite
public boolean containAllWorkEffortCartItems() {
// Check for existing cart item.
- for (int i = 0; i < this.cartLines.size(); i++) {
- ShoppingCartItem cartItem = cartLines.get(i);
+ for(ShoppingCartItem cartItem : this.cartLines) {
if (!cartItem.getItemType().equals("RENTAL_ORDER_ITEM")) { // not a item to create workefforts?
return false;
}
@@ -833,8 +835,7 @@ public class ShoppingCart implements Ite
* 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++) {
- ShoppingCartItem cartItem = cartLines.get(i);
+ for(ShoppingCartItem cartItem : this.cartLines) {
GenericValue product = cartItem.getProduct();
try {
GenericValue productType = product.getRelatedOneCache("ProductType");
@@ -1003,16 +1004,12 @@ public class ShoppingCart implements Ite
if (itemGroup != null) {
// go through all cart items and remove from group if they are in it
List<ShoppingCartItem> cartItemList = this.getCartItemsInGroup(groupNumber);
- Iterator<ShoppingCartItem> cartItemIter = cartItemList.iterator();
- while (cartItemIter.hasNext()) {
- ShoppingCartItem cartItem = cartItemIter.next();
+ for(ShoppingCartItem cartItem : cartItemList) {
cartItem.setItemGroup(null);
}
// if this is a parent of any set them to this group's parent (or null)
- Iterator<ShoppingCartItemGroup> itemGroupIter = this.itemGroupByNumberMap.values().iterator();
- while (itemGroupIter.hasNext()) {
- ShoppingCartItemGroup otherItemGroup = itemGroupIter.next();
+ for(ShoppingCartItemGroup otherItemGroup : this.itemGroupByNumberMap.values()) {
if (itemGroup.equals(otherItemGroup.getParentGroup())) {
otherItemGroup.inheritParentsParent();
}
@@ -1068,9 +1065,7 @@ public class ShoppingCart implements Ite
String partyId = this.getPartyId();
if (UtilValidate.isNotEmpty(partyId)) {
// recalculate all prices
- Iterator<ShoppingCartItem> cartItemIter = this.iterator();
- while (cartItemIter.hasNext()) {
- ShoppingCartItem cartItem = cartItemIter.next();
+ for(ShoppingCartItem cartItem : this) {
cartItem.updatePrice(dispatcher, this);
}
@@ -1555,9 +1550,7 @@ public class ShoppingCart implements Ite
/** Returns the CartPaymentInfo objects which have matching fields */
public List<CartPaymentInfo> getPaymentInfos(boolean isPaymentMethod, boolean isPaymentMethodType, boolean hasRefNum) {
List<CartPaymentInfo> foundRecords = new LinkedList<CartPaymentInfo>();
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (isPaymentMethod && inf.paymentMethodId != null) {
if (hasRefNum && inf.refNum != null) {
foundRecords.add(inf);
@@ -1583,9 +1576,7 @@ public class ShoppingCart implements Ite
/** Locates an existing (or creates a new) CartPaymentInfo object */
public CartPaymentInfo getPaymentInfo(String id, String refNum, String authCode, BigDecimal amount, boolean update) {
CartPaymentInfo thisInf = this.makePaymentInfo(id, refNum, authCode, amount);
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.compareTo(thisInf) == 0) {
// update the info
if (update) {
@@ -1621,9 +1612,7 @@ public class ShoppingCart implements Ite
// this payment method will set the billing address for the order;
// before it is set we have to verify if the billing address is
// compatible with the ProductGeos
- Iterator<GenericValue> products = (ShoppingCart.getItemsProducts(this.cartLines)).iterator();
- while (products.hasNext()) {
- GenericValue product = products.next();
+ for(GenericValue product : ShoppingCart.getItemsProducts(this.cartLines)) {
if (!ProductWorker.isBillableToAddress(product, billingAddress)) {
throw new IllegalArgumentException("The billing address is not compatible with ProductGeos rules.");
}
@@ -1666,9 +1655,7 @@ public class ShoppingCart implements Ite
}
public String getPaymentRef(String id) {
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.paymentMethodId.equals(id) || inf.paymentMethodTypeId.equals(id)) {
return inf.refNum[0];
}
@@ -1679,9 +1666,7 @@ public class ShoppingCart implements Ite
/** returns the total payment amounts */
public BigDecimal getPaymentTotal() {
BigDecimal total = BigDecimal.ZERO;
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.amount != null) {
total = total.add(inf.amount);
}
@@ -1734,8 +1719,7 @@ public class ShoppingCart implements Ite
List<GenericValue> declinedPaymentMethods = delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", orderId, "statusId", "PAYMENT_DECLINED"));
if (!UtilValidate.isEmpty(declinedPaymentMethods)) {
List<String> paymentMethodIdsToRemove = new ArrayList<String>();
- for (Iterator<GenericValue> iter = declinedPaymentMethods.iterator(); iter.hasNext();) {
- GenericValue opp = iter.next();
+ for(GenericValue opp : declinedPaymentMethods) {
paymentMethodIdsToRemove.add(opp.getString("paymentMethodId"));
}
clearPaymentMethodsById(paymentMethodIdsToRemove);
@@ -1749,9 +1733,7 @@ public class ShoppingCart implements Ite
private void expireSingleUsePayments() {
Timestamp now = UtilDateTime.nowTimestamp();
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.paymentMethodId == null || !inf.singleUse) {
continue;
}
@@ -1778,9 +1760,7 @@ public class ShoppingCart implements Ite
/** Returns the Payment Method Ids */
public List<String> getPaymentMethodIds() {
List<String> pmi = new LinkedList<String>();
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.paymentMethodId != null) {
pmi.add(inf.paymentMethodId);
}
@@ -1791,9 +1771,7 @@ public class ShoppingCart implements Ite
/** Returns the Payment Method Ids */
public List<String> getPaymentMethodTypeIds() {
List<String> pmt = FastList.newInstance();
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.paymentMethodTypeId != null) {
pmt.add(inf.paymentMethodTypeId);
}
@@ -1805,9 +1783,7 @@ public class ShoppingCart implements Ite
public List<GenericValue> getPaymentMethods() {
List<GenericValue> methods = FastList.newInstance();
if (UtilValidate.isNotEmpty(paymentInfo)) {
- Iterator<String> paymentMethodIdIter = getPaymentMethodIds().iterator();
- while (paymentMethodIdIter.hasNext()) {
- String paymentMethodId = paymentMethodIdIter.next();
+ for(String paymentMethodId : getPaymentMethodIds()) {
try {
GenericValue paymentMethod = this.getDelegator().findByPrimaryKeyCache("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId));
if (paymentMethod != null) {
@@ -1828,9 +1804,7 @@ public class ShoppingCart implements Ite
public List<GenericValue> getPaymentMethodTypes() {
List<GenericValue> types = new LinkedList<GenericValue>();
if (UtilValidate.isNotEmpty(paymentInfo)) {
- Iterator<String> i = getPaymentMethodTypeIds().iterator();
- while (i.hasNext()) {
- String id = i.next();
+ for(String id : getPaymentMethodIds()) {
try {
types.add(this.getDelegator().findByPrimaryKeyCache("PaymentMethodType", UtilMisc.toMap("paymentMethodTypeId", id)));
} catch (GenericEntityException e) {
@@ -1846,9 +1820,7 @@ public class ShoppingCart implements Ite
List<GenericValue> paymentMethods = this.getPaymentMethods();
List<GenericValue> creditCards = new LinkedList<GenericValue>();
if (paymentMethods != null) {
- Iterator<GenericValue> i = paymentMethods.iterator();
- while (i.hasNext()) {
- GenericValue pm = i.next();
+ for(GenericValue pm : paymentMethods) {
if ("CREDIT_CARD".equals(pm.getString("paymentMethodTypeId"))) {
try {
GenericValue cc = pm.getRelatedOne("CreditCard");
@@ -1867,9 +1839,7 @@ public class ShoppingCart implements Ite
List<GenericValue> paymentMethods = this.getPaymentMethods();
List<GenericValue> giftCards = new LinkedList<GenericValue>();
if (paymentMethods != null) {
- Iterator<GenericValue> i = paymentMethods.iterator();
- while (i.hasNext()) {
- GenericValue pm = i.next();
+ for(GenericValue pm : paymentMethods) {
if ("GIFT_CARD".equals(pm.getString("paymentMethodTypeId"))) {
try {
GenericValue gc = pm.getRelatedOne("GiftCard");
@@ -1901,9 +1871,7 @@ public class ShoppingCart implements Ite
public GenericValue getBillingAddress() {
GenericValue billingAddress = null;
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
billingAddress = inf.getBillingAddress(this.getDelegator());
if (billingAddress != null) {
break;
@@ -2088,8 +2056,7 @@ public class ShoppingCart implements Ite
Map<Integer, BigDecimal> shipGroups = this.getShipGroups(item);
if ((shipGroups != null) && (shipGroups.keySet() != null)) {
- for (Iterator<Integer> shipGroupKeys = shipGroups.keySet().iterator(); shipGroupKeys.hasNext();) {
- Integer shipGroup = shipGroupKeys.next();
+ for(Integer shipGroup : shipGroups.keySet()) {
CartShipInfo cartShipInfo = this.getShipInfo(shipGroup.intValue());
cartShipInfo.resetShipAfterDateIfBefore(item.getShipAfterDate());
@@ -2237,9 +2204,7 @@ public class ShoppingCart implements Ite
if (shippingAddress != null) {
Set<ShoppingCartItem> shipItems = csi.getShipItems();
if (UtilValidate.isNotEmpty(shipItems)) {
- Iterator<ShoppingCartItem> siit = shipItems.iterator();
- while (siit.hasNext()) {
- ShoppingCartItem cartItem = siit.next();
+ for(ShoppingCartItem cartItem : shipItems) {
GenericValue product = cartItem.getProduct();
if (UtilValidate.isNotEmpty(product)) {
if (!ProductWorker.isShippableToAddress(product, shippingAddress)) {
@@ -2586,11 +2551,8 @@ public class ShoppingCart implements Ite
public BigDecimal getTotalShipping() {
BigDecimal tempShipping = BigDecimal.ZERO;
- Iterator<CartShipInfo> shipIter = this.shipInfo.iterator();
- while (shipIter.hasNext()) {
- CartShipInfo csi = shipIter.next();
+ for(CartShipInfo csi : this.shipInfo) {
tempShipping = tempShipping.add(csi.shipEstimate);
-
}
return tempShipping;
@@ -2599,10 +2561,8 @@ public class ShoppingCart implements Ite
/** Returns the item-total in the cart (not including discount/tax/shipping). */
public BigDecimal getItemTotal() {
BigDecimal itemTotal = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
-
- while (i.hasNext()) {
- itemTotal = itemTotal.add((i.next()).getBasePrice());
+ for(ShoppingCartItem cartItem : this.cartLines) {
+ itemTotal = itemTotal.add(cartItem.getBasePrice());
}
return itemTotal;
}
@@ -2610,10 +2570,8 @@ public class ShoppingCart implements Ite
/** Returns the sub-total in the cart (item-total - discount). */
public BigDecimal getSubTotal() {
BigDecimal itemsTotal = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
-
- while (i.hasNext()) {
- itemsTotal = itemsTotal.add((i.next()).getItemSubTotal());
+ for(ShoppingCartItem cartItem : this.cartLines) {
+ itemsTotal = itemsTotal.add(cartItem.getItemSubTotal());
}
return itemsTotal;
}
@@ -2630,9 +2588,8 @@ public class ShoppingCart implements Ite
public BigDecimal getDisplaySubTotal() {
BigDecimal itemsTotal = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
- while (i.hasNext()) {
- itemsTotal = itemsTotal.add((i.next()).getDisplayItemSubTotal());
+ for(ShoppingCartItem cartItem : this.cartLines) {
+ itemsTotal = itemsTotal.add(cartItem.getDisplayItemSubTotal());
}
return itemsTotal;
}
@@ -2644,9 +2601,8 @@ public class ShoppingCart implements Ite
public BigDecimal getDisplayRecurringSubTotal() {
BigDecimal itemsTotal = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
- while (i.hasNext()) {
- itemsTotal = itemsTotal.add((i.next()).getDisplayItemRecurringSubTotal());
+ for(ShoppingCartItem cartItem : this.cartLines) {
+ itemsTotal = itemsTotal.add(cartItem.getDisplayItemRecurringSubTotal());
}
return itemsTotal;
}
@@ -2663,10 +2619,7 @@ public class ShoppingCart implements Ite
/** Returns the sub-total in the cart (item-total - discount). */
public BigDecimal getSubTotalForPromotions() {
BigDecimal itemsTotal = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
-
- while (i.hasNext()) {
- ShoppingCartItem cartItem = i.next();
+ for(ShoppingCartItem cartItem : this.cartLines) {
GenericValue product = cartItem.getProduct();
if (product != null && "N".equals(product.getString("includeInPromotions"))) {
// don't include in total if this is the case...
@@ -2684,8 +2637,7 @@ public class ShoppingCart implements Ite
public BigDecimal getOrderPaymentPreferenceTotalByType(String paymentMethodTypeId) {
BigDecimal total = BigDecimal.ZERO;
String thisPaymentMethodTypeId = null;
- for (Iterator<CartPaymentInfo> iter = paymentInfo.iterator(); iter.hasNext();) {
- CartPaymentInfo payment = iter.next();
+ for(CartPaymentInfo payment : paymentInfo) {
if (payment.amount == null) continue;
if (payment.paymentMethodId != null) {
try {
@@ -2749,10 +2701,10 @@ public class ShoppingCart implements Ite
public int getAdjustmentPromoIndex(String productPromoId) {
int index = adjustments.size();
while (index > 0) {
+ index--;
if (adjustments.get(index).getString("productPromoId").equals(productPromoId)) {
return(index);
}
- index++;
}
return -1;
}
@@ -2831,9 +2783,7 @@ public class ShoppingCart implements Ite
if (termTypeId == null) {
return false;
}
- Iterator<GenericValue> orderTermsIt = orderTerms.iterator();
- while (orderTermsIt.hasNext()) {
- GenericValue orderTerm = orderTermsIt.next();
+ for(GenericValue orderTerm : orderTerms) {
if (termTypeId.equals(orderTerm.getString("termTypeId"))) {
return true;
}
@@ -2857,11 +2807,8 @@ public class ShoppingCart implements Ite
List<List<GenericValue>> adjsLists = FastList.newInstance();
adjsLists.add(this.getAdjustments());
- Iterator<ShoppingCartItem> cartIterator = this.iterator();
-
- while (cartIterator.hasNext()) {
- ShoppingCartItem item = cartIterator.next();
+ for(ShoppingCartItem item : this) {
if (item.getAdjustments() != null) {
adjsLists.add(item.getAdjustments());
}
@@ -2886,11 +2833,8 @@ public class ShoppingCart implements Ite
/** Returns the total weight in the cart. */
public BigDecimal getTotalWeight() {
BigDecimal weight = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
-
- while (i.hasNext()) {
- ShoppingCartItem item = i.next();
+ for(ShoppingCartItem item : this.cartLines) {
weight = weight.add(item.getWeight().multiply(item.getQuantity()));
}
return weight;
@@ -2899,10 +2843,9 @@ public class ShoppingCart implements Ite
/** Returns the total quantity in the cart. */
public BigDecimal getTotalQuantity() {
BigDecimal count = BigDecimal.ZERO;
- Iterator<ShoppingCartItem> i = iterator();
- while (i.hasNext()) {
- count = count.add((i.next()).getQuantity());
+ for(ShoppingCartItem item : this.cartLines) {
+ count = count.add(item.getQuantity());
}
return count;
}
@@ -2997,9 +2940,7 @@ public class ShoppingCart implements Ite
/** Returns true when there are shippable items in the cart */
public boolean shippingApplies() {
boolean shippingApplies = false;
- Iterator<ShoppingCartItem> i = this.iterator();
- while (i.hasNext()) {
- ShoppingCartItem item = i.next();
+ for(ShoppingCartItem item : this) {
if (item.shippingApplies()) {
shippingApplies = true;
break;
@@ -3011,9 +2952,7 @@ public class ShoppingCart implements Ite
/** Returns true when there are taxable items in the cart */
public boolean taxApplies() {
boolean taxApplies = false;
- Iterator<ShoppingCartItem> i = this.iterator();
- while (i.hasNext()) {
- ShoppingCartItem item = i.next();
+ for(ShoppingCartItem item : this) {
if (item.taxApplies()) {
taxApplies = true;
break;
@@ -3131,9 +3070,7 @@ public class ShoppingCart implements Ite
public void clearCartItemUseInPromoInfo() {
// clear out info about which cart items have been used in promos
- Iterator<ShoppingCartItem> cartLineIter = this.iterator();
- while (cartLineIter.hasNext()) {
- ShoppingCartItem cartLine = cartLineIter.next();
+ for(ShoppingCartItem cartLine : this) {
cartLine.clearPromoRuleUseInfo();
}
}
@@ -3146,9 +3083,7 @@ public class ShoppingCart implements Ite
BigDecimal totalDiscount = BigDecimal.ZERO;
List<GenericValue> cartAdjustments = this.getAdjustments();
if (cartAdjustments != null) {
- Iterator<GenericValue> cartAdjustmentIter = cartAdjustments.iterator();
- while (cartAdjustmentIter.hasNext()) {
- GenericValue checkOrderAdjustment = cartAdjustmentIter.next();
+ for(GenericValue checkOrderAdjustment : cartAdjustments) {
if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) &&
UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) &&
UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) {
@@ -3160,9 +3095,7 @@ public class ShoppingCart implements Ite
}
// add cart line adjustments from promo actions
- Iterator<ShoppingCartItem> cartItemIter = this.iterator();
- while (cartItemIter.hasNext()) {
- ShoppingCartItem checkItem = cartItemIter.next();
+ for(ShoppingCartItem checkItem : this) {
Iterator<GenericValue> checkOrderAdjustments = UtilMisc.toIterator(checkItem.getAdjustments());
while (checkOrderAdjustments != null && checkOrderAdjustments.hasNext()) {
GenericValue checkOrderAdjustment = checkOrderAdjustments.next();
@@ -3266,17 +3199,13 @@ public class ShoppingCart implements Ite
// remove all cart adjustments
this.adjustments.clear();
// remove all cart item adjustments
- Iterator<ShoppingCartItem> cartItemIter = this.iterator();
- while (cartItemIter.hasNext()) {
- ShoppingCartItem checkItem = cartItemIter.next();
+ for(ShoppingCartItem checkItem : this) {
checkItem.getAdjustments().clear();
}
}
public void clearAllItemStatus() {
- Iterator<ShoppingCartItem> lineIter = this.iterator();
- while (lineIter.hasNext()) {
- ShoppingCartItem item = lineIter.next();
+ for(ShoppingCartItem item : this) {
item.setStatusId(null);
}
}
@@ -3310,17 +3239,13 @@ public class ShoppingCart implements Ite
}
public synchronized void resetPromoRuleUse(String productPromoId, String productPromoRuleId) {
- Iterator<ShoppingCartItem> lineIter = this.iterator();
- while (lineIter.hasNext()) {
- ShoppingCartItem cartItem = lineIter.next();
+ for(ShoppingCartItem cartItem : this) {
cartItem.resetPromoRuleUse(productPromoId, productPromoRuleId);
}
}
public synchronized void confirmPromoRuleUse(String productPromoId, String productPromoRuleId) {
- Iterator<ShoppingCartItem> lineIter = this.iterator();
- while (lineIter.hasNext()) {
- ShoppingCartItem cartItem = lineIter.next();
+ for(ShoppingCartItem cartItem : this) {
cartItem.confirmPromoRuleUse(productPromoId, productPromoRuleId);
}
}
@@ -3334,9 +3259,8 @@ public class ShoppingCart implements Ite
// search if there is an existing entry
List<String> parties = additionalPartyRole.get(roleTypeId);
if (parties != null) {
- Iterator<String> it = parties.iterator();
- while (it.hasNext()) {
- if ((it.next()).equals(partyId)) {
+ for(String pi : parties) {
+ if (pi.equals(partyId)) {
return;
}
}
@@ -3410,7 +3334,11 @@ public class ShoppingCart implements Ite
serviceContext.put("internalName", internalName);
serviceContext.put("productName", productName);
serviceContext.put("description", description);
- serviceContext.put("productTypeId", "AGGREGATED_CONF");
+ if(ProductWorker.isAggregateService(delegator, item.getProductId()))
+ serviceContext.put("productTypeId", "AGGREGATEDSERV_CONF");
+ else
+ serviceContext.put("productTypeId", "AGGREGATED_CONF");
+
serviceContext.put("configId", configId);
if (UtilValidate.isNotEmpty(product.getString("requirementMethodEnumId"))) {
serviceContext.put("requirementMethodEnumId", product.getString("requirementMethodEnumId"));
@@ -3466,9 +3394,7 @@ public class ShoppingCart implements Ite
public List<GenericValue> makeOrderItemGroups() {
List<GenericValue> result = FastList.newInstance();
- Iterator<ShoppingCartItemGroup> groupValueIter = this.itemGroupByNumberMap.values().iterator();
- while (groupValueIter.hasNext()) {
- ShoppingCart.ShoppingCartItemGroup itemGroup = groupValueIter.next();
+ for(ShoppingCart.ShoppingCartItemGroup itemGroup : this.itemGroupByNumberMap.values()) {
result.add(itemGroup.makeOrderItemGroup(this.getDelegator()));
}
return result;
@@ -3478,11 +3404,7 @@ public class ShoppingCart implements Ite
if (dispatcher == null) return;
synchronized (cartLines) {
List<ShoppingCartItem> cartLineItems = new LinkedList<ShoppingCartItem>(cartLines);
- Iterator<ShoppingCartItem> itemIter = cartLineItems.iterator();
-
- while (itemIter.hasNext()) {
- ShoppingCartItem item = itemIter.next();
-
+ for(ShoppingCartItem item : cartLineItems) {
//Debug.logInfo("Item qty: " + item.getQuantity(), module);
try {
item.explodeItem(this, dispatcher);
@@ -3503,10 +3425,7 @@ public class ShoppingCart implements Ite
public void explodeItems(List<ShoppingCartItem> shoppingCartItems, LocalDispatcher dispatcher) {
if (dispatcher == null) return;
synchronized (cartLines) {
- Iterator<ShoppingCartItem> itemIter = shoppingCartItems.iterator();
- while (itemIter.hasNext()) {
- ShoppingCartItem item = itemIter.next();
-
+ for(ShoppingCartItem item : shoppingCartItems) {
//Debug.logInfo("Item qty: " + item.getQuantity(), module);
try {
item.explodeItem(this, dispatcher);
@@ -3780,9 +3699,7 @@ public class ShoppingCart implements Ite
remainingAmount = BigDecimal.ZERO;
}
}
- Iterator<CartPaymentInfo> i = paymentInfo.iterator();
- while (i.hasNext()) {
- CartPaymentInfo inf = i.next();
+ for(CartPaymentInfo inf : paymentInfo) {
if (inf.amount == null) {
inf.amount = remainingAmount;
remainingAmount = BigDecimal.ZERO;
@@ -3801,11 +3718,7 @@ public class ShoppingCart implements Ite
Collection<GenericValue> infos = item.getOrderItemPriceInfos();
if (infos != null) {
- Iterator<GenericValue> infosIter = infos.iterator();
-
- while (infosIter.hasNext()) {
- GenericValue orderItemPriceInfo = infosIter.next();
-
+ for(GenericValue orderItemPriceInfo : infos) {
orderItemPriceInfo.set("orderItemSeqId", item.getOrderItemSeqId());
allInfos.add(orderItemPriceInfo);
}
@@ -3836,15 +3749,11 @@ public class ShoppingCart implements Ite
/** make a list of SurveyResponse object to update with order information set */
public List<GenericValue> makeAllOrderItemSurveyResponses() {
List<GenericValue> allInfos = new LinkedList<GenericValue>();
- Iterator<ShoppingCartItem> itemIter = this.iterator();
- while (itemIter.hasNext()) {
- ShoppingCartItem item = itemIter.next();
+ for(ShoppingCartItem item : this) {
List<String> responses = UtilGenerics.checkList(item.getAttribute("surveyResponses"));
GenericValue response = null;
if (responses != null) {
- Iterator<String> ri = responses.iterator();
- while (ri.hasNext()) {
- String responseId = ri.next();
+ for(String responseId : responses) {
try {
response = this.getDelegator().findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", responseId));
} catch (GenericEntityException e) {
@@ -3910,10 +3819,8 @@ public class ShoppingCart implements Ite
public List<GenericValue> makeAllShipGroupInfos() {
List<GenericValue> groups = new LinkedList<GenericValue>();
- Iterator<CartShipInfo> grpIterator = this.shipInfo.iterator();
long seqId = 1;
- while (grpIterator.hasNext()) {
- CartShipInfo csi = grpIterator.next();
+ for(CartShipInfo csi : this.shipInfo) {
groups.addAll(csi.makeItemShipGroupAndAssoc(this.getDelegator(), this, seqId));
seqId++;
}
@@ -3936,9 +3843,7 @@ public class ShoppingCart implements Ite
for (ShoppingCartItem item : cartLines) {
Map<String, String> orderItemAttributes = item.getOrderItemAttributes();
- Iterator<String> attributesIter = orderItemAttributes.keySet().iterator();
- while (attributesIter.hasNext()) {
- String key = attributesIter.next();
+ for(String key : orderItemAttributes.keySet()) {
String value = orderItemAttributes.get(key);
GenericValue orderItemAttribute = getDelegator().makeValue("OrderItemAttribute");
@@ -4020,36 +3925,39 @@ public class ShoppingCart implements Ite
public List<GenericValue> makeAllOrderItemAssociations() {
List<GenericValue> allOrderItemAssociations = new LinkedList<GenericValue>();
- for (ShoppingCartItem item : cartLines) {
- String requirementId = item.getRequirementId();
- if (requirementId != null) {
- try {
- List<GenericValue> commitments = getDelegator().findByAnd("OrderRequirementCommitment", UtilMisc.toMap("requirementId", requirementId));
- // TODO: multiple commitments for the same requirement are still not supported
- GenericValue commitment = EntityUtil.getFirst(commitments);
- if (commitment != null) {
- GenericValue orderItemAssociation = getDelegator().makeValue("OrderItemAssoc");
- orderItemAssociation.set("orderId", commitment.getString("orderId"));
- orderItemAssociation.set("orderItemSeqId", commitment.getString("orderItemSeqId"));
- orderItemAssociation.set("shipGroupSeqId", "_NA_");
- orderItemAssociation.set("toOrderItemSeqId", item.getOrderItemSeqId());
- orderItemAssociation.set("toShipGroupSeqId", "_NA_");
- orderItemAssociation.set("orderItemAssocTypeId", "PURCHASE_ORDER");
- allOrderItemAssociations.add(orderItemAssociation);
+ for (CartShipInfo csi : shipInfo) {
+ Set<ShoppingCartItem> items = csi.getShipItems();
+ for (ShoppingCartItem item : items) {
+ String requirementId = item.getRequirementId();
+ if (requirementId != null) {
+ try {
+ List<GenericValue> commitments = getDelegator().findByAnd("OrderRequirementCommitment", UtilMisc.toMap("requirementId", requirementId));
+ // TODO: multiple commitments for the same requirement are still not supported
+ GenericValue commitment = EntityUtil.getFirst(commitments);
+ if (commitment != null) {
+ GenericValue orderItemAssociation = getDelegator().makeValue("OrderItemAssoc");
+ orderItemAssociation.set("orderId", commitment.getString("orderId"));
+ orderItemAssociation.set("orderItemSeqId", commitment.getString("orderItemSeqId"));
+ orderItemAssociation.set("shipGroupSeqId", "_NA_");
+ orderItemAssociation.set("toOrderItemSeqId", item.getOrderItemSeqId());
+ orderItemAssociation.set("toShipGroupSeqId", "_NA_");
+ orderItemAssociation.set("orderItemAssocTypeId", "PURCHASE_ORDER");
+ allOrderItemAssociations.add(orderItemAssociation);
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, "Unable to load OrderRequirementCommitment records for requirement ID : " + requirementId, module);
}
- } catch (GenericEntityException e) {
- Debug.logError(e, "Unable to load OrderRequirementCommitment records for requirement ID : " + requirementId, module);
}
- }
- if (item.getAssociatedOrderId() != null && item.getAssociatedOrderItemSeqId() != null) {
- GenericValue orderItemAssociation = getDelegator().makeValue("OrderItemAssoc");
- orderItemAssociation.set("orderId", item.getAssociatedOrderId());
- orderItemAssociation.set("orderItemSeqId", item.getAssociatedOrderItemSeqId());
- orderItemAssociation.set("shipGroupSeqId", "_NA_");
- orderItemAssociation.set("toOrderItemSeqId", item.getOrderItemSeqId());
- orderItemAssociation.set("toShipGroupSeqId", "_NA_");
- orderItemAssociation.set("orderItemAssocTypeId", item.getOrderItemAssocTypeId());
- allOrderItemAssociations.add(orderItemAssociation);
+ if (item.getAssociatedOrderId() != null && item.getAssociatedOrderItemSeqId() != null) {
+ GenericValue orderItemAssociation = getDelegator().makeValue("OrderItemAssoc");
+ orderItemAssociation.set("orderId", item.getAssociatedOrderId());
+ orderItemAssociation.set("orderItemSeqId", item.getAssociatedOrderItemSeqId());
+ orderItemAssociation.set("shipGroupSeqId", csi.getAssociatedShipGroupSeqId() != null ? csi.getAssociatedShipGroupSeqId() : "_NA_");
+ orderItemAssociation.set("toOrderItemSeqId", item.getOrderItemSeqId());
+ orderItemAssociation.set("toShipGroupSeqId", csi.getShipGroupSeqId() != null ? csi.getShipGroupSeqId() : "_NA_");
+ orderItemAssociation.set("orderItemAssocTypeId", item.getOrderItemAssocTypeId());
+ allOrderItemAssociations.add(orderItemAssociation);
+ }
}
}
return allOrderItemAssociations;
@@ -4172,11 +4080,7 @@ public class ShoppingCart implements Ite
Set<ShoppingCartItem> shipItems = shipInfo.getShipItems();
if (UtilValidate.isEmpty(shipItems)) continue;
- Iterator<ShoppingCartItem> siit = shipItems.iterator();
- while (siit.hasNext()) {
-
- ShoppingCartItem cartItem = siit.next();
-
+ for(ShoppingCartItem cartItem : shipItems) {
BigDecimal itemQuantity = cartItem.getQuantity();
BigDecimal dropShipQuantity = BigDecimal.ZERO;
@@ -4248,10 +4152,7 @@ public class ShoppingCart implements Ite
}
// Reassign the drop-shippable item quantities to new or existing drop-ship groups
- Iterator<String> dsit = dropShipItems.keySet().iterator();
- while (dsit.hasNext()) {
- String supplierPartyId = dsit.next();
-
+ for (String supplierPartyId : dropShipItems.keySet()) {
CartShipInfo shipInfo = null;
int newShipGroupIndex = -1 ;
@@ -4268,15 +4169,9 @@ public class ShoppingCart implements Ite
shipInfo.supplierPartyId = supplierPartyId;
Map<ShoppingCartItem, Map<Integer, BigDecimal>> supplierCartItems = UtilGenerics.checkMap(dropShipItems.get(supplierPartyId));
- Iterator<ShoppingCartItem> itit = supplierCartItems.keySet().iterator();
- while (itit.hasNext()) {
-
- ShoppingCartItem cartItem = itit.next();
+ for(ShoppingCartItem cartItem : supplierCartItems.keySet()) {
Map<Integer, BigDecimal> cartItemGroupQuantities = UtilGenerics.checkMap(supplierCartItems.get(cartItem));
- Iterator<Integer> cigit = cartItemGroupQuantities.keySet().iterator();
- while (cigit.hasNext()) {
-
- Integer previousShipGroupIndex = cigit.next();
+ for(Integer previousShipGroupIndex : cartItemGroupQuantities.keySet()) {
BigDecimal dropShipQuantity = cartItemGroupQuantities.get(previousShipGroupIndex);
positionItemToGroup(cartItem, dropShipQuantity, previousShipGroupIndex.intValue(), newShipGroupIndex, true);
}
@@ -4422,6 +4317,7 @@ public class ShoppingCart implements Ite
public Timestamp shipBeforeDate = null;
public Timestamp shipAfterDate = null;
private String shipGroupSeqId = null;
+ private String associatedShipGroupSeqId = null;
public String vendorPartyId = null;
public String productStoreShipMethId = null;
public Map<String, Object> attributes = FastMap.newInstance();
@@ -4456,6 +4352,11 @@ public class ShoppingCart implements Ite
this.shipGroupSeqId = shipGroupSeqId;
}
+ public String getAssociatedShipGroupSeqId() { return associatedShipGroupSeqId; }
+ public void setAssociatedShipGroupSeqId(String shipGroupSeqId) {
+ this.associatedShipGroupSeqId = shipGroupSeqId;
+ }
+
public String getFacilityId() { return facilityId; }
public void setFacilityId(String facilityId) {
this.facilityId = facilityId;
@@ -4474,9 +4375,7 @@ public class ShoppingCart implements Ite
public void clearAllTaxInfo() {
this.shipTaxAdj.clear();
- Iterator<CartShipItemInfo> i = shipItemInfo.values().iterator();
- while (i.hasNext()) {
- CartShipItemInfo itemInfo = i.next();
+ for(CartShipItemInfo itemInfo : shipItemInfo.values()) {
itemInfo.itemTaxAdj.clear();
}
}
@@ -4561,17 +4460,13 @@ public class ShoppingCart implements Ite
}
// create the top level tax adjustments
- Iterator<GenericValue> ti = shipTaxAdj.iterator();
- while (ti.hasNext()) {
- GenericValue taxAdj = ti.next();
+ for(GenericValue taxAdj : shipTaxAdj) {
taxAdj.set("shipGroupSeqId", shipGroupSeqId);
values.add(taxAdj);
}
// create the ship group item associations
- Iterator<ShoppingCartItem> i = shipItemInfo.keySet().iterator();
- while (i.hasNext()) {
- ShoppingCartItem item = i.next();
+ for(ShoppingCartItem item : shipItemInfo.keySet()) {
CartShipItemInfo itemInfo = shipItemInfo.get(item);
GenericValue assoc = delegator.makeValue("OrderItemShipGroupAssoc");
@@ -4581,9 +4476,7 @@ public class ShoppingCart implements Ite
values.add(assoc);
// create the item tax adjustment
- Iterator<GenericValue> iti = itemInfo.itemTaxAdj.iterator();
- while (iti.hasNext()) {
- GenericValue taxAdj = iti.next();
+ for(GenericValue taxAdj : itemInfo.itemTaxAdj) {
taxAdj.set("orderItemSeqId", item.getOrderItemSeqId());
taxAdj.set("shipGroupSeqId", shipGroupSeqId);
values.add(taxAdj);
@@ -4837,9 +4730,7 @@ public class ShoppingCart implements Ite
throw new GeneralRuntimeException("Split Payment Preference per Ship Group does not yet support multiple Payment Methods");
}
if ("Y".equals(splitPayPrefPerShpGrp) && cart.paymentInfo.size() == 1) {
- Iterator<CartShipInfo> shipIter = cart.getShipGroups().iterator();
- while (shipIter.hasNext()) {
- CartShipInfo csi = shipIter.next();
+ for(CartShipInfo csi : cart.getShipGroups()) {
maxAmount = csi.getTotal().add(cart.getOrderOtherAdjustmentTotal().divide(new BigDecimal(cart.getShipGroupSize()), generalRounding)).add(csi.getShipEstimate().add(csi.getTotalTax(cart)));
maxAmount = maxAmount.setScale(scale, rounding);
@@ -4875,8 +4766,8 @@ public class ShoppingCart implements Ite
opp.set("statusId", "PAYMENT_RECEIVED");
}
}
- Debug.log("ShipGroup [" + csi.getShipGroupSeqId() +"]", module);
- Debug.log("Creating OrderPaymentPreference - " + opp, module);
+ Debug.logInfo("ShipGroup [" + csi.getShipGroupSeqId() +"]", module);
+ Debug.logInfo("Creating OrderPaymentPreference - " + opp, module);
values.add(opp);
}
} else if ("N".equals(splitPayPrefPerShpGrp)) {
@@ -4914,7 +4805,7 @@ public class ShoppingCart implements Ite
opp.set("statusId", "PAYMENT_RECEIVED");
}
}
- Debug.log("Creating OrderPaymentPreference - " + opp, module);
+ Debug.logInfo("Creating OrderPaymentPreference - " + opp, module);
values.add(opp);
}
}
@@ -5031,10 +4922,8 @@ public class ShoppingCart implements Ite
}
if (itemBasePrice == null) {
List<GenericValue> productPriceList = EntityUtil.filterByDate(delegator.findList("ProductPrice", EntityCondition.makeCondition("productId", itemProductId), null, null, null, false));
- Iterator<GenericValue> it = productPriceList.iterator();
Map<String, BigDecimal> productPriceMap = FastMap.newInstance();
- while (it.hasNext()) {
- GenericValue productPrice = it.next();
+ for(GenericValue productPrice : productPriceList) {
productPriceMap.put(productPrice.getString("productPriceTypeId"), productPrice.getBigDecimal("price"));
}
if (UtilValidate.isNotEmpty(productPriceMap.get("SPECIAL_PROMO_PRICE"))) {
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Mon Mar 26 20:56:02 2012
@@ -522,9 +522,7 @@ public class ShoppingCartEvents {
productAssocs = delegator.findList("ProductAssoc", cond, null, null, null, false);
productAssocs = EntityUtil.filterByDate(productAssocs);
List<String> productList = FastList.newInstance();
- Iterator<GenericValue> iter = productAssocs.iterator();
- while (iter.hasNext()) {
- GenericValue productAssoc = iter.next();
+ for(GenericValue productAssoc : productAssocs) {
if (productId.equals(productAssoc.getString("productId"))) {
productList.add(productAssoc.getString("productIdTo"));
continue;
@@ -534,9 +532,7 @@ public class ShoppingCartEvents {
continue;
}
}
- Iterator<ShoppingCartItem> sciIter = cart.iterator();
- while (sciIter.hasNext()) {
- ShoppingCartItem sci = sciIter.next();
+ for(ShoppingCartItem sci : cart) {
if (productList.contains(sci.getProductId())) {
try {
cart.removeCartItem(sci, dispatcher);
@@ -553,9 +549,7 @@ public class ShoppingCartEvents {
EntityCondition.makeCondition("productAssocTypeId", EntityOperator.EQUALS, "PRODUCT_UPGRADE")), EntityOperator.AND);
productList = delegator.findList("ProductAssoc", cond, UtilMisc.toSet("productId"), null, null, false);
if (productList != null) {
- Iterator<ShoppingCartItem> sciIter = cart.iterator();
- while (sciIter.hasNext()) {
- ShoppingCartItem sci = sciIter.next();
+ for(ShoppingCartItem sci : cart) {
if (productList.contains(sci.getProductId())) {
try {
cart.removeCartItem(sci, dispatcher);
Modified: ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1305581&r1=1305580&r2=1305581&view=diff
==============================================================================
--- ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original)
+++ ofbiz/branches/20111205EmailHandling/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Mon Mar 26 20:56:02 2012
@@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import javolution.util.FastMap;
@@ -44,6 +45,7 @@ import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityTypeUtil;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.order.order.OrderReadHelper;
import org.ofbiz.order.shoppingcart.product.ProductPromoWorker;
@@ -207,10 +209,8 @@ public class ShoppingCartHelper {
// Get the additional features selected for the product (if any)
Map<String, Object> selectedFeatures = UtilHttp.makeParamMapWithPrefix(context, null, "FT", null);
- Iterator<String> selectedFeaturesTypes = selectedFeatures.keySet().iterator();
Map<String, GenericValue> additionalFeaturesMap = FastMap.newInstance();
- while (selectedFeaturesTypes.hasNext()) {
- String selectedFeatureType = selectedFeaturesTypes.next();
+ for(String selectedFeatureType : selectedFeatures.keySet()) {
String selectedFeatureValue = (String)selectedFeatures.get(selectedFeatureType);
if (UtilValidate.isNotEmpty(selectedFeatureValue)) {
GenericValue productFeatureAndAppl = null;
@@ -229,6 +229,15 @@ public class ShoppingCartHelper {
}
}
+ // get order item attributes
+ Map<String, String> orderItemAttributes = FastMap.newInstance();
+ String orderItemAttributePrefix = UtilProperties.getPropertyValue("order.properties", "order.item.attr.prefix");
+ for (Entry<String, ? extends Object> entry : context.entrySet()) {
+ if (entry.getKey().toString().contains(orderItemAttributePrefix) && UtilValidate.isNotEmpty(entry.getValue())) {
+ orderItemAttributes.put(entry.getKey().replaceAll(orderItemAttributePrefix, ""), entry.getValue().toString());
+ }
+ }
+
// add or increase the item to the cart
int itemId = -1;
try {
@@ -236,7 +245,7 @@ public class ShoppingCartHelper {
itemId = cart.addOrIncreaseItem(productId, amount, quantity, reservStart, reservLength,
reservPersons, accommodationMapId, accommodationSpotId, shipBeforeDate, shipAfterDate, additionalFeaturesMap, attributes,
- catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher);
+ orderItemAttributes, catalogId, configWrapper, itemType, itemGroupNumber, pProductId, dispatcher);
} else {
itemId = cart.addNonProductItem(itemType, itemDescription, productCategoryId, price, quantity, attributes, catalogId, itemGroupNumber, dispatcher);
@@ -317,7 +326,7 @@ public class ShoppingCartHelper {
BigDecimal amount = orderItem.getBigDecimal("selectedAmount");
ProductConfigWrapper configWrapper = null;
String aggregatedProdId = null;
- if ("AGGREGATED_CONF".equals(ProductWorker.getProductTypeId(delegator, productId))) {
+ if (EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", ProductWorker.getProductTypeId(delegator, productId), "parentTypeId", "AGGREGATED")) {
try {
GenericValue instanceProduct = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
String configId = instanceProduct.getString("configId");
@@ -577,10 +586,7 @@ public class ShoppingCartHelper {
}
BigDecimal totalQuantity = BigDecimal.ZERO;
- Iterator<GenericValue> pcmIter = prodCatMemberCol.iterator();
-
- while (pcmIter.hasNext()) {
- GenericValue productCategoryMember = pcmIter.next();
+ for(GenericValue productCategoryMember : prodCatMemberCol) {
BigDecimal quantity = productCategoryMember.getBigDecimal("quantity");
if (quantity != null && quantity.compareTo(BigDecimal.ZERO) > 0) {
@@ -610,13 +616,8 @@ public class ShoppingCartHelper {
/** Delete an item from the shopping cart. */
public Map<String, Object> deleteFromCart(Map<String, ? extends Object> context) {
Map<String, Object> result = null;
- Set<String> names = context.keySet();
- Iterator<String> i = names.iterator();
ArrayList<String> errorMsgs = new ArrayList<String>();
-
- while (i.hasNext()) {
- String o = i.next();
-
+ for(String o : context.keySet()) {
if (o.toUpperCase().startsWith("DELETE")) {
try {
String indexStr = o.substring(o.lastIndexOf('_') + 1);
@@ -651,9 +652,6 @@ public class ShoppingCartHelper {
ArrayList<ShoppingCartItem> deleteList = new ArrayList<ShoppingCartItem>();
ArrayList<String> errorMsgs = new ArrayList<String>();
- Set<String> parameterNames = context.keySet();
- Iterator<String> parameterNameIter = parameterNames.iterator();
-
BigDecimal oldQuantity = BigDecimal.ONE.negate();
String oldDescription = "";
BigDecimal oldPrice = BigDecimal.ONE.negate();
@@ -666,8 +664,7 @@ public class ShoppingCartHelper {
}
// TODO: This should be refactored to use UtilHttp.parseMultiFormData(parameters)
- while (parameterNameIter.hasNext()) {
- String parameterName = parameterNameIter.next();
+ for(String parameterName : context.keySet()) {
int underscorePos = parameterName.lastIndexOf('_');
if (underscorePos >= 0) {
@@ -870,10 +867,7 @@ public class ShoppingCartHelper {
}
}
- Iterator<ShoppingCartItem> di = deleteList.iterator();
-
- while (di.hasNext()) {
- ShoppingCartItem item = di.next();
+ for(ShoppingCartItem item : deleteList) {
int itemIndex = this.cart.getItemIndex(item);
if (Debug.infoOn())