in ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayEvents.java [617:990]
public static String updateProductExportDetail(HttpServletRequest request, HttpServletResponse response) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
HttpSession session = request.getSession(true);
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
Map<String, Object> requestParams = UtilHttp.getParameterMap(request);
Locale locale = UtilHttp.getLocale(request);
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
Map<String, Object> attributeMapList = new HashMap<>();
String id = "";
if (UtilValidate.isNotEmpty(requestParams.get("listype"))) {
if ("auction".equals(requestParams.get("listype"))) {
id = "_1";
} else {
id = "_2";
}
}
String startPrice = "";
if (UtilValidate.isNotEmpty(requestParams.get("startPrice".concat(id)))) {
startPrice = (String) requestParams.get("startPrice".concat(id));
}
String buyItNowPrice = "";
if (UtilValidate.isNotEmpty(requestParams.get("buyItNowPrice".concat(id)))) {
buyItNowPrice = (String) requestParams.get("buyItNowPrice".concat(id));
}
String productId = null;
if (UtilValidate.isNotEmpty(requestParams.get("productId"))) {
productId = requestParams.get("productId").toString();
}
String itemPkCateId = (String) requestParams.get("primaryCateId");
String shippingService = (String) requestParams.get("ShippingService");
String productStoreId = (String) requestParams.get("productStoreId");
// initialize request parameter.
Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
List<String> nameSpecificList = new LinkedList<>();
List<String> valueSpecificList = new LinkedList<>();
String nameValueListType = null;
String valueListType = null;
int rowCount = UtilHttp.getMultiFormRowCount(paramMap);
if (rowCount > 1) {
for (int i = 0; i < rowCount; i++) {
String thisSuffix = UtilHttp.getMultiRowDelimiter() + i; // current suffix after each field id
// get the NameSpecifics
if (paramMap.containsKey("nameValueListType" + thisSuffix)) {
nameValueListType = (String) paramMap.remove("nameValueListType" + thisSuffix);
}
// get the ValueSpecifics
if (paramMap.containsKey("categorySpecifics" + thisSuffix)) {
valueListType = (String) paramMap.remove("categorySpecifics" + thisSuffix);
}
if ((UtilValidate.isNotEmpty(nameValueListType)) && (UtilValidate.isNotEmpty(valueListType))) {
nameSpecificList.add(nameValueListType);
valueSpecificList.add(valueListType);
}
}
}
try {
ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
Map<String, Object> addItemObject = getAddItemListingObject(request, apiContext);
List<Map<String, Object>> listAddItem = null;
if (UtilValidate.isNotEmpty(addItemObject.get("itemListing"))) {
listAddItem = UtilGenerics.checkList(addItemObject.get("itemListing"));
} else {
listAddItem = new LinkedList<>();
}
for (Map<String, Object> itemObj : listAddItem) {
AddItemCall addItemCall = (AddItemCall) itemObj.get("addItemCall");
ItemType item = addItemCall.getItem();
String SKU = item.getSKU();
if (UtilValidate.isNotEmpty(productId)) {
if (productId.equals(SKU)) {
attributeMapList.put("Title", item.getTitle());
attributeMapList.put("SKU", SKU);
attributeMapList.put("Currency", item.getCurrency().value());
attributeMapList.put("Description", item.getDescription());
attributeMapList.put("ApplicationData", item.getApplicationData());
attributeMapList.put("Country", item.getCountry().value());
attributeMapList.put("PictureURL", item.getPictureDetails().getPictureURL(0));
attributeMapList.put("Site", item.getSite().value());
attributeMapList.put("UseTaxTable", "false");
attributeMapList.put("BestOfferEnabled", "true");
attributeMapList.put("AutoPayEnabled", "true");
attributeMapList.put("CategoryID", item.getPrimaryCategory().getCategoryID());
attributeMapList.put("CategoryLevel", item.getPrimaryCategory().getCategoryLevel());
attributeMapList.put("CategoryName", item.getPrimaryCategory().getCategoryName());
attributeMapList.put("CategoryParentID", item.getPrimaryCategory().getCategoryParentID(0).toString());
attributeMapList.put("LeafCategory", "true");
attributeMapList.put("LSD", "true");
// set Item Specifics.
int itemSpecificsSize = nameSpecificList.size();
int valueSpecificsSize = valueSpecificList.size();
if ((itemSpecificsSize > 0) && (valueSpecificsSize > 0)) {
NameValueListArrayType nameValueListArray = new NameValueListArrayType();
NameValueListType[] nameValueListTypes = new NameValueListType[nameSpecificList.size()];
for (int i = 0; i < itemSpecificsSize; i++) {
String name = nameSpecificList.get(i);
String value = valueSpecificList.get(i);
String[] valueArray = new String[] {value };
// set Name value list type.
NameValueListType listType = new NameValueListType();
listType.setName(name);
listType.setValue(valueArray);
nameValueListTypes[i] = listType;
}
nameValueListArray.setNameValueList(nameValueListTypes);
item.setItemSpecifics(nameValueListArray);
}
item.setUseTaxTable(false);
item.setDispatchTimeMax(3);
ReturnPolicyType policy = new ReturnPolicyType();
policy.setReturnsAcceptedOption("ReturnsNotAccepted");
item.setReturnPolicy(policy);
attributeMapList.put("ReturnsAcceptedOption", "ReturnsNotAccepted");
String currencyId = "";
if (UtilValidate.isNotEmpty(requestParams.get("currencyId".concat(id)))) {
currencyId = (String) requestParams.get("currencyId".concat(id));
}
if (UtilValidate.isNotEmpty(requestParams.get("enabledTheme")) && "Y".equals(requestParams.get("enabledTheme"))) {
ListingDesignerType designer = new ListingDesignerType();
String layoutId = (String) requestParams.get("themeGroup");
String themeIdImage = (String) requestParams.get("theme");
String themeId = themeIdImage.substring(0, themeIdImage.indexOf(":"));
designer.setLayoutID(Integer.parseInt(layoutId));
designer.setThemeID(Integer.parseInt(themeId));
item.setListingDesigner(designer);
attributeMapList.put("LayoutID", item.getListingDesigner().getLayoutID());
attributeMapList.put("ThemeID", item.getListingDesigner().getThemeID());
}
if ("_1".equals(id)) {
item.setListingType(ListingTypeCodeType.CHINESE);
AmountType amtStart = new AmountType();
amtStart.setCurrencyID(CurrencyCodeType.valueOf(currencyId));
amtStart.setValue(Double.parseDouble(startPrice));
item.setStartPrice(amtStart);
AmountType amtBIN = new AmountType();
amtBIN.setCurrencyID(CurrencyCodeType.valueOf(currencyId));
amtBIN.setValue(Double.parseDouble(buyItNowPrice));
item.setBuyItNowPrice(amtBIN);
attributeMapList.put("BuyItNowPrice", item.getBuyItNowPrice().getValue());
if (UtilValidate.isNotEmpty(requestParams.get("reservePrice".concat(id)))) {
AmountType amtResv = new AmountType();
amtResv.setCurrencyID(CurrencyCodeType.valueOf(currencyId));
amtResv.setValue(Double.parseDouble(requestParams.get("reservePrice".concat(id)).toString()));
item.setReservePrice(amtResv);
attributeMapList.put("ReservePrice", item.getReservePrice().getValue());
}
} else if ("_2".equals(id)) {
item.setListingType(ListingTypeCodeType.FIXED_PRICE_ITEM);
AmountType amtBIN = new AmountType();
amtBIN.setCurrencyID(CurrencyCodeType.valueOf(currencyId));
amtBIN.setValue(Double.parseDouble(startPrice));
item.setStartPrice(amtBIN);
if (UtilValidate.isNotEmpty(requestParams.get("enableBestOffer".concat(id)))) {
item.setBestOfferEnabled(Boolean.valueOf(requestParams.get("enableBestOffer".concat(id)).toString()));
}
}
attributeMapList.put("ListingType", item.getListingType().value());
attributeMapList.put("StartPrice", item.getStartPrice().getValue());
EbayStoreHelper.mappedPaymentMethods(requestParams, itemPkCateId, addItemObject, item, attributeMapList);
ShippingDetailsType shippingDetail = new ShippingDetailsType();
ShippingServiceOptionsType[] shippingOptions = new ShippingServiceOptionsType[1];
ShippingServiceOptionsType shippingOption = new ShippingServiceOptionsType();
shippingOption.setShippingServicePriority(1);
shippingOption.setShippingService(shippingService);
AmountType amtServiceCost = new AmountType();
amtServiceCost.setValue(5.0);
amtServiceCost.setCurrencyID(CurrencyCodeType.USD);
shippingOption.setShippingServiceCost(amtServiceCost);
shippingOptions[0] = shippingOption;
shippingDetail.setShippingType(ShippingTypeCodeType.FLAT);
shippingDetail.setShippingServiceOptions(shippingOptions);
item.setShippingDetails(shippingDetail);
attributeMapList.put("ShippingService", shippingService);
attributeMapList.put("ShippingServiceCost", ""+ 5.0);
attributeMapList.put("ShippingServiceCostCurrency", "USD");
attributeMapList.put("ShippingServicePriority", "1");
attributeMapList.put("ShippingType", "Flat");
attributeMapList.put("ShippingServiceAdditionalCost", amtServiceCost.getValue());
EbayStoreHelper.mappedShippingLocations(requestParams, item, apiContext, request, attributeMapList);
if (UtilValidate.isNotEmpty(requestParams.get("vatPercent".concat(id)))) {
VATDetailsType vat = new VATDetailsType();
vat.setVATPercent(new Float(requestParams.get("vatPercent".concat(id)).toString()));
item.setVATDetails(vat);
attributeMapList.put("VATPercent", vat);
}
if (UtilValidate.isNotEmpty(requestParams.get("location"))) {
item.setLocation(requestParams.get("location").toString());
attributeMapList.put("Location", requestParams.get("location").toString());
}
if (UtilValidate.isNotEmpty(requestParams.get("quantity".concat(id)))) {
item.setQuantity(Integer.parseInt(requestParams.get("quantity".concat(id)).toString()));
attributeMapList.put("Quantity", requestParams.get("quantity".concat(id)).toString());
}
if (UtilValidate.isNotEmpty(requestParams.get("duration".concat(id)))) {
item.setListingDuration(requestParams.get("duration".concat(id)).toString());
attributeMapList.put("ListingDuration", requestParams.get("duration".concat(id)).toString());
}
if (UtilValidate.isNotEmpty(requestParams.get("lotsize".concat(id)))) {
item.setLotSize(Integer.parseInt(requestParams.get("lotsize".concat(id)).toString()));
attributeMapList.put("LotSize", requestParams.get("lotsize".concat(id)).toString());
}
if (UtilValidate.isNotEmpty(requestParams.get("postalCode".concat(id)))) {
item.setPostalCode(requestParams.get("postalCode".concat(id)).toString());
attributeMapList.put("PostalCode", requestParams.get("postalCode".concat(id)).toString());
}
StorefrontType storeFront = new StorefrontType();
if (UtilValidate.isNotEmpty(requestParams.get("ebayStore1Category"))) {
String ebayStore1Category = (String) requestParams.get("ebayStore1Category");
if (ebayStore1Category.contains("false")) {
request.setAttribute("_ERROR_MESSAGE_", "Please select ebay store category with low level of categories.");
return "error";
} else {
if (ebayStore1Category.contains("true")) ebayStore1Category = ebayStore1Category.substring(0, ebayStore1Category.indexOf(":"));
}
storeFront.setStoreCategoryID(new Long(ebayStore1Category));
attributeMapList.put("StoreCategoryID", ebayStore1Category);
}
if (UtilValidate.isNotEmpty(requestParams.get("ebayStore2Category"))) {
String ebayStore2Category = (String) requestParams.get("ebayStore2Category");
if (ebayStore2Category.contains("false")) {
request.setAttribute("_ERROR_MESSAGE_", "Please select ebay store category with low level of categories.");
return "error";
} else {
if (ebayStore2Category.contains("true")) ebayStore2Category = ebayStore2Category.substring(0, ebayStore2Category.indexOf(":"));
}
storeFront.setStoreCategory2ID(new Long(ebayStore2Category));
attributeMapList.put("StoreCategory2ID", ebayStore2Category);
}
if (UtilValidate.isNotEmpty(requestParams.get("ebayStore1Category")) || UtilValidate.isNotEmpty(requestParams.get("ebayStore2Category"))) {
item.setStorefront(storeFront);
}
//TODO: set value of country and currency on the basis of request param values
item.setCountry(CountryCodeType.US);
attributeMapList.put("Country", "US");
item.setCurrency(CurrencyCodeType.USD);
attributeMapList.put("Currency", "USD");
if (UtilValidate.isNotEmpty(requestParams.get("requireEbayInventory")) && "Y".equals(requestParams.get("requireEbayInventory").toString())) {
GenericValue ebayProductStore = EntityQuery.use(delegator).from("EbayProductStoreInventory").where("productStoreId", productStoreId, "productId", productId).filterByDate().queryFirst();
if (ebayProductStore != null) {
String facilityId = ebayProductStore.getString("facilityId");
BigDecimal atp = ebayProductStore.getBigDecimal("availableToPromiseListing");
int intAtp = atp.intValue();
if (("" != facilityId) && (intAtp != 0)) {
int newAtp = intAtp - 1;
Map<String, Object> inMap = new HashMap<>();
inMap.put("productStoreId", productStoreId);
inMap.put("facilityId", facilityId);
inMap.put("productId", productId);
inMap.put("availableToPromiseListing", new BigDecimal(newAtp));
inMap.put("userLogin", userLogin);
try {
Map<String, Object> resultMap = dispatcher.runSync("updateEbayProductStoreInventory", inMap);
if (ServiceUtil.isError(resultMap)) {
String errorMessage = ServiceUtil.getErrorMessage(resultMap);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, MODULE);
return "error";
}
} catch (GenericServiceException ex) {
Debug.logError(ex.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(ex.getMessage()));
return "error";
}
itemObj.put("requireEbayInventory", "Y");
}
}
}
addItemCall.setItem(item);
// create/update EbayProductListing entity
Map<String, Object> prodMap = new HashMap<>();
prodMap.put("productStoreId", productStoreId);
prodMap.put("productId", productId);
prodMap.put("userLogin", userLogin);
if (UtilValidate.isNotEmpty(requestParams.get("isAutoRelist"))) {
prodMap.put("autoRelisting", "Y");
itemObj.put("isAutoRelist", "Y");
}
try {
GenericValue storeRole = EntityQuery.use(delegator).from("ProductStoreRole").where("productStoreId", productStoreId, "roleTypeId", "EBAY_ACCOUNT").queryFirst();
if (storeRole != null) {
GenericValue eBayUserLogin = EntityQuery.use(delegator).from("UserLogin")
.where("partyId", storeRole.get("partyId"))
.queryFirst();
if (eBayUserLogin != null) {
prodMap.put("userLoginId", eBayUserLogin.get("userLoginId").toString());
}
}
} catch (GenericEntityException ex) {
Debug.logError(ex.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(ex.getMessage()));
return "error";
}
String productListingId = null;
if (UtilValidate.isEmpty(itemObj.get("productListingId"))) {
try {
prodMap.put("statusId", "ITEM_CREATED");
Map<String, Object> result = dispatcher.runSync("createEbayProductListing", prodMap);
if (ServiceUtil.isError(result)) {
String errorMessage = ServiceUtil.getErrorMessage(result);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, MODULE);
return "error";
}
productListingId = result.get("productListingId").toString();
itemObj.put("productListingId", productListingId);
itemObj.put("isSaved", "Y");
} catch (GenericServiceException ex) {
Debug.logError(ex.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(ex.getMessage()));
return "error";
}
} else {
productListingId = itemObj.get("productListingId").toString();
prodMap.put("productListingId", productListingId);
try {
Map<String, Object> result = dispatcher.runSync("updateEbayProductListing", prodMap);
if (ServiceUtil.isError(result)) {
String errorMessage = ServiceUtil.getErrorMessage(result);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, MODULE);
return "error";
}
} catch (GenericServiceException ex) {
Debug.logError(ex.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(ex.getMessage()));
return "error";
}
}
// create/update EbayProductListingAttribute
if (UtilValidate.isNotEmpty(productListingId)) {
attributeMapList.put("productListingId", productListingId);
Map<String, Object> ebayProdAttrMap = new HashMap<>();
ebayProdAttrMap.put("productListingId", productListingId);
ebayProdAttrMap.put("userLogin", userLogin);
ebayProdAttrMap.put("attributeMapList", attributeMapList);
try {
Map<String, Object> result = dispatcher.runSync("setEbayProductListingAttribute", ebayProdAttrMap);
if (ServiceUtil.isError(result)) {
String errorMessage = ServiceUtil.getErrorMessage(result);
request.setAttribute("_ERROR_MESSAGE_", errorMessage);
Debug.logError(errorMessage, MODULE);
return "error";
}
} catch (GenericServiceException ex) {
Debug.logError(ex.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(ex.getMessage()));
return "error";
}
}
}
}
}
request.setAttribute("productStoreId", requestParams.get("productStoreId"));
} catch (Exception e) {
Debug.logError(e.getMessage(), MODULE);
request.setAttribute("_ERROR_MESSAGE_", "Exception: ".concat(e.getMessage()));
return "error";
}
return "success";
}