diff --git a/applications/order/config/OrderUiLabels.properties b/applications/order/config/OrderUiLabels.properties index 4ccee21ef8..bf807b1f71 100644 --- a/applications/order/config/OrderUiLabels.properties +++ b/applications/order/config/OrderUiLabels.properties @@ -998,6 +998,7 @@ ordersImportFromEbay.exceptionInSetEbayOrderToComplete=Exception in setEbayOrder ordersImportFromEbay.externalIdAlreadyExist=ExternalId Already Exists ordersImportFromEbay.externalIdNotAvailable=ExternalId Not Available ordersImportFromEbay.noOrdersFound=No Orders Found +ordersImportFromEbay.orderIdOrExternalIdAreMandatory=OrderId Or ExternalId Are Mandatory ordersImportFromEbay.paymentIsStillNotReceived=Before Import the order from eBay you have to receive the payment from the buyer ordersImportFromEbay.productIdNotAvailable=ProductId Not Available ordersImportFromEbay.productStoreIdIsMandatory=ProductStoreId Is Mandatory diff --git a/applications/order/config/OrderUiLabels_it.properties b/applications/order/config/OrderUiLabels_it.properties index ef2f5e03c4..b152c5a0cc 100644 --- a/applications/order/config/OrderUiLabels_it.properties +++ b/applications/order/config/OrderUiLabels_it.properties @@ -862,6 +862,7 @@ ordersImportFromEbay.exceptionInSetEbayOrderToComplete=Eccezione in setEbayOrder ordersImportFromEbay.externalIdAlreadyExist=Numero Ordine Esterno Gi\u00e0 Esistente ordersImportFromEbay.externalIdNotAvailable=Numero Ordine Esterno Non Disponibile ordersImportFromEbay.noOrdersFound=Nessun Ordine Trovato +ordersImportFromEbay.orderIdOrExternalIdAreMandatory=OrderId O ExternalId Sono Obbligatori ordersImportFromEbay.paymentIsStillNotReceived=Prima di Importare l'ordine da eBay tu devi ricevere il pagamento dal compratore ordersImportFromEbay.productIdNotAvailable=Codice Prodotto Non Disponibile ordersImportFromEbay.productStoreIdIsMandatory=Codice Negozio \u00e8 Obbligatorio diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index e0725b0c5d..15bfd1be64 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -773,9 +773,9 @@ under the License. Import Order from eBay - + @@ -798,7 +798,9 @@ under the License. Complete Order to eBay - + + + diff --git a/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java b/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java index b7f92a9cfa..a986ae402e 100644 --- a/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java +++ b/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java @@ -49,6 +49,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.order.shoppingcart.CheckOutHelper; import org.ofbiz.order.shoppingcart.ShoppingCart; +import org.ofbiz.party.contact.ContactMechWorker; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -120,32 +121,30 @@ public class ImportOrdersFromEbay { Map order = FastMap.newInstance(); Map result = FastMap.newInstance(); try { - String orderSelected = (String) context.get("orderSelected"); - if (UtilValidate.isNotEmpty(orderSelected) && "Y".equals(orderSelected)) { - order.put("productStoreId", (String) context.get("productStoreId")); - order.put("userLogin", (GenericValue) context.get("userLogin")); - order.put("externalId", (String) context.get("externalId")); - order.put("createdDate", (String) context.get("createdDate")); - order.put("productId", (String) context.get("productId")); - order.put("quantityPurchased", (String) context.get("quantityPurchased")); - order.put("transactionPrice", (String) context.get("transactionPrice")); - order.put("shippingServiceCost", (String) context.get("shippingServiceCost")); - order.put("shippingTotalAdditionalCost", (String) context.get("shippingTotalAdditionalCost")); - order.put("amountPaid", (String) context.get("amountPaid")); - order.put("paidTime", (String) context.get("paidTime")); - order.put("shippedTime", (String) context.get("shippedTime")); - - order.put("buyerName", (String) context.get("buyerName")); - order.put("emailBuyer", (String) context.get("emailBuyer")); - order.put("shippingAddressPhone", (String) context.get("shippingAddressPhone")); - order.put("shippingAddressStreet1", (String) context.get("shippingAddressStreet1")); - order.put("shippingAddressPostalCode", (String) context.get("shippingAddressPostalCode")); - order.put("shippingAddressCountry", (String) context.get("shippingAddressCountry")); - order.put("shippingAddressStateOrProvince", (String) context.get("shippingAddressStateOrProvince")); - order.put("shippingAddressCityName", (String) context.get("shippingAddressCityName")); - - result = createShoppingCart(delegator, dispatcher, locale, order, true); - } + order.put("productStoreId", (String) context.get("productStoreId")); + order.put("userLogin", (GenericValue) context.get("userLogin")); + order.put("externalId", (String) context.get("externalId")); + order.put("transactionId", (String) context.get("transactionId")); + order.put("createdDate", (String) context.get("createdDate")); + order.put("productId", (String) context.get("productId")); + order.put("quantityPurchased", (String) context.get("quantityPurchased")); + order.put("transactionPrice", (String) context.get("transactionPrice")); + order.put("shippingServiceCost", (String) context.get("shippingServiceCost")); + order.put("shippingTotalAdditionalCost", (String) context.get("shippingTotalAdditionalCost")); + order.put("amountPaid", (String) context.get("amountPaid")); + order.put("paidTime", (String) context.get("paidTime")); + order.put("shippedTime", (String) context.get("shippedTime")); + + order.put("buyerName", (String) context.get("buyerName")); + order.put("emailBuyer", (String) context.get("emailBuyer")); + order.put("shippingAddressPhone", (String) context.get("shippingAddressPhone")); + order.put("shippingAddressStreet1", (String) context.get("shippingAddressStreet1")); + order.put("shippingAddressPostalCode", (String) context.get("shippingAddressPostalCode")); + order.put("shippingAddressCountry", (String) context.get("shippingAddressCountry")); + order.put("shippingAddressStateOrProvince", (String) context.get("shippingAddressStateOrProvince")); + order.put("shippingAddressCityName", (String) context.get("shippingAddressCityName")); + + result = createShoppingCart(delegator, dispatcher, locale, order, true); } catch (Exception e) { Debug.logError("Exception in importOrderFromEbay " + e, module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.exceptionInImportOrderFromEbay", locale)); @@ -158,22 +157,35 @@ public class ImportOrdersFromEbay { GenericDelegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); String orderId = (String) context.get("orderId"); + String externalId = (String) context.get("externalId"); + String transactionId = (String) context.get("transactionId"); Map result = FastMap.newInstance(); try { - // Get the order header and verify if this order has been imported - // from eBay (i.e. sales channel = EBAY_CHANNEL and externalId is set) - GenericValue orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId)); - if (orderHeader == null) { - Debug.logError("Cannot find order with orderId [" + orderId + "]", module); - return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.errorRetrievingOrderFromOrderId", locale)); + if (orderId == null && externalId == null) { + Debug.logError("orderId or externalId must be filled", module); + return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.orderIdOrExternalIdAreMandatory", locale)); } - // get externalId from orderId - String externalId = (String)orderHeader.get("externalId"); - if (!"EBAY_SALES_CHANNEL".equals(orderHeader.getString("salesChannelEnumId")) || orderHeader.getString("externalId") == null) { - // This order was not imported from eBay: there is nothing to do. - return ServiceUtil.returnSuccess(); + + GenericValue orderHeader = null; + if (UtilValidate.isNotEmpty(orderId)) { + // Get the order header and verify if this order has been imported + // from eBay (i.e. sales channel = EBAY_CHANNEL and externalId is set) + orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId)); + if (orderHeader == null) { + Debug.logError("Cannot find order with orderId [" + orderId + "]", module); + return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.errorRetrievingOrderFromOrderId", locale)); + } + + if (!"EBAY_SALES_CHANNEL".equals(orderHeader.getString("salesChannelEnumId")) || orderHeader.getString("externalId") == null) { + // This order was not imported from eBay: there is nothing to do. + return ServiceUtil.returnSuccess(); + } + + // get externalId and transactionId from OrderHeader + externalId = (String)orderHeader.get("externalId"); + transactionId = (String)orderHeader.get("transactionId"); } - + String configString = "productsExport.properties"; // get the Developer Key @@ -199,7 +211,7 @@ public class ImportOrdersFromEbay { StringBuffer completeSaleXml = new StringBuffer(); - if (!ServiceUtil.isFailure(buildCompleteSaleRequest(delegator, locale, externalId, context, completeSaleXml, token))) { + if (!ServiceUtil.isFailure(buildCompleteSaleRequest(delegator, locale, externalId, transactionId, context, completeSaleXml, token))) { result = postItem(xmlGatewayUri, completeSaleXml, devID, appID, certID, "CompleteSale", compatibilityLevel, siteID); String successMessage = (String)result.get("successMessage"); if (successMessage != null) { @@ -346,19 +358,20 @@ public class ImportOrdersFromEbay { return ServiceUtil.returnSuccess(); } - public static Map buildCompleteSaleRequest(GenericDelegator delegator, Locale locale, String externalId, Map context, StringBuffer dataItemsXml, String token) { + public static Map buildCompleteSaleRequest(GenericDelegator delegator, Locale locale, String itemId, String transactionId, Map context, StringBuffer dataItemsXml, String token) { String paid = (String)context.get("paid"); String shipped = (String)context.get("shipped"); try { - Map result = buildItemAndTransactionIdFromExternalId(externalId); - String itemId = (String)result.get("itemId"); - String transactionId = (String)result.get("transactionId"); - if (itemId == null || transactionId == null) { Debug.logError("Cannot be retrieve itemId and transactionId from externalId", module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.errorDuringBuildItemAndTransactionIdFromExternalId", locale)); - } + } + + // the CompleteSale api wants only the first 12 characters of the ItemId for TransactionId = 0 + if ("0".equals(transactionId)) { + itemId = itemId.substring(0, 11); + } Document transDoc = UtilXml.makeEmptyXmlDocument("CompleteSaleRequest"); Element transElem = transDoc.getDocumentElement(); @@ -368,12 +381,17 @@ public class ImportOrdersFromEbay { UtilXml.addChildElementValue(transElem, "ItemID", itemId, transDoc); + // default shipped = Y (call from eca during order completed) + if (paid == null && shipped == null) { + shipped = "Y"; + } + // Set item id to paid or not paid if (UtilValidate.isNotEmpty(paid)) { if ("Y".equals(paid)) { - paid = "1"; + paid = "true"; } else { - paid = "0"; + paid = "false"; } UtilXml.addChildElementValue(transElem, "Paid", paid, transDoc); } @@ -381,9 +399,9 @@ public class ImportOrdersFromEbay { // Set item id to shipped or not shipped if (UtilValidate.isNotEmpty(shipped)) { if ("Y".equals(shipped)) { - shipped = "1"; + shipped = "true"; } else { - shipped = "0"; + shipped = "false"; } UtilXml.addChildElementValue(transElem, "Shipped", shipped, transDoc); } @@ -465,7 +483,7 @@ public class ImportOrdersFromEbay { while (buyerElemIter.hasNext()) { Element buyerElement = (Element)buyerElemIter.next(); order.put("emailBuyer", UtilXml.childElementValue(buyerElement, "Email", "")); - order.put("eiasTokenBuyer", UtilXml.childElementValue(buyerElement, "EAISToken", "")); + order.put("eiasTokenBuyer", UtilXml.childElementValue(buyerElement, "EIASToken", "")); order.put("ebayUserIdBuyer", UtilXml.childElementValue(buyerElement, "UserID", "")); // retrieve buyer information @@ -573,11 +591,11 @@ public class ImportOrdersFromEbay { // retrieve transactionId String transactionId = UtilXml.childElementValue(transactionElement, "TransactionID", ""); - // build the externalId - String externalId = buildExternalId(itemId, transactionId); - order.put("externalId", externalId); + // set the externalId and transactionId + order.put("externalId", itemId); + order.put("transactionId", transactionId); - GenericValue orderExist = externalOrderExists(delegator, externalId); + GenericValue orderExist = externalOrderExists(delegator, itemId, transactionId); if (orderExist != null) { order.put("orderId", (String)orderExist.get("orderId")); } else { @@ -682,14 +700,18 @@ public class ImportOrdersFromEbay { // create a new shopping cart ShoppingCart cart = new ShoppingCart(delegator, productStoreId, locale, defaultCurrencyUomId); - // set the external id with the eBay Item Id + eBay Transacation Id + // set the external id with the eBay Item Id String externalId = (String) parameters.get("externalId"); + // set the transaction id with the eBay Transacation Id + String transactionId = (String) parameters.get("transactionId"); + if (UtilValidate.isNotEmpty(externalId)) { - if (externalOrderExists(delegator, externalId) != null && create) { + if (externalOrderExists(delegator, externalId, transactionId) != null && create) { return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.externalIdAlreadyExist", locale)); } cart.setExternalId(externalId); + cart.setTransactionId(transactionId); } else { return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.externalIdNotAvailable", locale)); } @@ -779,22 +801,30 @@ public class ImportOrdersFromEbay { GenericValue partyAttribute = EntityUtil.getFirst(delegator.findByAnd("PartyAttribute", UtilMisc.toMap("attrValue", parameters.get("eiasTokenBuyer")))); if (UtilValidate.isNotEmpty(partyAttribute)) { partyId = (String) partyAttribute.get("partyId"); + GenericValue contactMech = EntityUtil.getFirst(delegator.findByAnd("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechPurposeTypeId","SHIPPING_LOCATION"))); + if (contactMech != null) { + contactMechId = contactMech.getString("contactMechId"); + } // TODO: check for current contact information here // and, if needed, 'update' the existing ones - } else { - partyId = createCustomerParty(dispatcher, (String) parameters.get("buyerName"), userLogin); - if (UtilValidate.isNotEmpty(partyId)) { - contactMechId = createAddress(dispatcher, partyId, userLogin, "SHIPPING_LOCATION", parameters); - createPartyPhone(dispatcher, partyId, (String) parameters.get("shippingAddressPhone"), userLogin); - createEbayCustomer(dispatcher, partyId, (String) parameters.get("ebayUserIdBuyer"), (String) parameters.get("eiasTokenBuyer"), userLogin); - String emailBuyer = (String) parameters.get("emailBuyer"); - if (!(emailBuyer.equals("") || emailBuyer.equalsIgnoreCase("Invalid Request"))) { - createPartyEmail(dispatcher, partyId, emailBuyer, userLogin); - } - } else { + } + + if (UtilValidate.isEmpty(partyId)) { + partyId = createCustomerParty(dispatcher, (String) parameters.get("buyerName"), userLogin); + if (UtilValidate.isEmpty(partyId)) { partyId = "admin"; - } - } + } + } + + if (UtilValidate.isEmpty(contactMechId)) { + contactMechId = createAddress(dispatcher, partyId, userLogin, "SHIPPING_LOCATION", parameters); + createPartyPhone(dispatcher, partyId, (String) parameters.get("shippingAddressPhone"), userLogin); + createEbayCustomer(dispatcher, partyId, (String) parameters.get("ebayUserIdBuyer"), (String) parameters.get("eiasTokenBuyer"), userLogin); + String emailBuyer = (String) parameters.get("emailBuyer"); + if (!(emailBuyer.equals("") || emailBuyer.equalsIgnoreCase("Invalid Request"))) { + createPartyEmail(dispatcher, partyId, emailBuyer, userLogin); + } + } cart.setBillToCustomerPartyId(partyId); cart.setPlacingCustomerPartyId(partyId); @@ -1020,7 +1050,7 @@ public class ImportOrdersFromEbay { context.put("contactMechTypeId", "EMAIL_ADDRESS"); summaryResult = dispatcher.runSync("createEmailAddress", context); emailContactMechId = (String) summaryResult.get("contactMechId"); - + context.clear(); context.put("partyId", partyId); context.put("contactMechId", emailContactMechId); @@ -1089,45 +1119,16 @@ public class ImportOrdersFromEbay { return result; } - private static GenericValue externalOrderExists(GenericDelegator delegator, String externalId) throws GenericEntityException { - Debug.logInfo("Checking for existing externalOrderId: " + externalId, module); + private static GenericValue externalOrderExists(GenericDelegator delegator, String externalId, String transactionId) throws GenericEntityException { + Debug.logInfo("Checking for existing externalId: " + externalId +" and transactionId: " + transactionId, module); GenericValue orderHeader = null; - List entities = delegator.findByAnd("OrderHeader", UtilMisc.toMap("externalId", externalId)); + List entities = delegator.findByAnd("OrderHeader", UtilMisc.toMap("externalId", externalId, "transactionId", transactionId)); if (entities != null && entities.size() > 0) { orderHeader = EntityUtil.getFirst(entities); } return orderHeader; } - private static String buildExternalId(String itemId, String transactionId) { - StringBuffer str = new StringBuffer(); - if (itemId != null) { - str.append(itemId); - } - - if (transactionId != null) { - if (!("0".equals(transactionId))) { - str.append("_"); - } - str.append(transactionId); - } - return str.toString(); - } - - private static Map buildItemAndTransactionIdFromExternalId(String externalId) { - Map items = FastMap.newInstance(); - String ext[] = externalId.split("_"); - - if (ext.length == 2) { - items.put("itemId", ext[0]); - items.put("transactionId", ext[1]); - } else { - items.put("itemId", externalId); - items.put("transactionId", "0"); - } - return items; - } - private static String convertDate(String dateIn, String fromDateFormat, String toDateFormat) { String dateOut; try { diff --git a/applications/order/webapp/ordermgr/entry/checkinits.ftl b/applications/order/webapp/ordermgr/entry/checkinits.ftl index 02da2397e2..faac57f401 100644 --- a/applications/order/webapp/ordermgr/entry/checkinits.ftl +++ b/applications/order/webapp/ordermgr/entry/checkinits.ftl @@ -39,8 +39,9 @@ under the License.
  • ${uiLabelMap.OrderSalesOrder}<#if shoppingCart?exists> ${uiLabelMap.OrderInProgress}
  • ${uiLabelMap.CommonContinue}
  • ${uiLabelMap.PartyFindParty}
  • +
  • ${uiLabelMap.OrderImportOrdersFromEbay}
  • -
    +
    @@ -137,7 +138,7 @@ under the License.
  • ${uiLabelMap.CommonContinue}
  • ${uiLabelMap.PartyFindParty}
  • -
    +
    diff --git a/applications/order/webapp/ordermgr/order/OrderForms.xml b/applications/order/webapp/ordermgr/order/OrderForms.xml index 13a985e824..8914869a6f 100644 --- a/applications/order/webapp/ordermgr/order/OrderForms.xml +++ b/applications/order/webapp/ordermgr/order/OrderForms.xml @@ -136,6 +136,7 @@ under the License. +