diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalServices.java index 3c1888fea3d..730676f69e2 100644 --- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalServices.java +++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/thirdparty/paypal/PayPalServices.java @@ -484,7 +484,7 @@ public static Map getExpressCheckout(DispatchContext dctx, Map getExpressCheckout(DispatchContext dctx, Map getExpressCheckout(DispatchContext dctx, Map postalMap = new HashMap<>(); postalMap.put("toName", decoder.get("SHIPTONAME")); postalMap.put("address1", decoder.get("SHIPTOSTREET")); diff --git a/applications/order/src/main/groovy/org/apache/ofbiz/order/order/CheckoutServices.groovy b/applications/order/src/main/groovy/org/apache/ofbiz/order/order/CheckoutServices.groovy index eb69276ced6..f799ef1cc2b 100644 --- a/applications/order/src/main/groovy/org/apache/ofbiz/order/order/CheckoutServices.groovy +++ b/applications/order/src/main/groovy/org/apache/ofbiz/order/order/CheckoutServices.groovy @@ -86,7 +86,7 @@ Map createUpdateCustomerAndShippingAddress() { result.shipToPhoneContactMechId = serviceResultCUPTN.contactMechId if (shipToPhoneContactMechId) { - shoppingCart.addContactMech('PHONE_SHIPPING', shipToPhoneContactMechId) + shoppingCart.addContactMechId('PHONE_SHIPPING', shipToPhoneContactMechId) } // Create Update email address Map createUpdatePartyEmailCtx = emailAddressCtx @@ -98,10 +98,10 @@ Map createUpdateCustomerAndShippingAddress() { result.emailContactMechId = serviceResultCUPEM.contactMechId result.partyId = partyId if (parameters.emailContactMechId) { - shoppingCart.addContactMech('ORDER_EMAIL', parameters.emailContactMechId) + shoppingCart.addContactMechId('ORDER_EMAIL', parameters.emailContactMechId) } shoppingCart.setUserLogin(userLogin, dispatcher) - shoppingCart.addContactMech('SHIPPING_LOCATION', parameters.shipToContactMechId) + shoppingCart.addContactMechId('SHIPPING_LOCATION', parameters.shipToContactMechId) shoppingCart.setAllShippingContactMechId(parameters.shipToContactMechId) shoppingCart.setOrderPartyId(partyId) return result @@ -149,7 +149,7 @@ Map createUpdateBillingAddressAndPaymentMethod() { parameters.billToContactMechId = serviceResultCUBA.contactMechId result.contactMechId = serviceResultCUBA.contactMechId if (parameters.billToContactMechId) { - shoppingCart.addContactMech('BILLING_LOCATION', parameters.billToContactMechId) + shoppingCart.addContactMechId('BILLING_LOCATION', parameters.billToContactMechId) } // Create Update Billing Telecom Number Map createUpdatePartyTelecomNumberCtx = billToPhoneContext @@ -165,7 +165,7 @@ Map createUpdateBillingAddressAndPaymentMethod() { String billToPhoneContactMechId = serviceResultCUPTN.contactMechId result.billToPhoneContactMechId = serviceResultCUPTN.contactMechId if (billToPhoneContactMechId) { - shoppingCart.addContactMech('PHONE_BILLING', billToPhoneContactMechId) + shoppingCart.addContactMechId('PHONE_BILLING', billToPhoneContactMechId) } // Create Update credit card Map creditCartCtx = parameters diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java index 431c6cfb12a..196cb99c164 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java @@ -139,7 +139,7 @@ public class ShoppingCart implements Iterable, Serializable { private long nextGroupNumber = 1; private List paymentInfo = new LinkedList<>(); private List shipInfo = new LinkedList<>(); - private Map contactMechIdsMap = new HashMap<>(); + private Map> contactMechIdsMap = new HashMap<>(); private Map orderAttributes = new HashMap<>(); private Map attributes = new HashMap<>(); // user defined attributes // Lists of internal/public notes: when the order is stored they are transformed into OrderHeaderNotes @@ -3465,28 +3465,41 @@ public BigDecimal getGiftCardPaymentPreferenceTotal() { } /** Add a contact mech to this purpose; the contactMechPurposeTypeId is required */ - public void addContactMech(String contactMechPurposeTypeId, String contactMechId) { + public void addContactMechId(String contactMechPurposeTypeId, String contactMechId) { if (contactMechPurposeTypeId == null) { throw new IllegalArgumentException("You must specify a contactMechPurposeTypeId to add a ContactMech"); } - contactMechIdsMap.put(contactMechPurposeTypeId, contactMechId); + UtilMisc.addToSetInMap(contactMechId, contactMechIdsMap, contactMechPurposeTypeId); } /** Get the contactMechId for this cart given the contactMechPurposeTypeId */ - public String getContactMech(String contactMechPurposeTypeId) { - return contactMechIdsMap.get(contactMechPurposeTypeId); + public String getContactMechId(String contactMechPurposeTypeId) { + return UtilValidate.isNotEmpty(getContactMechIds(contactMechPurposeTypeId)) + ? getContactMechIds(contactMechPurposeTypeId).get(0) + : null; } - /** Remove the contactMechId from this cart given the contactMechPurposeTypeId */ - public String removeContactMech(String contactMechPurposeTypeId) { - return contactMechIdsMap.remove(contactMechPurposeTypeId); + /** Get the contactMechIds list for this cart given the contactMechPurposeTypeId */ + public List getContactMechIds(String contactMechPurposeTypeId) { + Set contactMechIds = contactMechIdsMap.get(contactMechPurposeTypeId); + return contactMechIds != null + ? new ArrayList<>(contactMechIds) + : List.of(); + } + + /** Remove the contactMechIds list from this cart given the contactMechPurposeTypeId */ + public List removeContactMechId(String contactMechPurposeTypeId) { + Set contactMechIds = contactMechIdsMap.remove(contactMechPurposeTypeId); + return contactMechIds != null + ? new ArrayList<>(contactMechIds) + : List.of(); } /** * Gets order contact mech ids. * @return the order contact mech ids */ - public Map getOrderContactMechIds() { + public Map> getOrderContactMechIds() { return this.contactMechIdsMap; } @@ -4616,17 +4629,15 @@ public List makeAllOrderItemSurveyResponses() { public List makeAllOrderContactMechs() { List allOrderContactMechs = new LinkedList<>(); - Map contactMechIds = this.getOrderContactMechIds(); - + Map> contactMechIds = this.getOrderContactMechIds(); if (contactMechIds != null) { - for (Map.Entry entry : contactMechIds.entrySet()) { - GenericValue orderContactMech = getDelegator().makeValue("OrderContactMech"); - orderContactMech.set("contactMechPurposeTypeId", entry.getKey()); - orderContactMech.set("contactMechId", entry.getValue()); - allOrderContactMechs.add(orderContactMech); + for (Map.Entry> entry : contactMechIds.entrySet()) { + entry.getValue().forEach(contactMechId -> + allOrderContactMechs.add(getDelegator().makeValue("OrderContactMech", + Map.of("contactMechPurposeTypeId", entry.getKey(), + "contactMechId", contactMechId)))); } } - return allOrderContactMechs; } diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java index d25583c86b3..20f2dd8493b 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java @@ -329,7 +329,7 @@ public static Map loadCartFromOrder(DispatchContext dctx, Map orderItemShipGroupList = orh.getOrderItemShipGroups();