in ebay/src/main/java/org/apache/ofbiz/ebay/ProductsExportToEbay.java [181:347]
public static Map<String, Object> buildDataItemsXml(DispatchContext dctx, Map<String, Object> context, StringBuffer dataItemsXml, String token,
GenericValue prod) {
Locale locale = (Locale) context.get("locale");
try {
Delegator delegator = dctx.getDelegator();
String webSiteUrl = (String) context.get("webSiteUrl");
UtilCodec.SimpleEncoder encoder = UtilCodec.getEncoder("xml");
// Get the list of products to be exported to eBay
try {
Document itemDocument = UtilXml.makeEmptyXmlDocument("AddItemRequest");
Element itemRequestElem = itemDocument.getDocumentElement();
itemRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
appendRequesterCredentials(itemRequestElem, itemDocument, token);
String title = prod.getString("internalName");
String qnt = (String) context.get("quantity");
if (UtilValidate.isEmpty(qnt)) {
qnt = "1";
}
String productDescription = "";
String description = prod.getString("description");
String longDescription = prod.getString("longDescription");
if (UtilValidate.isNotEmpty(description)) {
productDescription = description;
} else if (UtilValidate.isNotEmpty(longDescription)) {
productDescription = longDescription;
} else if (UtilValidate.isNotEmpty(prod.getString("productName"))) {
productDescription = prod.getString("productName");
}
String startPrice = (String) context.get("startPrice");
String startPriceCurrencyUomId = null;
if (UtilValidate.isEmpty(startPrice)) {
GenericValue startPriceValue = EntityUtil.getFirst(EntityUtil.filterByDate(prod.getRelated("ProductPrice", UtilMisc.toMap(
"productPricePurposeId", "EBAY", "productPriceTypeId", "MINIMUM_PRICE"), null, false)));
if (UtilValidate.isNotEmpty(startPriceValue)) {
startPrice = startPriceValue.getString("price");
startPriceCurrencyUomId = startPriceValue.getString("currencyUomId");
}
}
// Buy it now is the optional value for a product that you send to eBay. Once this value is entered by user - this option allow
// user to win auction immediately.
String buyItNowPrice = (String) context.get("buyItNowPrice");
String buyItNowCurrencyUomId = null;
if (UtilValidate.isEmpty(buyItNowPrice)) {
GenericValue buyItNowPriceValue = EntityUtil.getFirst(EntityUtil.filterByDate(prod.getRelated("ProductPrice", UtilMisc.toMap(
"productPricePurposeId", "EBAY", "productPriceTypeId", "MAXIMUM_PRICE"), null, false)));
if (UtilValidate.isNotEmpty(buyItNowPriceValue)) {
buyItNowPrice = buyItNowPriceValue.getString("price");
buyItNowCurrencyUomId = buyItNowPriceValue.getString("currencyUomId");
}
}
Element itemElem = UtilXml.addChildElement(itemRequestElem, "Item", itemDocument);
UtilXml.addChildElementValue(itemElem, "Country", (String) context.get("country"), itemDocument);
String location = (String) context.get("location");
if (UtilValidate.isNotEmpty(location)) {
UtilXml.addChildElementValue(itemElem, "Location", location, itemDocument);
}
UtilXml.addChildElementValue(itemElem, "ApplicationData", prod.getString("productId"), itemDocument);
UtilXml.addChildElementValue(itemElem, "SKU", prod.getString("productId"), itemDocument);
UtilXml.addChildElementValue(itemElem, "Title", title, itemDocument);
UtilXml.addChildElementValue(itemElem, "ListingDuration", (String) context.get("listingDuration"), itemDocument);
UtilXml.addChildElementValue(itemElem, "Quantity", qnt, itemDocument);
String listingFormat = "";
if (UtilValidate.isNotEmpty(context.get("listingFormat"))) {
listingFormat = (String) context.get("listingFormat");
UtilXml.addChildElementValue(itemElem, "ListingType", listingFormat, itemDocument);
}
if ("FixedPriceItem".equals(listingFormat)) {
Element startPriceElem = UtilXml.addChildElementValue(itemElem, "StartPrice", startPrice, itemDocument);
if (UtilValidate.isEmpty(startPriceCurrencyUomId)) {
startPriceCurrencyUomId = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
startPriceElem.setAttribute("currencyID", startPriceCurrencyUomId);
} else {
Element startPriceElem = UtilXml.addChildElementValue(itemElem, "StartPrice", startPrice, itemDocument);
if (UtilValidate.isEmpty(startPriceCurrencyUomId)) {
startPriceCurrencyUomId = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
startPriceElem.setAttribute("currencyID", startPriceCurrencyUomId);
if (UtilValidate.isNotEmpty(buyItNowPrice)) {
Element buyNowPriceElem = UtilXml.addChildElementValue(itemElem, "BuyItNowPrice", buyItNowPrice, itemDocument);
if (UtilValidate.isEmpty(buyItNowCurrencyUomId)) {
buyItNowCurrencyUomId = EntityUtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD", delegator);
}
buyNowPriceElem.setAttribute("currencyID", buyItNowCurrencyUomId);
}
}
ProductContentWrapper pcw = new ProductContentWrapper(dctx.getDispatcher(), prod, locale, EntityUtilProperties.getPropertyValue(
"content", "defaultMimeType", "text/html; charset=utf-8", delegator));
StringUtil.StringWrapper ebayDescription = pcw.get("EBAY_DESCRIPTION", "html");
if (UtilValidate.isNotEmpty(ebayDescription.toString())) {
UtilXml.addChildElementCDATAValue(itemElem, "Description", ebayDescription.toString(), itemDocument);
} else {
UtilXml.addChildElementValue(itemElem, "Description", encoder.encode(productDescription), itemDocument);
}
String smallImage = prod.getString("smallImageUrl");
String mediumImage = prod.getString("mediumImageUrl");
String largeImage = prod.getString("largeImageUrl");
String ebayImage = null;
if (UtilValidate.isNotEmpty(largeImage)) {
ebayImage = largeImage;
} else if (UtilValidate.isNotEmpty(mediumImage)) {
ebayImage = mediumImage;
} else if (UtilValidate.isNotEmpty(smallImage)) {
ebayImage = smallImage;
}
if (UtilValidate.isNotEmpty(ebayImage)) {
Element pictureDetails = UtilXml.addChildElement(itemElem, "PictureDetails", itemDocument);
UtilXml.addChildElementValue(pictureDetails, "PictureURL", webSiteUrl + ebayImage, itemDocument);
}
setPaymentMethodAccepted(itemDocument, itemElem, context);
setMiscDetails(itemDocument, itemElem, context, delegator);
String categoryCode = (String) context.get("ebayCategory");
String primaryCategoryId = "";
if (categoryCode != null) {
if (categoryCode.indexOf("_") != -1) {
String[] params = categoryCode.split("_");
if (UtilValidate.isEmpty(params) || params[1].isEmpty()) {
ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "productsExportToEbay"
+ ".parametersNotCorrectInGetEbayCategories", locale));
} else {
primaryCategoryId = params[1];
}
} else {
primaryCategoryId = categoryCode;
}
} else {
GenericValue productCategoryValue = EntityQuery.use(delegator).from("ProductCategoryAndMember")
.where("productCategoryTypeId", "EBAY_CATEGORY", "productId", prod.getString("productId"))
.filterByDate()
.queryFirst();
if (UtilValidate.isNotEmpty(productCategoryValue)) {
primaryCategoryId = productCategoryValue.getString("categoryName");
}
}
Element primaryCatElem = UtilXml.addChildElement(itemElem, "PrimaryCategory", itemDocument);
UtilXml.addChildElementValue(primaryCatElem, "CategoryID", primaryCategoryId, itemDocument);
UtilXml.addChildElementValue(itemElem, "ConditionID", "1000", itemDocument);
Element itemSpecificsElem = UtilXml.addChildElement(itemElem, "ItemSpecifics", itemDocument);
Element nameValueListElem = UtilXml.addChildElement(itemSpecificsElem, "NameValueList", itemDocument);
UtilXml.addChildElementValue(nameValueListElem, "Name", "Condition", itemDocument);
UtilXml.addChildElementValue(nameValueListElem, "Value", "New: With Tags", itemDocument);
//Debug.logInfo("The generated string is ======= " + UtilXml.writeXmlDocument(itemDocument), MODULE);
dataItemsXml.append(UtilXml.writeXmlDocument(itemDocument));
} catch (Exception e) {
Debug.logError("Exception during building data items to eBay: " + e.getMessage(), MODULE);
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay",
locale));
}
} catch (Exception e) {
Debug.logError("Exception during building data items to eBay: " + e.getMessage(), MODULE);
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay",
locale));
}
return ServiceUtil.returnSuccess();
}