PageRenderTime 83ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java

https://bitbucket.org/sudhirk76/ogb12
Java | 2941 lines | 2697 code | 183 blank | 61 comment | 514 complexity | ad7f06de334910d29e0260eb8f271d85 MD5 | raw file
Possible License(s): CPL-1.0, Apache-2.0, GPL-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.ofbiz.ebaystore;
  20. import java.io.BufferedReader;
  21. import java.io.File;
  22. import java.io.FileOutputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.InputStreamReader;
  26. import java.io.OutputStream;
  27. import java.math.BigDecimal;
  28. import java.net.HttpURLConnection;
  29. import java.net.URL;
  30. import java.nio.ByteBuffer;
  31. import java.nio.channels.FileChannel;
  32. import java.util.Calendar;
  33. import java.util.Date;
  34. import java.util.Iterator;
  35. import java.util.List;
  36. import java.util.Locale;
  37. import java.util.Map;
  38. import javax.swing.table.AbstractTableModel;
  39. import javax.swing.table.TableModel;
  40. import javolution.util.FastList;
  41. import javolution.util.FastMap;
  42. import org.ofbiz.base.util.Debug;
  43. import org.ofbiz.base.util.UtilDateTime;
  44. import org.ofbiz.base.util.UtilGenerics;
  45. import org.ofbiz.base.util.UtilMisc;
  46. import org.ofbiz.base.util.UtilProperties;
  47. import org.ofbiz.base.util.UtilValidate;
  48. import org.ofbiz.base.util.UtilXml;
  49. import org.ofbiz.ebay.EbayHelper;
  50. import org.ofbiz.ebay.ProductsExportToEbay;
  51. import org.ofbiz.entity.Delegator;
  52. import org.ofbiz.entity.GenericEntityException;
  53. import org.ofbiz.entity.GenericValue;
  54. import org.ofbiz.entity.util.EntityUtil;
  55. import org.ofbiz.service.DispatchContext;
  56. import org.ofbiz.service.GenericServiceException;
  57. import org.ofbiz.service.LocalDispatcher;
  58. import org.ofbiz.service.ModelService;
  59. import org.ofbiz.service.ServiceUtil;
  60. import org.w3c.dom.Document;
  61. import org.w3c.dom.Element;
  62. import com.ebay.sdk.ApiContext;
  63. import com.ebay.sdk.ApiException;
  64. import com.ebay.sdk.SdkException;
  65. import com.ebay.sdk.SdkSoapException;
  66. import com.ebay.sdk.TimeFilter;
  67. import com.ebay.sdk.call.AddDisputeCall;
  68. import com.ebay.sdk.call.AddSecondChanceItemCall;
  69. import com.ebay.sdk.call.GetAllBiddersCall;
  70. import com.ebay.sdk.call.GetItemCall;
  71. import com.ebay.sdk.call.GetMyeBaySellingCall;
  72. import com.ebay.sdk.call.GetOrdersCall;
  73. import com.ebay.sdk.call.GetSellerTransactionsCall;
  74. import com.ebay.sdk.call.GetSellingManagerSoldListingsCall;
  75. import com.ebay.sdk.call.GetStoreCall;
  76. import com.ebay.sdk.call.GetStoreOptionsCall;
  77. import com.ebay.sdk.call.ReviseItemCall;
  78. import com.ebay.sdk.call.SetStoreCall;
  79. import com.ebay.sdk.call.SetStoreCategoriesCall;
  80. import com.ebay.sdk.call.VerifyAddSecondChanceItemCall;
  81. import com.ebay.sdk.util.eBayUtil;
  82. import com.ebay.soap.eBLBaseComponents.AddressType;
  83. import com.ebay.soap.eBLBaseComponents.AmountType;
  84. import com.ebay.soap.eBLBaseComponents.CheckoutStatusType;
  85. import com.ebay.soap.eBLBaseComponents.CurrencyCodeType;
  86. import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
  87. import com.ebay.soap.eBLBaseComponents.DisputeExplanationCodeType;
  88. import com.ebay.soap.eBLBaseComponents.DisputeReasonCodeType;
  89. import com.ebay.soap.eBLBaseComponents.ExternalTransactionType;
  90. import com.ebay.soap.eBLBaseComponents.GalleryTypeCodeType;
  91. import com.ebay.soap.eBLBaseComponents.GetAllBiddersModeCodeType;
  92. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsRequestType;
  93. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsResponseType;
  94. import com.ebay.soap.eBLBaseComponents.GetStoreRequestType;
  95. import com.ebay.soap.eBLBaseComponents.GetStoreResponseType;
  96. import com.ebay.soap.eBLBaseComponents.ItemArrayType;
  97. import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
  98. import com.ebay.soap.eBLBaseComponents.ItemSortTypeCodeType;
  99. import com.ebay.soap.eBLBaseComponents.ItemType;
  100. import com.ebay.soap.eBLBaseComponents.ListingTypeCodeType;
  101. import com.ebay.soap.eBLBaseComponents.MerchDisplayCodeType;
  102. import com.ebay.soap.eBLBaseComponents.OfferType;
  103. import com.ebay.soap.eBLBaseComponents.OrderStatusCodeType;
  104. import com.ebay.soap.eBLBaseComponents.OrderTransactionType;
  105. import com.ebay.soap.eBLBaseComponents.OrderType;
  106. import com.ebay.soap.eBLBaseComponents.PaginatedItemArrayType;
  107. import com.ebay.soap.eBLBaseComponents.PaginationType;
  108. import com.ebay.soap.eBLBaseComponents.PhotoDisplayCodeType;
  109. import com.ebay.soap.eBLBaseComponents.PictureDetailsType;
  110. import com.ebay.soap.eBLBaseComponents.PictureSourceCodeType;
  111. import com.ebay.soap.eBLBaseComponents.SalesTaxType;
  112. import com.ebay.soap.eBLBaseComponents.SecondChanceOfferDurationCodeType;
  113. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchType;
  114. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchTypeCodeType;
  115. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldListingsPropertyTypeCodeType;
  116. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldOrderType;
  117. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldTransactionType;
  118. import com.ebay.soap.eBLBaseComponents.SellingStatusType;
  119. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesRequestType;
  120. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesResponseType;
  121. import com.ebay.soap.eBLBaseComponents.SetStoreRequestType;
  122. import com.ebay.soap.eBLBaseComponents.SetStoreResponseType;
  123. import com.ebay.soap.eBLBaseComponents.ShippingDetailsType;
  124. import com.ebay.soap.eBLBaseComponents.ShippingServiceOptionsType;
  125. import com.ebay.soap.eBLBaseComponents.StoreCategoryUpdateActionCodeType;
  126. import com.ebay.soap.eBLBaseComponents.StoreColorSchemeType;
  127. import com.ebay.soap.eBLBaseComponents.StoreColorType;
  128. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryArrayType;
  129. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryType;
  130. import com.ebay.soap.eBLBaseComponents.StoreCustomHeaderLayoutCodeType;
  131. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderDisplayCodeType;
  132. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderType;
  133. import com.ebay.soap.eBLBaseComponents.StoreFontFaceCodeType;
  134. import com.ebay.soap.eBLBaseComponents.StoreFontSizeCodeType;
  135. import com.ebay.soap.eBLBaseComponents.StoreFontType;
  136. import com.ebay.soap.eBLBaseComponents.StoreHeaderStyleCodeType;
  137. import com.ebay.soap.eBLBaseComponents.StoreItemListLayoutCodeType;
  138. import com.ebay.soap.eBLBaseComponents.StoreItemListSortOrderCodeType;
  139. import com.ebay.soap.eBLBaseComponents.StoreLogoArrayType;
  140. import com.ebay.soap.eBLBaseComponents.StoreLogoType;
  141. import com.ebay.soap.eBLBaseComponents.StoreSubscriptionLevelCodeType;
  142. import com.ebay.soap.eBLBaseComponents.StoreThemeArrayType;
  143. import com.ebay.soap.eBLBaseComponents.StoreThemeType;
  144. import com.ebay.soap.eBLBaseComponents.StoreType;
  145. import com.ebay.soap.eBLBaseComponents.TradingRoleCodeType;
  146. import com.ebay.soap.eBLBaseComponents.TransactionType;
  147. import com.ebay.soap.eBLBaseComponents.UserType;
  148. import com.ibm.icu.text.SimpleDateFormat;
  149. public class EbayStore {
  150. private static final String resource = "EbayStoreUiLabels";
  151. private static final String module = ProductsExportToEbay.class.getName();
  152. public static ProductsExportToEbay productExportEbay = new ProductsExportToEbay();
  153. private static void appendRequesterCredentials(Element elem, Document doc, String token) {
  154. Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
  155. UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
  156. }
  157. private static Map<String, Object> postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID,
  158. String callName, String compatibilityLevel, String siteID) throws IOException {
  159. if (Debug.verboseOn()) {
  160. Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), module);
  161. }
  162. HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
  163. connection.setDoInput(true);
  164. connection.setDoOutput(true);
  165. connection.setRequestMethod("POST");
  166. connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
  167. connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
  168. connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
  169. connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
  170. connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
  171. connection.setRequestProperty("X-EBAY-API-SITEID", siteID);
  172. connection.setRequestProperty("Content-Type", "text/xml");
  173. OutputStream outputStream = connection.getOutputStream();
  174. outputStream.write(dataItems.toString().getBytes());
  175. outputStream.close();
  176. int responseCode = connection.getResponseCode();
  177. InputStream inputStream;
  178. Map<String, Object> result = FastMap.newInstance();
  179. String response = null;
  180. if (responseCode == HttpURLConnection.HTTP_CREATED ||
  181. responseCode == HttpURLConnection.HTTP_OK) {
  182. inputStream = connection.getInputStream();
  183. response = toString(inputStream);
  184. result = ServiceUtil.returnSuccess(response);
  185. } else {
  186. inputStream = connection.getErrorStream();
  187. response = toString(inputStream);
  188. result = ServiceUtil.returnFailure(response);
  189. }
  190. if (Debug.verboseOn()) {
  191. Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
  192. }
  193. return result;
  194. }
  195. private static String toString(InputStream inputStream) throws IOException {
  196. String string;
  197. StringBuilder outputBuilder = new StringBuilder();
  198. if (inputStream != null) {
  199. BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
  200. while (null != (string = reader.readLine())) {
  201. outputBuilder.append(string).append('\n');
  202. }
  203. }
  204. return outputBuilder.toString();
  205. }
  206. /* add/update/delete categories and child into your ebay store category */
  207. public static Map<String,Object> exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map<String,? extends Object> context) {
  208. Locale locale = (Locale) context.get("locale");
  209. Delegator delegator = dctx.getDelegator();
  210. Map<String, Object> result = FastMap.newInstance();
  211. SetStoreCategoriesRequestType req = null;
  212. StoreCustomCategoryArrayType categoryArrayType = null;
  213. List<GenericValue> catalogCategories = null;
  214. if (UtilValidate.isEmpty(context.get("prodCatalogId")) || UtilValidate.isEmpty(context.get("productStoreId")) || UtilValidate.isEmpty(context.get("partyId"))) {
  215. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStoreSetCatalogIdAndProductStoreId", locale));
  216. }
  217. if (!EbayStoreHelper.validatePartyAndRoleType(delegator,context.get("partyId").toString())) {
  218. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStorePartyWithoutRoleEbayAccount", UtilMisc.toMap("partyId", context.get("partyId").toString()), locale));
  219. }
  220. try {
  221. SetStoreCategoriesCall call = new SetStoreCategoriesCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  222. catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString(),"prodCatalogCategoryTypeId","PCCT_EBAY_ROOT"), UtilMisc.toList("sequenceNum ASC"));
  223. if (catalogCategories != null && catalogCategories.size() > 0) {
  224. List<StoreCustomCategoryType> listAdd = FastList.newInstance();
  225. List<StoreCustomCategoryType> listEdit = FastList.newInstance();
  226. //start at level 0 of categories
  227. for (GenericValue catalogCategory : catalogCategories) {
  228. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  229. if (productCategory != null) {
  230. String ebayCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  231. StoreCustomCategoryType categoryType = new StoreCustomCategoryType();
  232. if (ebayCategoryId == null) {
  233. categoryType.setName(productCategory.getString("categoryName"));
  234. listAdd.add(categoryType);
  235. } else {
  236. categoryType.setCategoryID(new Long(ebayCategoryId));
  237. categoryType.setName(productCategory.getString("categoryName"));
  238. listEdit.add(categoryType);
  239. }
  240. }
  241. }
  242. if (listAdd.size() > 0) {
  243. req = new SetStoreCategoriesRequestType();
  244. categoryArrayType = new StoreCustomCategoryArrayType();
  245. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  246. req.setStoreCategories(categoryArrayType);
  247. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
  248. }
  249. if (listEdit.size() > 0) {
  250. req = new SetStoreCategoriesRequestType();
  251. categoryArrayType = new StoreCustomCategoryArrayType();
  252. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  253. req.setStoreCategories(categoryArrayType);
  254. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
  255. }
  256. //start at level 1 of categories
  257. listAdd = FastList.newInstance();
  258. listEdit = FastList.newInstance();
  259. for (GenericValue catalogCategory : catalogCategories) {
  260. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  261. if (productCategory != null) {
  262. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  263. if (ebayParentCategoryId != null) {
  264. List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategory.getString("productCategoryId")), UtilMisc.toList("sequenceNum ASC"));
  265. for (GenericValue productCategoryRollup : productCategoryRollupList) {
  266. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryRollup.getString("productCategoryId")));
  267. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  268. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  269. if (ebayChildCategoryId == null) {
  270. childCategoryType.setName(productCategory.getString("categoryName"));
  271. listAdd.add(childCategoryType);
  272. } else {
  273. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  274. childCategoryType.setName(productCategory.getString("categoryName"));
  275. listEdit.add(childCategoryType);
  276. }
  277. }
  278. }
  279. if (listAdd.size() > 0) {
  280. req = new SetStoreCategoriesRequestType();
  281. categoryArrayType = new StoreCustomCategoryArrayType();
  282. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  283. req.setStoreCategories(categoryArrayType);
  284. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  285. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
  286. }
  287. if (listEdit.size() > 0) {
  288. req = new SetStoreCategoriesRequestType();
  289. categoryArrayType = new StoreCustomCategoryArrayType();
  290. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  291. req.setStoreCategories(categoryArrayType);
  292. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  293. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
  294. }
  295. }
  296. }
  297. //start at level 2 of categories
  298. listAdd = FastList.newInstance();
  299. listEdit = FastList.newInstance();
  300. for (GenericValue catalogCategory : catalogCategories) {
  301. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  302. if (productCategory != null) {
  303. List<GenericValue> productParentCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategory.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  304. for (GenericValue productParentCategoryRollup : productParentCategoryRollupList) {
  305. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productParentCategoryRollup.getString("productCategoryId"),context.get("partyId").toString());
  306. if (ebayParentCategoryId != null) {
  307. List<GenericValue> productChildCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productParentCategoryRollup.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  308. for (GenericValue productChildCategoryRollup : productChildCategoryRollupList) {
  309. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productChildCategoryRollup.getString("productCategoryId")));
  310. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  311. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  312. if (ebayChildCategoryId == null) {
  313. childCategoryType.setName(productCategory.getString("categoryName"));
  314. listAdd.add(childCategoryType);
  315. } else {
  316. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  317. childCategoryType.setName(productCategory.getString("categoryName"));
  318. listEdit.add(childCategoryType);
  319. }
  320. }
  321. if (listAdd.size() > 0) {
  322. req = new SetStoreCategoriesRequestType();
  323. categoryArrayType = new StoreCustomCategoryArrayType();
  324. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  325. req.setStoreCategories(categoryArrayType);
  326. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  327. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator, context.get("partyId").toString(), catalogCategories, locale);
  328. }
  329. if (listEdit.size() > 0) {
  330. req = new SetStoreCategoriesRequestType();
  331. categoryArrayType = new StoreCustomCategoryArrayType();
  332. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  333. req.setStoreCategories(categoryArrayType);
  334. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  335. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator, context.get("partyId").toString(), catalogCategories, locale);
  336. }
  337. }
  338. }
  339. }
  340. }
  341. } else {
  342. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStoreRootCategoryNotFound", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId")), locale));
  343. }
  344. } catch (GenericEntityException e) {
  345. result = ServiceUtil.returnFailure(e.getMessage());
  346. }
  347. if (result.get("responseMessage") != null && result.get("responseMessage").equals("fail")) {
  348. result = ServiceUtil.returnError(result.get("errorMessage").toString());
  349. }
  350. return result;
  351. }
  352. public static StoreCustomCategoryType[] toStoreCustomCategoryTypeArray(List<StoreCustomCategoryType> list) {
  353. StoreCustomCategoryType[] storeCustomCategoryTypeArry = null;
  354. try {
  355. if (list != null && list.size() > 0) {
  356. storeCustomCategoryTypeArry = new StoreCustomCategoryType[list.size()];
  357. int i=0;
  358. for (StoreCustomCategoryType val : list) {
  359. storeCustomCategoryTypeArry[i] = val;
  360. }
  361. }
  362. } catch (Exception e) {
  363. Debug.logError(e.getMessage(), module);
  364. }
  365. return storeCustomCategoryTypeArry;
  366. }
  367. public static Map<String, Object> excuteExportCategoryToEbayStore(SetStoreCategoriesCall call, SetStoreCategoriesRequestType req, StoreCategoryUpdateActionCodeType actionCode,Delegator delegator, String partyId,List<GenericValue> catalogCategories, Locale locale) {
  368. Map<String, Object> result = FastMap.newInstance();
  369. SetStoreCategoriesResponseType resp = null;
  370. try {
  371. if (req != null && actionCode != null) {
  372. req.setAction(actionCode);
  373. resp = (SetStoreCategoriesResponseType) call.execute(req);
  374. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  375. StoreCustomCategoryArrayType returnedCustomCategory = resp.getCustomCategory();
  376. if (actionCode.equals(StoreCategoryUpdateActionCodeType.ADD) && returnedCustomCategory != null) {
  377. StoreCustomCategoryType[] returnCategoryTypeList = returnedCustomCategory.getCustomCategory();
  378. for (StoreCustomCategoryType returnCategoryType : returnCategoryTypeList) {
  379. List<GenericValue> productCategoryList = delegator.findByAnd("ProductCategory", UtilMisc.toMap("categoryName",returnCategoryType.getName(),"productCategoryTypeId","EBAY_CATEGORY"));
  380. for (GenericValue productCategory : productCategoryList) {
  381. if (EbayStoreHelper.veriflyCategoryInCatalog(delegator,catalogCategories,productCategory.getString("productCategoryId"))) {
  382. if (EbayStoreHelper.createEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), partyId, String.valueOf(returnCategoryType.getCategoryID()))) {
  383. Debug.logInfo("Create new ProductCategoryRollup with partyId "+partyId+" categoryId "+productCategory.getString("productCategoryId")+ " and ebayCategoryId "+String.valueOf(returnCategoryType.getCategoryID()), module);
  384. }
  385. break;
  386. }
  387. }
  388. }
  389. }
  390. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayExportToEbayStoreSuccess", locale));
  391. } else {
  392. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayExportToEbayStoreFailed", UtilMisc.toMap("errorString", resp.getMessage()), locale));
  393. }
  394. }
  395. } catch (ApiException e) {
  396. result = ServiceUtil.returnFailure(e.getMessage());
  397. } catch (SdkSoapException e) {
  398. result = ServiceUtil.returnFailure(e.getMessage());
  399. } catch (SdkException e) {
  400. result = ServiceUtil.returnFailure(e.getMessage());
  401. } catch (GenericEntityException e) {
  402. result = ServiceUtil.returnFailure(e.getMessage());
  403. }
  404. return result;
  405. }
  406. public static Map<String, Object> buildSetStoreXml(DispatchContext dctx, Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID) {
  407. Locale locale = (Locale)context.get("locale");
  408. try {
  409. Delegator delegator = dctx.getDelegator();
  410. // Get the list of products to be exported to eBay
  411. try {
  412. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreRequest");
  413. Element storeRequestElem = storeDocument.getDocumentElement();
  414. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  415. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  416. /*UtilXml.addChildElementValue(storeRequestElem, "SiteId", siteID, storeDocument);
  417. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  418. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);*/
  419. // Prepare data for set to XML
  420. GenericValue productStore = null;
  421. if (UtilValidate.isNotEmpty(context.get("productStoreId").toString())) {
  422. productStore = delegator.findByPrimaryKey("ProductStore",UtilMisc.toMap("productStoreId", context.get("productStoreId").toString()));
  423. }
  424. Element itemElem = UtilXml.addChildElement(storeRequestElem, "Store", storeDocument);
  425. UtilXml.addChildElementValue(itemElem, "Name", productStore.getString("storeName"), storeDocument);
  426. UtilXml.addChildElementValue(itemElem, "SubscriptionLevel", "Basic", storeDocument);
  427. UtilXml.addChildElementValue(itemElem, "Description", productStore.getString("title"), storeDocument);
  428. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  429. } catch (Exception e) {
  430. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  431. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  432. }
  433. } catch (Exception e) {
  434. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  435. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  436. }
  437. return ServiceUtil.returnSuccess();
  438. }
  439. public static String readEbayResponse(String msg, String productStoreId) {
  440. String result = "success";
  441. try {
  442. Document docResponse = UtilXml.readXmlDocument(msg, true);
  443. Element elemResponse = docResponse.getDocumentElement();
  444. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  445. if (ack != null && "Failure".equals(ack)) {
  446. String errorMessage = "";
  447. List<Element> errorList = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Errors"));
  448. Iterator<Element> errorElemIter = errorList.iterator();
  449. while (errorElemIter.hasNext()) {
  450. Element errorElement = errorElemIter.next();
  451. errorMessage = UtilXml.childElementValue(errorElement, "LongMessage");
  452. }
  453. result = errorMessage;
  454. } else {
  455. result = "Successfully exported with ID (" + productStoreId + ").";
  456. }
  457. } catch (Exception e) {
  458. Debug.logError("Error in processing xml string" + e.getMessage(), module);
  459. result = "Failure";
  460. }
  461. return result;
  462. }
  463. public static Map<String, Object> buildGetStoreXml(Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID) {
  464. Locale locale = (Locale)context.get("locale");
  465. // Get the list of products to be exported to eBay
  466. try {
  467. Document storeDocument = UtilXml.makeEmptyXmlDocument("GetStoreRequest");
  468. Element storeRequestElem = storeDocument.getDocumentElement();
  469. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  470. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  471. //UtilXml.addChildElementValue(storeRequestElem, "CategorySiteID", siteID, storeDocument);
  472. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  473. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);
  474. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  475. } catch (Exception e) {
  476. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  477. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  478. }
  479. return ServiceUtil.returnSuccess();
  480. }
  481. public static Map<String, Object> buildSetStoreCategoriesXml(DispatchContext dctx, Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID, String productCategoryId) {
  482. Delegator delegator = dctx.getDelegator();
  483. Locale locale = (Locale)context.get("locale");
  484. // Get the list of products to be exported to eBay
  485. try {
  486. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreCategoriesRequest");
  487. Element storeRequestElem = storeDocument.getDocumentElement();
  488. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  489. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  490. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  491. UtilXml.addChildElementValue(storeRequestElem, "Version", "643", storeDocument);
  492. UtilXml.addChildElementValue(storeRequestElem, "Action", "Add", storeDocument);
  493. Element StoreCategoriesElem = UtilXml.addChildElement(storeRequestElem, "StoreCategories", storeDocument);
  494. //UtilXml.addChildElementValue(StoreCategoriesElem, "Country", (String)context.get("country"), storeDocument);
  495. GenericValue category = null;
  496. if (UtilValidate.isNotEmpty(context.get("prodCatalogId"))) {
  497. category = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId));
  498. }
  499. String categoryName = category.getString("productCategoryId").toString();
  500. if (category.getString("categoryName").toString() != null) {
  501. categoryName = category.getString("categoryName").toString();
  502. }
  503. Element customCategoryElem = UtilXml.addChildElement(StoreCategoriesElem, "CustomCategory", storeDocument);
  504. //UtilXml.addChildElementValue(customCategoryElem, "CategoryID", "", storeDocument);
  505. UtilXml.addChildElementValue(customCategoryElem, "Name", categoryName, storeDocument);
  506. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  507. } catch (Exception e) {
  508. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  509. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  510. }
  511. return ServiceUtil.returnSuccess();
  512. }
  513. public static Map<String, Object> readEbayGetStoreCategoriesResponse(String msg, Locale locale) {
  514. Map<String, Object> results = null;
  515. List<Map<Object, Object>> categories = FastList.newInstance();
  516. try {
  517. Document docResponse = UtilXml.readXmlDocument(msg, true);
  518. Element elemResponse = docResponse.getDocumentElement();
  519. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  520. if (ack != null && "Failure".equals(ack)) {
  521. String errorMessage = "";
  522. List<Element> errorList = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Errors"));
  523. Iterator<Element> errorElemIter = errorList.iterator();
  524. while (errorElemIter.hasNext()) {
  525. Element errorElement = errorElemIter.next();
  526. errorMessage = UtilXml.childElementValue(errorElement, "ShortMessage", "");
  527. }
  528. return ServiceUtil.returnFailure(errorMessage);
  529. } else {
  530. // retrieve Store
  531. List<Element> Store = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Store"));
  532. Iterator<Element> StoreElemIter = Store.iterator();
  533. while (StoreElemIter.hasNext()) {
  534. Element StoreElemIterElemIterElement = StoreElemIter.next();
  535. // retrieve Custom Category Array
  536. List<Element> customCategories = UtilGenerics.checkList(UtilXml.childElementList(StoreElemIterElemIterElement, "CustomCategories"));
  537. Iterator<Element> customCategoriesElemIter = customCategories.iterator();
  538. while (customCategoriesElemIter.hasNext()) {
  539. Element customCategoriesElemIterElement = customCategoriesElemIter.next();
  540. // retrieve CustomCategory
  541. List<Element> customCategory = UtilGenerics.checkList(UtilXml.childElementList(customCategoriesElemIterElement, "CustomCategory"));
  542. Iterator<Element> customCategoryElemIter = customCategory.iterator();
  543. while (customCategoryElemIter.hasNext()) {
  544. Map<Object, Object> categ = FastMap.newInstance();
  545. Element categoryElement = customCategoryElemIter.next();
  546. categ.put("CategoryID", UtilXml.childElementValue(categoryElement, "CategoryID"));
  547. categ.put("CategoryName", UtilXml.childElementValue(categoryElement, "Name"));
  548. categ.put("CategorySeq", UtilXml.childElementValue(categoryElement, "Order"));
  549. categories.add(categ);
  550. }
  551. }
  552. }
  553. categories = UtilMisc.sortMaps(categories, UtilMisc.toList("CategoryName"));
  554. results = UtilMisc.<String, Object>toMap("categories", categories);
  555. }
  556. } catch (Exception e) {
  557. return ServiceUtil.returnFailure();
  558. }
  559. return results;
  560. }
  561. public static Map<String, Object> getEbayStoreUser(DispatchContext dctx, Map<String, ? extends Object> context) {
  562. Map<String, Object> result = FastMap.newInstance();
  563. Delegator delegator = dctx.getDelegator();
  564. String productStoreId = (String) context.get("productStoreId");
  565. try {
  566. List<GenericValue> productStores = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStoreId, "roleTypeId", "EBAY_ACCOUNT"));
  567. if (productStores.size() != 0) {
  568. String partyId = (productStores.get(0)).getString("partyId");
  569. List<GenericValue> userLoginStore = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  570. if (userLoginStore.size() != 0) {
  571. String userLoginId = (userLoginStore.get(0)).getString("userLoginId");
  572. result.put("userLoginId", userLoginId);
  573. }
  574. }
  575. } catch (Exception e) {
  576. }
  577. return result;
  578. }
  579. /*Editing the Store Settings */
  580. /* Get store output */
  581. public static Map<String,Object> getEbayStoreOutput(DispatchContext dctx, Map<String,Object> context) {
  582. Locale locale = (Locale) context.get("locale");
  583. GenericValue userLogin = (GenericValue) context.get("userLogin");
  584. Delegator delegator = dctx.getDelegator();
  585. Map<String,Object> result = FastMap.newInstance();
  586. StoreType returnedStoreType = null;
  587. GetStoreRequestType req = new GetStoreRequestType();
  588. GetStoreResponseType resp = null;
  589. String userLoginId = null;
  590. if (context.get("productStoreId") != null) {
  591. String partyId = null;
  592. try {
  593. List<GenericValue> productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(),"roleTypeId","EBAY_ACCOUNT"));
  594. if (productStoreRoles.size() != 0) {
  595. partyId= (String)productStoreRoles.get(0).get("partyId");
  596. List<GenericValue> userLogins = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  597. if (userLogins.size() != 0) {
  598. userLoginId = (String)userLogins.get(0).get("userLoginId");
  599. }
  600. }
  601. } catch (GenericEntityException e1) {
  602. e1.printStackTrace();
  603. }
  604. Debug.logInfo("userLoginId is "+userLoginId+" and productStoreId is "+ context.get("productStoreId"), module);
  605. GetStoreCall call = new GetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  606. //call.setSite(EbayHelper.getSiteCodeType((String)context.get("productStoreId"), locale, delegator));
  607. call.setCategoryStructureOnly(false);
  608. call.setUserID(userLoginId);
  609. try {
  610. resp = (GetStoreResponseType)call.execute(req);
  611. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  612. returnedStoreType = resp.getStore();
  613. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
  614. //result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "EbayStoreLoadSuccess", locale));
  615. // update product store in ofbiz
  616. updateProductStore(dctx, context, returnedStoreType,(String) context.get("productStoreId"));
  617. Map<String,Object> ebayResp = FastMap.newInstance();
  618. ebayResp.put("storeName", returnedStoreType.getName());
  619. ebayResp.put("storeUrl", returnedStoreType.getURL());
  620. ebayResp.put("storeUrlPath", returnedStoreType.getURLPath());
  621. String desc = returnedStoreType.getDescription();
  622. if (desc != null) desc = desc.trim();
  623. ebayResp.put("storeDesc", desc);
  624. StoreLogoType logoType = returnedStoreType.getLogo();
  625. ebayResp.put("storeLogoId", logoType.getLogoID());
  626. ebayResp.put("storeLogoName", logoType.getName());
  627. ebayResp.put("storeLogoURL", logoType.getURL());
  628. StoreThemeType themeType = returnedStoreType.getTheme();
  629. ebayResp.put("storeThemeId", themeType.getThemeID());
  630. ebayResp.put("storeThemeName", themeType.getName());
  631. StoreColorSchemeType colorSchemeType = themeType.getColorScheme();
  632. ebayResp.put("storeColorSchemeId", colorSchemeType.getColorSchemeID());
  633. StoreColorType colorType = colorSchemeType.getColor();
  634. ebayResp.put("storeColorPrimary", colorType.getPrimary());
  635. ebayResp.put("storeColorAccent", colorType.getAccent());
  636. ebayResp.put("storeColorSecondary", colorType.getSecondary());
  637. StoreFontType fontType = colorSchemeType.getFont();
  638. ebayResp.put("storeDescColor", fontType.getDescColor());
  639. ebayResp.put("storeNameColor", fontType.getNameColor());
  640. ebayResp.put("storeTitleColor", fontType.getTitleColor());
  641. if (fontType != null) {// basic & advance theme
  642. String themeId = themeType.getThemeID().toString().concat("-").concat(colorSchemeType.getColorSchemeID().toString());
  643. context.put("themeId", themeId);
  644. Map<String,Object> results = retrieveThemeColorSchemeByThemeId(dctx, context);
  645. if (results != null) {
  646. Map<String,Object> storeFontScheme = UtilGenerics.checkMap(results.get("storeFontScheme"));
  647. if (storeFontScheme != null) {
  648. ebayResp.put("storeDescFontFace", storeFontScheme.get("storeFontTypeFontDescValue"));
  649. ebayResp.put("storeDescSizeCode", storeFontScheme.get("storeDescSizeValue"));
  650. ebayResp.put("storeNameFontFace", storeFontScheme.get("storeFontTypeFontFaceValue"));
  651. ebayResp.put("storeNameFontFaceSize", storeFontScheme.get("storeFontTypeSizeFaceValue"));
  652. ebayResp.put("storeTitleFontFace", storeFontScheme.get("storeFontTypeFontTitleValue"));
  653. ebayResp.put("storeTitleFontFaceSize", storeFontScheme.get("storeFontSizeTitleValue"));
  654. }
  655. }
  656. }
  657. StoreHeaderStyleCodeType storeHeaderStyleCodeType = returnedStoreType.getHeaderStyle();
  658. ebayResp.put("storeHeaderStyle", storeHeaderStyleCodeType.value());
  659. StoreHeaderStyleCodeType[] storeHeaderStyleCodeList = StoreHeaderStyleCodeType.values();
  660. if (storeHeaderStyleCodeList != null) {
  661. List<Map<String,Object>> storeHeaderStyleList = FastList.newInstance();
  662. int i=0;
  663. while (i<storeHeaderStyleCodeList.length) {
  664. Map<String,Object> storeHeaderStyleMap = FastMap.newInstance();
  665. StoreHeaderStyleCodeType storeHeaderStyleCode = storeHeaderStyleCodeList[i];
  666. storeHeaderStyleMap.put("storeHeaderStyleName", storeHeaderStyleCode.name());
  667. storeHeaderStyleMap.put("storeHeaderStyleValue", storeHeaderStyleCode.value());
  668. storeHeaderStyleList.add(storeHeaderStyleMap);
  669. i++;
  670. }
  671. ebayResp.put("storeHeaderStyleList", storeHeaderStyleList);
  672. }
  673. ebayResp.put("storeHomePage", returnedStoreType.getHomePage().toString());
  674. StoreItemListLayoutCodeType storeItemListLayoutCodeType = returnedStoreType.getItemListLayout();
  675. ebayResp.put("storeItemLayoutSelected", storeItemListLayoutCodeType.value());
  676. StoreItemListLayoutCodeType[] storeItemListLayoutCodeTypeList = StoreItemListLayoutCodeType.values();
  677. if (storeItemListLayoutCodeTypeList != null) {
  678. List<Map<String,Object>> storeItemListLayoutCodeList = FastList.newInstance();
  679. int i = 0;
  680. while (i < storeItemListLayoutCodeTypeList.length) {
  681. Map<String,Object> storeItemListLayoutCodeMap = FastMap.newInstance();
  682. StoreItemListLayoutCodeType storeItemListLayoutCode = storeItemListLayoutCodeTypeList[i];
  683. storeItemListLayoutCodeMap.put("storeItemLayoutName", storeItemListLayoutCode.name());
  684. storeItemListLayoutCodeMap.put("storeItemLayoutValue", storeItemListLayoutCode.value());
  685. storeItemListLayoutCodeList.add(storeItemListLayoutCodeMap);
  686. i++;
  687. }
  688. ebayResp.put("storeItemLayoutList", storeItemListLayoutCodeList);
  689. }
  690. StoreItemListSortOrderCodeType storeItemListSortOrderCodeType = returnedStoreType.getItemListSortOrder();
  691. ebayResp.put("storeItemSortOrderSelected", storeItemListSortOrderCodeType.value());
  692. StoreItemListSortOrderCodeType[] storeItemListSortOrderCodeTypeList = StoreItemListSortOrderCodeType.values();
  693. if (storeItemListSortOrderCodeTypeList != null) {
  694. List<Map<String,Object>> storeItemSortOrderCodeList = FastList.newInstance();
  695. int i = 0;
  696. while (i < storeItemListSortOrderCodeTypeList.length) {
  697. Map<String,Object> storeItemSortOrderCodeMap = FastMap.newInstance();
  698. StoreItemListSortOrderCodeType storeItemListLayoutCode = storeItemListSortOrderCodeTypeList[i];
  699. storeItemSortOrderCodeMap.put("storeItemSortLayoutName", storeItemListLayoutCode.name());
  700. storeItemSortOrderCodeMap.put("storeItemSortLayoutValue", storeItemListLayoutCode.value());
  701. storeItemSortOrderCodeList.add(storeItemSortOrderCodeMap);
  702. i++;
  703. }
  704. ebayResp.put("storeItemSortOrderList", storeItemSortOrderCodeList);
  705. }
  706. ebayResp.put("storeCustomHeader", returnedStoreType.getCustomHeader());
  707. StoreCustomHeaderLayoutCodeType storeCustomHeaderLayoutCodeType = returnedStoreType.getCustomHeaderLayout();
  708. ebayResp.put("storeCustomHeaderLayout", storeCustomHeaderLayoutCodeType.value());
  709. StoreCustomHeaderLayoutCodeType[] storeCustomHeaderLayoutCodeTypeList = StoreCustomHeaderLayoutCodeType.values();
  710. if (storeCustomHeaderLayoutCodeTypeList != null) {
  711. List<Map<String,Object>> storeCustomHeaderLayoutList = FastList.newInstance();
  712. int i = 0;
  713. while (i < storeCustomHeaderLayoutCodeTypeList.length) {
  714. Map<String,Object> storeCustomHeaderLayoutMap = FastMap.newInstance();
  715. StoreCustomHeaderLayoutCodeType StoreCustomHeaderLayoutCode = storeCustomHeaderLayoutCodeTypeList[i];
  716. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutName", StoreCustomHeaderLayoutCode.name());
  717. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutValue", StoreCustomHeaderLayoutCode.value());
  718. storeCustomHeaderLayoutList.add(storeCustomHeaderLayoutMap);
  719. i++;
  720. }
  721. ebayResp.put("storeCustomHeaderLayoutList", storeCustomHeaderLayoutList);
  722. }
  723. StoreCustomListingHeaderType storeCustomListingHeaderType = returnedStoreType.getCustomListingHeader();
  724. if (storeCustomListingHeaderType != null) {
  725. StoreCustomListingHeaderDisplayCodeType storeCustomListingHeaderDisplayCodeType = storeCustomListingHeaderType.getDisplayType();
  726. ebayResp.put("isLogo", storeCustomListingHeaderType.isLogo());
  727. ebayResp.put("isSearchBox", storeCustomListingHeaderType.isSearchBox());
  728. ebayResp.put("isAddToFavoriteStores", storeCustomListingHeaderType.isAddToFavoriteStores());
  729. ebayResp.put("isSignUpForStoreNewsletter", storeCustomListingHeaderType.isSignUpForStoreNewsletter());
  730. ebayResp.put("storeCustomListingHeaderDisplayName", storeCustomListingHeaderDisplayCodeType.name());
  731. ebayResp.put("storeCustomListingHeaderDisplayValue", storeCustomListingHeaderDisplayCodeType.value());
  732. StoreCustomListingHeaderDisplayCodeType[] storeCustomListingHeaderDisplayCodeTypeList = StoreCustomListingHeaderDisplayCodeType.values();
  733. if (storeCustomListingHeaderDisplayCodeTypeList != null) {
  734. List<Map<String,Object>> storeCustomListingHeaderDisplayCodeList = FastList.newInstance();
  735. int i = 0;
  736. while (i < storeCustomListingHeaderDisplayCodeTypeList.length) {
  737. Map<String,Object> storeCustomListingHeaderDisplayCodeMap = FastMap.newInstance();
  738. StoreCustomListingHeaderDisplayCodeType storeCustomListingHeaderDisplayCode = storeCustomListingHeaderDisplayCodeTypeList[i];
  739. storeCustomListingHeaderDisplayCodeMap.put("storeCustomHeaderLayoutName", storeCustomListingHeaderDisplayCode.name());
  740. storeCustomListingHeaderDisplayCodeMap.put("storeCustomHeaderLayoutValue", storeCustomListingHeaderDisplayCode.value());
  741. storeCustomListingHeaderDisplayCodeList.add(storeCustomListingHeaderDisplayCodeMap);
  742. i++;
  743. }
  744. ebayResp.put("storeCustomListingHeaderDisplayList", storeCustomListingHeaderDisplayCodeList);
  745. }
  746. }
  747. //CustomListingHeader
  748. MerchDisplayCodeType merchDisplayCodeType = returnedStoreType.getMerchDisplay();
  749. ebayResp.put("storeMerchDisplay",merchDisplayCodeType.value());
  750. MerchDisplayCodeType[] merchDisplayCodeTypeList = MerchDisplayCodeType.values();
  751. if (merchDisplayCodeTypeList != null) {
  752. List<Map<String,Object>> merchDisplayCodeList = FastList.newInstance();
  753. int i = 0;
  754. while (i < merchDisplayCodeTypeList.length) {
  755. Map<String,Object> merchDisplayCodeMap = FastMap.newInstance();
  756. MerchDisplayCodeType merchDisplayCode = merchDisplayCodeTypeList[i];
  757. merchDisplayCodeMap.put("merchDisplayCodeName", merchDisplayCode.name());
  758. merchDisplayCodeMap.put("merchDisplayCodeValue", merchDisplayCode.value());
  759. merchDisplayCodeList.add(merchDisplayCodeMap);
  760. i++;
  761. }
  762. ebayResp.put("storeMerchDisplayList",merchDisplayCodeList);
  763. }
  764. Calendar calendar = returnedStoreType.getLastOpenedTime();
  765. ebayResp.put("storeLastOpenedTime", calendar.getTime().toString());
  766. ebayResp.put("storeSubscriptionLevel", returnedStoreType.getSubscriptionLevel().value());
  767. returnedStoreType.getSubscriptionLevel();
  768. StoreSubscriptionLevelCodeType[] storeSubscriptionlevelList = StoreSubscriptionLevelCodeType.values();
  769. if (storeSubscriptionlevelList != null) {
  770. List<Map<String,Object>> storeSubscriptionLevelCodeList = FastList.newInstance();
  771. int i = 0;
  772. while (i < storeSubscriptionlevelList.length) {
  773. Map<String,Object> storeSubscriptionLevelCodeMap = FastMap.newInstance();
  774. StoreSubscriptionLevelCodeType storeSubscriptionLevelCode= storeSubscriptionlevelList[i];
  775. storeSubscriptionLevelCodeMap.put("storeSubscriptionLevelCodeName", storeSubscriptionLevelCode.name());
  776. storeSubscriptionLevelCodeMap.put("storeSubscriptionLevelCodeValue", storeSubscriptionLevelCode.value());
  777. storeSubscriptionLevelCodeList.add(storeSubscriptionLevelCodeMap);
  778. i++;
  779. }
  780. ebayResp.put("storeSubscriptionLevelList", storeSubscriptionLevelCodeList);
  781. }
  782. result.put("ebayStore", ebayResp);
  783. } else {
  784. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store : getEbayStoreOutput", resp.getErrors(0).getLongMessage());
  785. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  786. result.put(ModelService.ERROR_MESSAGE, resp.getAck().toString() +":"+ resp.getMessage());
  787. }
  788. } catch (ApiException e) {
  789. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  790. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  791. } catch (SdkSoapException e) {
  792. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  793. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  794. } catch (SdkException e) {
  795. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  796. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  797. }
  798. }
  799. return result;
  800. }
  801. public static void updateProductStore(DispatchContext dctx, Map<String,Object> context, StoreType returnStoreType, String productStoreId) {
  802. LocalDispatcher dispatcher = dctx.getDispatcher();
  803. try {
  804. Map<String,Object> inMap = FastMap.newInstance();
  805. if (returnStoreType != null) {
  806. inMap.put("productStoreId", productStoreId);
  807. inMap.put("storeName", returnStoreType.getName());
  808. inMap.put("subtitle", returnStoreType.getDescription());
  809. inMap.put("title", returnStoreType.getName());
  810. inMap.put("userLogin", context.get("userLogin"));
  811. dispatcher.runSync("updateProductStore", inMap);
  812. }
  813. } catch (Exception e) {
  814. Debug.logError("error message"+e, module);
  815. }
  816. }
  817. public static Map<String,Object> retrieveThemeColorSchemeByThemeId(DispatchContext dctx, Map<String,Object> context) {
  818. GenericValue userLogin = (GenericValue) context.get("userLogin");
  819. Locale locale = (Locale) context.get("locale");
  820. Delegator delegator = dctx.getDelegator();
  821. Map<String,Object> result = FastMap.newInstance();
  822. GetStoreOptionsRequestType req = null;
  823. GetStoreOptionsResponseType resp = null;
  824. StoreThemeArrayType returnedBasicThemeArray = null;
  825. try {
  826. if (context.get("productStoreId") != null) {
  827. String themeId = (String)context.get("themeId");
  828. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  829. req = new GetStoreOptionsRequestType();
  830. resp = (GetStoreOptionsResponseType) call.execute(req);
  831. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  832. returnedBasicThemeArray = resp.getBasicThemeArray();
  833. StoreThemeType[] storeBasicTheme = returnedBasicThemeArray.getTheme();
  834. int i = 0;
  835. String colorSchemeId = themeId.substring(themeId.indexOf("-") + 1);
  836. themeId = themeId.substring(0,themeId.indexOf("-"));
  837. Map<String,Object> storeColorSchemeMap = null;
  838. while (i < storeBasicTheme.length) {
  839. StoreThemeType storeThemeType = storeBasicTheme[i];
  840. if (themeId.equals(storeThemeType.getThemeID().toString())) {
  841. StoreColorSchemeType colorSchemeType = storeThemeType.getColorScheme();
  842. if (colorSchemeType != null) {
  843. if (colorSchemeId.equals(colorSchemeType.getColorSchemeID().toString())) {
  844. // get font,size and color
  845. storeColorSchemeMap = FastMap.newInstance();
  846. StoreFontType storeFontType = colorSchemeType.getFont();
  847. storeColorSchemeMap.put("storeFontTypeFontFaceValue", storeFontType.getNameFace().value());
  848. storeColorSchemeMap.put("storeFontTypeSizeFaceValue", storeFontType.getNameSize().value());
  849. storeColorSchemeMap.put("storeFontTypeFontTitleValue", storeFontType.getTitleFace().value());
  850. storeColorSchemeMap.put("storeFontSizeTitleValue", storeFontType.getTitleSize().value());
  851. storeColorSchemeMap.put("storeFontTypeFontDescValue", storeFontType.getDescFace().value());
  852. storeColorSchemeMap.put("storeDescSizeValue", storeFontType.getDescSize().value());
  853. break;
  854. }
  855. }
  856. }
  857. i++;
  858. }
  859. result.put("storeFontScheme", storeColorSchemeMap);
  860. } else {
  861. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveThemeColorSchemeByThemeId", resp.getErrors(0).getLongMessage());
  862. }
  863. }
  864. } catch (ApiException e) {
  865. e.printStackTrace();
  866. } catch (SdkSoapException e) {
  867. e.printStackTrace();
  868. } catch (SdkException e) {
  869. e.printStackTrace();
  870. }
  871. return result;
  872. }
  873. public static Map<String,Object> retrievePredesignedLogoOption(DispatchContext dctx, Map<String,Object> context) {
  874. GenericValue userLogin = (GenericValue) context.get("userLogin");
  875. Map<String,Object> result = FastMap.newInstance();
  876. Locale locale = (Locale) context.get("locale");
  877. Delegator delegator = dctx.getDelegator();
  878. GetStoreOptionsRequestType req = null;
  879. StoreLogoArrayType returnedLogoArray = null;
  880. GetStoreOptionsResponseType resp = null;
  881. try {
  882. if (context.get("productStoreId") != null) {
  883. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  884. req = new GetStoreOptionsRequestType();
  885. resp = (GetStoreOptionsResponseType) call.execute(req);
  886. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  887. returnedLogoArray = resp.getLogoArray();
  888. int i = 0;
  889. List<Map<String,Object>> logoList = FastList.newInstance();
  890. while (i < returnedLogoArray.getLogoLength()) {
  891. Map<String,Object> logo = FastMap.newInstance();
  892. StoreLogoType storeLogoType = returnedLogoArray.getLogo(i);
  893. logo.put("storeLogoId", storeLogoType.getLogoID());
  894. logo.put("storeLogoName", storeLogoType.getName());
  895. logo.put("storeLogoURL", storeLogoType.getURL());
  896. logoList.add(logo);
  897. i++;
  898. }
  899. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreLoadLogoSuccess", locale));
  900. result.put("storeLogoOptList", logoList);
  901. } else {
  902. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrievePredesignedLogoOption", resp.getErrors(0).getLongMessage());
  903. }
  904. }
  905. } catch (ApiException e) {
  906. e.printStackTrace();
  907. } catch (SdkSoapException e) {
  908. e.printStackTrace();
  909. } catch (SdkException e) {
  910. e.printStackTrace();
  911. }
  912. return result;
  913. }
  914. public static Map<String,Object> retrieveBasicThemeArray(DispatchContext dctx, Map<String,Object> context) {
  915. Map<String,Object> result = FastMap.newInstance();
  916. GenericValue userLogin = (GenericValue) context.get("userLogin");
  917. Locale locale = (Locale) context.get("locale");
  918. Delegator delegator = dctx.getDelegator();
  919. GetStoreOptionsRequestType req = null;
  920. StoreThemeArrayType returnedBasicThemeArray = null;
  921. GetStoreOptionsResponseType resp = null;
  922. try {
  923. if (context.get("productStoreId") != null) {
  924. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  925. req = new GetStoreOptionsRequestType();
  926. resp = (GetStoreOptionsResponseType) call.execute(req);
  927. StoreColorSchemeType storeFontColorSchemeType = null;
  928. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  929. returnedBasicThemeArray = resp.getBasicThemeArray();
  930. int i = 0;
  931. List<Map<String,Object>> themeList = FastList.newInstance();
  932. while (i < returnedBasicThemeArray.getThemeLength()) {
  933. Map<String,Object> basictheme = FastMap.newInstance();
  934. StoreThemeType storeBasicThemeType = returnedBasicThemeArray.getTheme(i);
  935. basictheme.put("storeThemeId", storeBasicThemeType.getThemeID());
  936. basictheme.put("storeThemeName", storeBasicThemeType.getName());
  937. StoreColorSchemeType storeColorSchemeType = storeBasicThemeType.getColorScheme();
  938. basictheme.put("storeColorSchemeId",storeColorSchemeType.getColorSchemeID());
  939. basictheme.put("storeColorSchemeName",storeColorSchemeType.getName());
  940. if (storeFontColorSchemeType == null) {
  941. storeFontColorSchemeType = storeBasicThemeType.getColorScheme();
  942. }
  943. themeList.add(basictheme);
  944. i++;
  945. }
  946. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreLoadBasicThemeSuccess", locale));
  947. result.put("storeThemeList", themeList);
  948. } else {
  949. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveBasicThemeArray", resp.getErrors(0).getLongMessage());
  950. }
  951. }
  952. } catch (ApiException e) {
  953. e.printStackTrace();
  954. } catch (SdkSoapException e) {
  955. e.printStackTrace();
  956. } catch (SdkException e) {
  957. e.printStackTrace();
  958. }
  959. return result;
  960. }
  961. public static Map<String,Object> retrieveAdvancedThemeArray(DispatchContext dctx, Map<String,Object> context) {
  962. Map<String,Object> result = FastMap.newInstance();
  963. GenericValue userLogin = (GenericValue) context.get("userLogin");
  964. Locale locale = (Locale) context.get("locale");
  965. Delegator delegator = dctx.getDelegator();
  966. GetStoreOptionsRequestType req = null;
  967. StoreThemeArrayType returnedAdvancedThemeArray = null;
  968. GetStoreOptionsResponseType resp = null;
  969. try {
  970. if (context.get("productStoreId") != null) {
  971. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  972. req = new GetStoreOptionsRequestType();
  973. resp = (GetStoreOptionsResponseType) call.execute(req);
  974. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  975. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreLoadAdvancedThemeSuccess", locale));
  976. returnedAdvancedThemeArray = resp.getAdvancedThemeArray();
  977. int i = 0;
  978. List<Map<String,Object>> themeList = FastList.newInstance();
  979. while (i < returnedAdvancedThemeArray.getThemeLength()) {
  980. Map<String,Object> advanceTheme = FastMap.newInstance();
  981. StoreThemeType storeThemeType = returnedAdvancedThemeArray.getTheme(i);
  982. advanceTheme.put("storeThemeId",storeThemeType.getThemeID());
  983. advanceTheme.put("storeThemeName",storeThemeType.getName());
  984. themeList.add(advanceTheme);
  985. i++;
  986. }
  987. result.put("storeThemeList", themeList);
  988. int j = 0;
  989. StoreColorSchemeType[] storeColorSchemeTypes = returnedAdvancedThemeArray.getGenericColorSchemeArray().getColorScheme();
  990. List<Map<String,Object>> themeColorList = FastList.newInstance();
  991. while (j < storeColorSchemeTypes.length) {
  992. Map<String,Object> advanceColorTheme = FastMap.newInstance();
  993. StoreColorSchemeType storeColorSchemeType = storeColorSchemeTypes[j];
  994. advanceColorTheme.put("storeColorSchemeId", storeColorSchemeType.getColorSchemeID());
  995. advanceColorTheme.put("storeColorName", storeColorSchemeType.getName());
  996. themeColorList.add(advanceColorTheme);
  997. j++;
  998. }
  999. result.put("storeAdvancedThemeColorOptList", themeColorList);
  1000. } else {
  1001. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveAdvancedThemeArray", resp.getErrors(0).getLongMessage());
  1002. }
  1003. //this.returnedSubscriptionArray = resp.getSubscriptionArray();
  1004. }
  1005. } catch (ApiException e) {
  1006. e.printStackTrace();
  1007. } catch (SdkSoapException e) {
  1008. e.printStackTrace();
  1009. } catch (SdkException e) {
  1010. e.printStackTrace();
  1011. }
  1012. return result;
  1013. }
  1014. public static Map<String,Object> retrieveStoreFontTheme(DispatchContext dctx, Map<String,Object> context) {
  1015. Map<String,Object> result = FastMap.newInstance();
  1016. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1017. Locale locale = (Locale) context.get("locale");
  1018. Delegator delegator = dctx.getDelegator();
  1019. GetStoreOptionsRequestType req = null;
  1020. StoreThemeArrayType returnedThemeArray = null;
  1021. GetStoreOptionsResponseType resp = null;
  1022. try {
  1023. if (context.get("productStoreId") != null) {
  1024. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  1025. req = new GetStoreOptionsRequestType();
  1026. resp = (GetStoreOptionsResponseType) call.execute(req);
  1027. Map<String,Object> advanceFontTheme = FastMap.newInstance();
  1028. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  1029. returnedThemeArray = resp.getAdvancedThemeArray();
  1030. int i = 0;
  1031. StoreColorSchemeType[] storeColorSchemeTypes = returnedThemeArray.getGenericColorSchemeArray().getColorScheme();
  1032. while (i < storeColorSchemeTypes.length) {
  1033. StoreColorSchemeType storeColorSchemeType = storeColorSchemeTypes[i];
  1034. StoreFontType storeFontType = storeColorSchemeType.getFont();
  1035. advanceFontTheme.put("storeFontTypeNameFaceColor",storeFontType.getNameColor());
  1036. int j = 0;
  1037. storeFontType.getNameFace();
  1038. StoreFontFaceCodeType[] storeFontNameFaceCodeTypes = StoreFontFaceCodeType.values();
  1039. List<Map<String,Object>> nameFaces = FastList.newInstance();
  1040. while (j < storeFontNameFaceCodeTypes.length) {
  1041. Map<String,Object> storeFontNameFaceCodeTypeMap = FastMap.newInstance();
  1042. StoreFontFaceCodeType storeFontNameFaceCodeType = storeFontNameFaceCodeTypes[j];
  1043. storeFontNameFaceCodeTypeMap.put("storeFontValue", storeFontNameFaceCodeType.value());
  1044. storeFontNameFaceCodeTypeMap.put("storeFontName", storeFontNameFaceCodeType.name());
  1045. nameFaces.add(storeFontNameFaceCodeTypeMap);
  1046. j++;
  1047. }
  1048. advanceFontTheme.put("storeFontTypeFontFaceList",nameFaces);
  1049. j = 0;
  1050. storeFontType.getNameSize();
  1051. StoreFontSizeCodeType[] storeFontSizeCodeTypes = StoreFontSizeCodeType.values();
  1052. List<Map<String,Object>> sizeFaces = FastList.newInstance();
  1053. while (j < storeFontSizeCodeTypes.length) {
  1054. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1055. StoreFontSizeCodeType storeFontSizeCodeType = storeFontSizeCodeTypes[j];
  1056. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1057. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1058. sizeFaces.add(storeFontSizeCodeTypeMap);
  1059. j++;
  1060. }
  1061. advanceFontTheme.put("storeFontTypeSizeFaceList", sizeFaces);
  1062. advanceFontTheme.put("storeFontTypeTitleColor", storeFontType.getTitleColor());
  1063. j = 0;
  1064. storeFontType.getTitleFace();
  1065. StoreFontFaceCodeType[] storeFontTypeTitleFaces = StoreFontFaceCodeType.values();
  1066. List<Map<String,Object>> titleFaces = FastList.newInstance();
  1067. while (j < storeFontTypeTitleFaces.length) {
  1068. Map<String,Object> storeFontTypeTitleFaceMap = FastMap.newInstance();
  1069. StoreFontFaceCodeType storeFontTypeTitleFace = storeFontTypeTitleFaces[j];
  1070. storeFontTypeTitleFaceMap.put("storeFontValue", storeFontTypeTitleFace.value());
  1071. storeFontTypeTitleFaceMap.put("storeFontName", storeFontTypeTitleFace.name());
  1072. titleFaces.add(storeFontTypeTitleFaceMap);
  1073. j++;
  1074. }
  1075. advanceFontTheme.put("storeFontTypeFontTitleList",titleFaces);
  1076. j = 0;
  1077. storeFontType.getTitleSize();
  1078. StoreFontSizeCodeType[] storeTitleSizeCodeTypes = StoreFontSizeCodeType.values();
  1079. List<Map<String,Object>> titleSizes = FastList.newInstance();
  1080. while (j < storeTitleSizeCodeTypes.length) {
  1081. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1082. StoreFontSizeCodeType storeFontSizeCodeType = storeTitleSizeCodeTypes[j];
  1083. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1084. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1085. titleSizes.add(storeFontSizeCodeTypeMap);
  1086. j++;
  1087. }
  1088. advanceFontTheme.put("storeFontSizeTitleList",titleSizes);
  1089. advanceFontTheme.put("storeFontTypeDescColor", storeFontType.getDescColor());
  1090. j = 0;
  1091. storeFontType.getDescFace();
  1092. StoreFontFaceCodeType[] storeFontTypeDescFaces = StoreFontFaceCodeType.values();
  1093. List<Map<String,Object>> descFaces = FastList.newInstance();
  1094. while (j < storeFontTypeDescFaces.length) {
  1095. Map<String,Object> storeFontTypeDescFaceMap = FastMap.newInstance();
  1096. StoreFontFaceCodeType storeFontTypeDescFace = storeFontTypeDescFaces[j];
  1097. storeFontTypeDescFaceMap.put("storeFontValue", storeFontTypeDescFace.value());
  1098. storeFontTypeDescFaceMap.put("storeFontName", storeFontTypeDescFace.name());
  1099. descFaces.add(storeFontTypeDescFaceMap);
  1100. j++;
  1101. }
  1102. advanceFontTheme.put("storeFontTypeFontDescList",descFaces);
  1103. j = 0;
  1104. storeFontType.getDescSize();
  1105. StoreFontSizeCodeType[] storeDescSizeCodeTypes = StoreFontSizeCodeType.values();
  1106. List<Map<String,Object>> descSizes = FastList.newInstance();
  1107. while (j < storeDescSizeCodeTypes.length) {
  1108. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1109. StoreFontSizeCodeType storeFontSizeCodeType = storeDescSizeCodeTypes[j];
  1110. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1111. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1112. descSizes.add(storeFontSizeCodeTypeMap);
  1113. j++;
  1114. }
  1115. advanceFontTheme.put("storeDescSizeList",descSizes);
  1116. i++;
  1117. }
  1118. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreLoadBasicThemeSuccess", locale));
  1119. result.put("advanceFontTheme", advanceFontTheme);
  1120. } else {
  1121. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveStoreFontTheme", resp.getErrors(0).getLongMessage());
  1122. }
  1123. }
  1124. } catch (ApiException e) {
  1125. e.printStackTrace();
  1126. } catch (SdkSoapException e) {
  1127. e.printStackTrace();
  1128. } catch (SdkException e) {
  1129. e.printStackTrace();
  1130. }
  1131. return result;
  1132. }
  1133. public static Map<String,Object> setEbayStoreInput(DispatchContext dctx, Map<String,Object> context) {
  1134. Map<String,Object> result = FastMap.newInstance();
  1135. Locale locale = (Locale) context.get("locale");
  1136. Delegator delegator = dctx.getDelegator();
  1137. SetStoreRequestType req = null;
  1138. SetStoreResponseType resp = null;
  1139. StoreType storeType = null;
  1140. try {
  1141. if (context.get("productStoreId") != null) {
  1142. SetStoreCall call = new SetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  1143. req = new SetStoreRequestType();
  1144. storeType = new StoreType();
  1145. storeType.setName((String)context.get("storeName"));
  1146. storeType.setDescription((String)context.get("storeDesc"));
  1147. storeType.setURL((String)context.get("storeUrl"));
  1148. storeType.setURLPath("");
  1149. StoreLogoType storeLogo = new StoreLogoType();
  1150. if (context.get("storeLogoURL") == null) {
  1151. if (context.get("storeLogoId") != null) storeLogo.setLogoID(Integer.parseInt((String)context.get("storeLogoId")));
  1152. storeLogo.setName((String)context.get("storeLogoName"));
  1153. } else {
  1154. storeLogo.setURL((String)context.get("storeLogoURL"));
  1155. }
  1156. storeType.setLogo(storeLogo);
  1157. StoreThemeType storeTheme = new StoreThemeType();
  1158. StoreColorSchemeType storeColorScheme = null;
  1159. StoreColorType storecolor = null;
  1160. StoreFontType storeFont = null;
  1161. if (context.get("themeType").equals("Advanced")) {
  1162. storeColorScheme = new StoreColorSchemeType();
  1163. if (context.get("storeAdvancedThemeColor") != null) storeColorScheme.setColorSchemeID(Integer.parseInt((String)context.get("storeAdvancedThemeColor")));
  1164. storecolor = new StoreColorType();
  1165. storecolor.setPrimary((String)context.get("storePrimaryColor"));
  1166. storecolor.setSecondary((String)context.get("storeSecondaryColor"));
  1167. storecolor.setAccent((String)context.get("storeAccentColor"));
  1168. storeColorScheme.setColor(storecolor);
  1169. storeTheme.setColorScheme(storeColorScheme);
  1170. storeTheme.setName(null);
  1171. storeTheme.setThemeID(Integer.parseInt((String)context.get("storeAdvancedTheme")));
  1172. } else if (context.get("themeType").equals("Basic")) {
  1173. storeColorScheme = new StoreColorSchemeType();
  1174. if (context.get("storeBasicTheme")!=null) {
  1175. String storeBasicTheme = (String)context.get("storeBasicTheme");
  1176. String storeThemeId = null;
  1177. String storeColorSchemeId = null;
  1178. if (storeBasicTheme.indexOf("-") != -1) {
  1179. storeThemeId = storeBasicTheme.substring(0, storeBasicTheme.indexOf("-"));
  1180. storeColorSchemeId = storeBasicTheme.substring(storeBasicTheme.indexOf("-")+1);
  1181. }
  1182. if (storeColorSchemeId != null) storeColorScheme.setColorSchemeID(Integer.parseInt(storeColorSchemeId));
  1183. storecolor = new StoreColorType();
  1184. storecolor.setPrimary((String)context.get("storePrimaryColor"));
  1185. storecolor.setSecondary((String)context.get("storeSecondaryColor"));
  1186. storecolor.setAccent((String)context.get("storeAccentColor"));
  1187. storeColorScheme.setColor(storecolor);
  1188. storeFont = new StoreFontType();
  1189. storeFont.setNameColor((String)context.get("storeNameFontColor"));
  1190. storeFont.setNameFace(StoreFontFaceCodeType.valueOf((String)context.get("storeNameFont")));
  1191. storeFont.setNameSize(StoreFontSizeCodeType.valueOf((String)context.get("storeNameFontSize")));
  1192. storeFont.setTitleColor((String)context.get("storeTitleFontColor"));
  1193. storeFont.setTitleFace(StoreFontFaceCodeType.valueOf((String)context.get("storeTitleFont")));
  1194. storeFont.setTitleSize(StoreFontSizeCodeType.valueOf((String)context.get("storeTitleFontSize")));
  1195. storeFont.setDescColor((String)context.get("storeDescFontColor"));
  1196. storeFont.setDescFace(StoreFontFaceCodeType.valueOf((String)context.get("storeDescFont")));
  1197. storeFont.setDescSize(StoreFontSizeCodeType.valueOf((String)context.get("storeDescFontSize")));
  1198. storeColorScheme.setFont(storeFont);
  1199. storeTheme.setColorScheme(storeColorScheme);
  1200. storeTheme.setName(null);
  1201. storeTheme.setThemeID(Integer.parseInt(storeThemeId));
  1202. }
  1203. }
  1204. storeType.setTheme(storeTheme);
  1205. storeType.setHeaderStyle(StoreHeaderStyleCodeType.valueOf((String)context.get("storeHeaderStyle")));
  1206. storeType.setItemListLayout(StoreItemListLayoutCodeType.valueOf((String)context.get("storeItemLayout")));
  1207. storeType.setItemListSortOrder(StoreItemListSortOrderCodeType.valueOf((String)context.get("storeItemSortOrder")));
  1208. storeType.setMerchDisplay(MerchDisplayCodeType.valueOf((String)context.get("storeMerchDisplay")));
  1209. storeType.setSubscriptionLevel(StoreSubscriptionLevelCodeType.valueOf((String)context.get("storeSubscriptionDisplay")));
  1210. storeType.setCustomHeader((String)context.get("storeCustomHeader"));
  1211. storeType.setCustomHeaderLayout(StoreCustomHeaderLayoutCodeType.valueOf((String)context.get("storeCustomHeaderLayout")));
  1212. if ( storeType == null )
  1213. throw new SdkException("StoreType property is not set.");
  1214. req.setStore(storeType);
  1215. resp = (SetStoreResponseType) call.execute(req);
  1216. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  1217. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreSaveSuccess",locale));
  1218. } else {
  1219. result = ServiceUtil.returnError(resp.getMessage());
  1220. }
  1221. LocalDispatcher dispatcher = dctx.getDispatcher();
  1222. Map<String,Object> results = dispatcher.runSync("getEbayStoreOutput",UtilMisc.toMap("productStoreId",(String) context.get("productStoreId"),"userLogin",context.get("userLogin")));
  1223. if (results != null) {
  1224. result.put("ebayStore", results.get("ebayStore"));
  1225. }
  1226. }
  1227. } catch (ApiException e) {
  1228. result = ServiceUtil.returnError(e.getMessage());
  1229. } catch (SdkSoapException e) {
  1230. result = ServiceUtil.returnError(e.getMessage());
  1231. } catch (SdkException e) {
  1232. result = ServiceUtil.returnError(e.getMessage());
  1233. } catch (GenericServiceException e) {
  1234. result = ServiceUtil.returnError(e.getMessage());
  1235. }
  1236. return result;
  1237. }
  1238. public static Map<String, Object> getEbayActiveItems(DispatchContext dctx, Map<String, ? extends Object> context) {
  1239. Map<String, Object> result = FastMap.newInstance();
  1240. Delegator delegator = dctx.getDelegator();
  1241. Locale locale = (Locale) context.get("locale");
  1242. String productStoreId = (String) context.get("productStoreId");
  1243. List<Map<String, Object>> activeItems = FastList.newInstance();
  1244. try {
  1245. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1246. GetMyeBaySellingCall getMyeBaySellingCall = new GetMyeBaySellingCall(apiContext);
  1247. ItemListCustomizationType activeList = new ItemListCustomizationType();
  1248. getMyeBaySellingCall.setActiveList(activeList );
  1249. DetailLevelCodeType[] level = {DetailLevelCodeType.RETURN_ALL};
  1250. getMyeBaySellingCall.setDetailLevel(level);
  1251. getMyeBaySellingCall.getMyeBaySelling();
  1252. PaginatedItemArrayType itemListCustomizationType = getMyeBaySellingCall.getReturnedActiveList();
  1253. if (itemListCustomizationType != null) {
  1254. ItemArrayType itemArrayType = itemListCustomizationType.getItemArray();
  1255. int itemArrayTypeSize = itemArrayType.getItemLength();
  1256. for (int i = 0; i < itemArrayTypeSize; i++) {
  1257. Map<String, Object> entry = FastMap.newInstance();
  1258. ItemType item = itemArrayType.getItem(i);
  1259. entry.put("itemId", item.getItemID());
  1260. entry.put("title", item.getTitle());
  1261. if (item.getPictureDetails() != null) {
  1262. String url[] = item.getPictureDetails().getPictureURL();
  1263. if (url.length != 0) {
  1264. entry.put("pictureURL", url[0]);
  1265. } else {
  1266. entry.put("pictureURL", null);
  1267. }
  1268. } else {
  1269. entry.put("pictureURL", null);
  1270. }
  1271. entry.put("timeLeft",item.getTimeLeft());
  1272. if (item.getBuyItNowPrice() != null) {
  1273. entry.put("buyItNowPrice", item.getBuyItNowPrice().getValue());
  1274. } else {
  1275. entry.put("buyItNowPrice", null);
  1276. }
  1277. if (item.getStartPrice() != null) {
  1278. entry.put("startPrice", item.getStartPrice().getValue());
  1279. } else {
  1280. entry.put("startPrice", null);
  1281. }
  1282. if (item.getListingDetails() != null) {
  1283. entry.put("relistedItemId", item.getListingDetails().getRelistedItemID());
  1284. } else {
  1285. entry.put("relistedItemId", null);
  1286. }
  1287. if (item.getListingType() != null) {
  1288. entry.put("listingType", item.getListingType().value());
  1289. } else {
  1290. entry.put("listingType", null);
  1291. }
  1292. activeItems.add(entry);
  1293. }
  1294. }
  1295. result.put("activeItems", activeItems);
  1296. } catch (Exception e) {
  1297. // TODO Auto-generated catch block
  1298. return ServiceUtil.returnError(e.getMessage());
  1299. }
  1300. return result;
  1301. }
  1302. public static Map<String, Object> getEbaySoldItems(DispatchContext dctx, Map<String, ? extends Object> context) {
  1303. Map<String, Object> result = FastMap.newInstance();
  1304. Delegator delegator = dctx.getDelegator();
  1305. Locale locale = (Locale) context.get("locale");
  1306. String productStoreId = (String) context.get("productStoreId");
  1307. String filter = (String) context.get("filter");
  1308. String itemId = (String) context.get("itemId");
  1309. String buyerId = (String) context.get("buyerId");
  1310. List<Map<String, Object>> soldItems = FastList.newInstance();
  1311. double reservPrice = 0;
  1312. try {
  1313. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1314. GetSellingManagerSoldListingsCall sellingManagerSoldListings = new GetSellingManagerSoldListingsCall(apiContext);
  1315. if (UtilValidate.isNotEmpty(filter)) {
  1316. SellingManagerSoldListingsPropertyTypeCodeType[] filterObject = {SellingManagerSoldListingsPropertyTypeCodeType.valueOf(filter)};
  1317. sellingManagerSoldListings.setFilter(filterObject );
  1318. }
  1319. if (UtilValidate.isNotEmpty(itemId)) {
  1320. SellingManagerSearchType search = new SellingManagerSearchType();
  1321. search.setSearchType(SellingManagerSearchTypeCodeType.ITEM_ID);
  1322. search.setSearchValue(itemId);
  1323. sellingManagerSoldListings.setSearch(search);
  1324. }
  1325. if (UtilValidate.isNotEmpty(buyerId)) {
  1326. SellingManagerSearchType search = new SellingManagerSearchType();
  1327. search.setSearchType(SellingManagerSearchTypeCodeType.BUYER_USER_ID);
  1328. search.setSearchValue(buyerId);
  1329. sellingManagerSoldListings.setSearch(search);
  1330. }
  1331. sellingManagerSoldListings.getSellingManagerSoldListings();
  1332. SellingManagerSoldOrderType[] sellingManagerSoldOrders = sellingManagerSoldListings.getReturnedSaleRecord();
  1333. if (UtilValidate.isNotEmpty(sellingManagerSoldOrders)) {
  1334. int soldOrderLength = sellingManagerSoldOrders.length;
  1335. for (int i = 0; i < soldOrderLength; i++) {
  1336. SellingManagerSoldOrderType sellingManagerSoldOrder = sellingManagerSoldOrders[i];
  1337. if (sellingManagerSoldOrder != null) {
  1338. SellingManagerSoldTransactionType[] sellingManagerSoldTransactions = sellingManagerSoldOrder.getSellingManagerSoldTransaction();
  1339. int sellingManagerSoldTransactionLength = sellingManagerSoldTransactions.length;
  1340. for (int j = 0; j < sellingManagerSoldTransactionLength; j++) {
  1341. Map<String, Object> entry = FastMap.newInstance();
  1342. SellingManagerSoldTransactionType sellingManagerSoldTransaction = sellingManagerSoldTransactions[j];
  1343. entry.put("itemId", sellingManagerSoldTransaction.getItemID());
  1344. entry.put("title", sellingManagerSoldTransaction.getItemTitle());
  1345. entry.put("transactionId", sellingManagerSoldTransaction.getTransactionID().toString());
  1346. entry.put("quantity", sellingManagerSoldTransaction.getQuantitySold());
  1347. entry.put("listingType", sellingManagerSoldTransaction.getListingType().value());
  1348. String buyer = null;
  1349. if (sellingManagerSoldOrder.getBuyerID() != null) {
  1350. buyer = sellingManagerSoldOrder.getBuyerID();
  1351. }
  1352. entry.put("buyer", buyer);
  1353. String buyerEmail = null;
  1354. if (sellingManagerSoldOrder.getBuyerID() != null) {
  1355. buyerEmail = sellingManagerSoldOrder.getBuyerEmail();
  1356. }
  1357. entry.put("buyerEmail", buyerEmail);
  1358. GetItemCall api = new GetItemCall(apiContext);
  1359. api.setItemID(sellingManagerSoldTransaction.getItemID());
  1360. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1361. DetailLevelCodeType.RETURN_ALL,
  1362. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1363. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1364. };
  1365. api.setDetailLevel(detailLevels);
  1366. ItemType itemType = api.getItem();
  1367. String itemUrl = null;
  1368. entry.put("SKU", itemType.getSKU());
  1369. if (UtilValidate.isNotEmpty(itemType.getReservePrice())) reservPrice = itemType.getReservePrice().getValue();
  1370. entry.put("reservePrice", reservPrice);
  1371. entry.put("hitCount", itemType.getHitCount() != null ? itemType.getHitCount() : 0);
  1372. if (itemType.getListingDetails() != null) {
  1373. itemUrl = itemType.getListingDetails().getViewItemURL();
  1374. }
  1375. entry.put("itemUrl", itemUrl);
  1376. String itemUrlNatural = null;
  1377. if (itemType.getListingDetails() != null) {
  1378. itemUrlNatural = itemType.getListingDetails().getViewItemURLForNaturalSearch();
  1379. }
  1380. entry.put("itemUrlNatural", itemUrlNatural);
  1381. String unpaidItemStatus = null;
  1382. if (sellingManagerSoldOrder.getUnpaidItemStatus() != null) {
  1383. unpaidItemStatus = sellingManagerSoldOrder.getUnpaidItemStatus().value();
  1384. }
  1385. entry.put("unpaidItemStatus", unpaidItemStatus);
  1386. Date creationTime = null;
  1387. if (sellingManagerSoldOrder.getCreationTime() != null) {
  1388. creationTime = sellingManagerSoldOrder.getCreationTime().getTime();
  1389. }
  1390. entry.put("creationTime", creationTime);
  1391. double totalAmount = 0;
  1392. if (sellingManagerSoldOrder.getTotalAmount() != null) {
  1393. totalAmount = sellingManagerSoldOrder.getTotalAmount().getValue();
  1394. }
  1395. entry.put("totalAmount", totalAmount);
  1396. if (sellingManagerSoldOrder.getSalePrice() != null) {
  1397. entry.put("salePrice", sellingManagerSoldOrder.getSalePrice().getValue());
  1398. }
  1399. Date paidTime = null;
  1400. String checkoutStatus = null;
  1401. String shippedStatus = null;
  1402. Date shippedTime = null;
  1403. if (sellingManagerSoldOrder.getOrderStatus() != null) {
  1404. if (sellingManagerSoldOrder.getOrderStatus().getPaidTime() != null) {
  1405. paidTime = sellingManagerSoldOrder.getOrderStatus().getPaidTime().getTime();
  1406. }
  1407. if (sellingManagerSoldOrder.getOrderStatus().getCheckoutStatus() != null) {
  1408. checkoutStatus = sellingManagerSoldOrder.getOrderStatus().getCheckoutStatus().value();
  1409. }
  1410. if (sellingManagerSoldOrder.getOrderStatus().getShippedStatus() != null) {
  1411. shippedStatus = sellingManagerSoldOrder.getOrderStatus().getShippedStatus().value();
  1412. }
  1413. if (sellingManagerSoldOrder.getOrderStatus().getShippedTime() != null) {
  1414. shippedTime = sellingManagerSoldOrder.getOrderStatus().getShippedTime().getTime();
  1415. }
  1416. }
  1417. entry.put("paidTime", paidTime);
  1418. entry.put("checkoutStatus", checkoutStatus);
  1419. entry.put("shippedStatus", shippedStatus);
  1420. entry.put("shippedTime", shippedTime);
  1421. soldItems.add(entry);
  1422. }
  1423. }
  1424. }
  1425. }
  1426. result.put("soldItems", soldItems);
  1427. } catch (Exception e) {
  1428. return ServiceUtil.returnError(e.getMessage());
  1429. }
  1430. return result;
  1431. }
  1432. public static Map<String, Object> exportProductsFromEbayStore(DispatchContext dctx, Map<String, Object> context) {
  1433. Map<String,Object> result = FastMap.newInstance();
  1434. Delegator delegator = dctx.getDelegator();
  1435. LocalDispatcher dispatcher = dctx.getDispatcher();
  1436. Map<String, Object> eBayConfigResult = EbayHelper.buildEbayConfig(context, delegator);
  1437. Map<String, Object> response = null;
  1438. try {
  1439. GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", context.get("productId").toString()));
  1440. int intAtp = 1;
  1441. String facilityId = "";
  1442. if (UtilValidate.isNotEmpty(context.get("requireEbayInventory")) && "on".equals(context.get("requireEbayInventory").toString())) {
  1443. GenericValue ebayProductStore = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("EbayProductStoreInventory", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(), "productId", context.get("productId")))));
  1444. if (UtilValidate.isNotEmpty(ebayProductStore)) {
  1445. facilityId = ebayProductStore.getString("facilityId");
  1446. BigDecimal atp = ebayProductStore.getBigDecimal("availableToPromiseListing");
  1447. intAtp = atp.intValue();
  1448. if (intAtp == 0) {
  1449. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1450. result.put(ModelService.ERROR_MESSAGE, "ATP is not enough, can not create listing.");
  1451. }
  1452. }
  1453. }
  1454. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1455. if (UtilValidate.isNotEmpty(context.get("productCategoryId"))) {
  1456. GenericValue prodCategoryMember = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", context.get("productCategoryId"),"productId", context.get("productId")))));
  1457. if (UtilValidate.isNotEmpty(prodCategoryMember)) {
  1458. GenericValue prodCategoryRole = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId", prodCategoryMember.get("productCategoryId").toString(), "partyId", userLogin.get("partyId"),"roleTypeId", "EBAY_ACCOUNT"))));
  1459. if (UtilValidate.isNotEmpty(prodCategoryRole)) {
  1460. context.put("ebayCategory", prodCategoryRole.get("comments"));
  1461. } else {
  1462. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1463. result.put(ModelService.ERROR_MESSAGE, "Category not found for this product on ebay.");
  1464. }
  1465. }
  1466. } else {
  1467. List<GenericValue> prodCategoryMember = EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productId", context.get("productId"))));
  1468. Iterator<GenericValue> prodCategoryMemberIter = prodCategoryMember.iterator();
  1469. while (prodCategoryMemberIter.hasNext()) {
  1470. GenericValue prodCategory = prodCategoryMemberIter.next();
  1471. GenericValue prodCatalogCategory = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId"), "productCategoryId", prodCategory.get("productCategoryId").toString()))));
  1472. if (UtilValidate.isNotEmpty(prodCatalogCategory)) {
  1473. GenericValue prodCategoryRole = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId", prodCatalogCategory.get("productCategoryId").toString(), "partyId", userLogin.get("partyId"),"roleTypeId", "EBAY_ACCOUNT"))));
  1474. if (UtilValidate.isNotEmpty(prodCategoryRole)) {
  1475. context.put("ebayCategory", prodCategoryRole.get("comments"));
  1476. } else {
  1477. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1478. result.put(ModelService.ERROR_MESSAGE, "Category not found for this product on ebay.");
  1479. }
  1480. }
  1481. }
  1482. }
  1483. if (intAtp != 0) {
  1484. if (UtilValidate.isNotEmpty(context.get("listingTypeAuc")) && "on".equals(context.get("listingTypeAuc").toString())) {
  1485. context.put("listingFormat", "Chinese");
  1486. context.put("listingDuration", context.get("listingDurationAuc").toString());
  1487. StringBuffer dataItemsXml = new StringBuffer();
  1488. Map<String, Object> resultMap = ProductsExportToEbay.buildDataItemsXml(dctx, context, dataItemsXml, eBayConfigResult.get("token").toString(), product);
  1489. if (!ServiceUtil.isFailure(resultMap)) {
  1490. response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "AddItem", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
  1491. if (ServiceUtil.isFailure(response)) {
  1492. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response));
  1493. }
  1494. if (UtilValidate.isNotEmpty(response)) {
  1495. ProductsExportToEbay.exportToEbayResponse((String) response.get("successMessage"), product);
  1496. }
  1497. } else {
  1498. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap));
  1499. }
  1500. }
  1501. if (UtilValidate.isNotEmpty(context.get("listingTypeFixed")) && "on".equals(context.get("listingTypeFixed").toString())) {
  1502. context.put("listingFormat", "FixedPriceItem");
  1503. context.put("listingDuration", context.get("listingDurationFixed").toString());
  1504. StringBuffer dataItemsXml = new StringBuffer();
  1505. Map<String, Object> resultMap = ProductsExportToEbay.buildDataItemsXml(dctx, context, dataItemsXml, eBayConfigResult.get("token").toString(), product);
  1506. if (!ServiceUtil.isFailure(resultMap)) {
  1507. response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "AddItem", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
  1508. if (ServiceUtil.isFailure(response)) {
  1509. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response));
  1510. }
  1511. if (UtilValidate.isNotEmpty(response)) {
  1512. ProductsExportToEbay.exportToEbayResponse((String) response.get("successMessage"), product);
  1513. }
  1514. } else {
  1515. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap));
  1516. }
  1517. }
  1518. }
  1519. if (UtilValidate.isNotEmpty(ProductsExportToEbay.getProductExportSuccessMessageList())) {
  1520. if ((facilityId != "") && (intAtp != 0)) {
  1521. int newAtp = intAtp - 1;
  1522. Map<String,Object> inMap = FastMap.newInstance();
  1523. inMap.put("productStoreId", context.get("productStoreId").toString());
  1524. inMap.put("facilityId", facilityId);
  1525. inMap.put("productId", context.get("productId"));
  1526. inMap.put("availableToPromiseListing", new BigDecimal(newAtp));
  1527. inMap.put("userLogin", context.get("userLogin"));
  1528. dispatcher.runSync("updateEbayProductStoreInventory", inMap);
  1529. }
  1530. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
  1531. result.put(ModelService.SUCCESS_MESSAGE, "Export products listing success..");
  1532. }
  1533. if (UtilValidate.isNotEmpty(ProductsExportToEbay.getproductExportFailureMessageList())) {
  1534. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1535. result.put(ModelService.ERROR_MESSAGE_LIST, ProductsExportToEbay.getproductExportFailureMessageList());
  1536. }
  1537. }catch (Exception e) {
  1538. return ServiceUtil.returnError(e.getMessage());
  1539. }
  1540. return result;
  1541. }
  1542. public static DisputeExplanationCodeType getEbayDisputeExplanationCodeType(String disputeExplanationCode) {
  1543. DisputeExplanationCodeType disputeExplanationCodeType = null;
  1544. if (disputeExplanationCode != null) {
  1545. if (disputeExplanationCode.equals("BUYER_HAS_NOT_RESPONDED")) {
  1546. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_HAS_NOT_RESPONDED;
  1547. } else if (disputeExplanationCode.equals("BUYER_REFUSED_TO_PAY")) {
  1548. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_REFUSED_TO_PAY;
  1549. } else if (disputeExplanationCode.equals("BUYER_RETURNED_ITEM_FOR_REFUND")) {
  1550. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_RETURNED_ITEM_FOR_REFUND;
  1551. } else if (disputeExplanationCode.equals("UNABLE_TO_RESOLVE_TERMS")) {
  1552. disputeExplanationCodeType = DisputeExplanationCodeType.UNABLE_TO_RESOLVE_TERMS;
  1553. } else if (disputeExplanationCode.equals("BUYER_PURCHASING_MISTAKE")) {
  1554. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_PURCHASING_MISTAKE;
  1555. } else if (disputeExplanationCode.equals("SHIP_COUNTRY_NOT_SUPPORTED")) {
  1556. disputeExplanationCodeType = DisputeExplanationCodeType.SHIP_COUNTRY_NOT_SUPPORTED;
  1557. } else if (disputeExplanationCode.equals("SHIPPING_ADDRESS_NOT_CONFIRMED")) {
  1558. disputeExplanationCodeType = DisputeExplanationCodeType.SHIPPING_ADDRESS_NOT_CONFIRMED;
  1559. } else if (disputeExplanationCode.equals("PAYMENT_METHOD_NOT_SUPPORTED")) {
  1560. disputeExplanationCodeType = DisputeExplanationCodeType.PAYMENT_METHOD_NOT_SUPPORTED;
  1561. } else if (disputeExplanationCode.equals("BUYER_NO_LONGER_REGISTERED")) {
  1562. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_NO_LONGER_REGISTERED;
  1563. } else if (disputeExplanationCode.equals("BUYER_NO_LONGER_REGISTERED")) {
  1564. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_NO_LONGER_REGISTERED;
  1565. } else {
  1566. disputeExplanationCodeType = DisputeExplanationCodeType.OTHER_EXPLANATION;
  1567. }
  1568. } else {
  1569. disputeExplanationCodeType = DisputeExplanationCodeType.OTHER_EXPLANATION;
  1570. }
  1571. return disputeExplanationCodeType;
  1572. }
  1573. public static DisputeReasonCodeType getEbayDisputeReasonCodeType(String disputeReasonCode) {
  1574. DisputeReasonCodeType disputeReasonCodeType = null;
  1575. if (disputeReasonCode != null) {
  1576. if (disputeReasonCode.equals("TRANSACTION_MUTUALLY_CANCELED")) {
  1577. disputeReasonCodeType = DisputeReasonCodeType.TRANSACTION_MUTUALLY_CANCELED;
  1578. } else if (disputeReasonCode.equals("BUYER_HAS_NOT_PAID")) {
  1579. disputeReasonCodeType = DisputeReasonCodeType.BUYER_HAS_NOT_PAID;
  1580. }
  1581. }
  1582. return disputeReasonCodeType;
  1583. }
  1584. public static Map<String, Object> addEbayDispute(DispatchContext dctx, Map<String, ? extends Object> context) {
  1585. Map<String, Object> result = FastMap.newInstance();
  1586. Delegator delegator = dctx.getDelegator();
  1587. Locale locale = (Locale) context.get("locale");
  1588. String productStoreId = (String) context.get("productStoreId");
  1589. try {
  1590. String itemId = (String) context.get("itemId");
  1591. String transactionId = (String) context.get("transactionId");
  1592. DisputeReasonCodeType drct = EbayStore.getEbayDisputeReasonCodeType((String)context.get("disputeReasonCodeType"));
  1593. DisputeExplanationCodeType dect = EbayStore.getEbayDisputeExplanationCodeType((String) context.get("disputeExplanationCodeType"));
  1594. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1595. DetailLevelCodeType.RETURN_ALL,
  1596. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1597. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1598. };
  1599. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1600. AddDisputeCall api = new AddDisputeCall(apiContext);
  1601. api.setDetailLevel(detailLevels);
  1602. api.setItemID(itemId);
  1603. api.setTransactionID(transactionId);
  1604. api.setDisputeExplanation(dect);
  1605. api.setDisputeReason(drct);
  1606. String disputeId = api.addDispute();
  1607. result.put("disputeId", disputeId);
  1608. } catch (Exception e) {
  1609. return ServiceUtil.returnError(e.getMessage());
  1610. }
  1611. return result;
  1612. }
  1613. public static Map<String, Object> verifyEbayAddSecondChanceItem(DispatchContext dctx, Map<String, ? extends Object> context) {
  1614. Map<String, Object> result = FastMap.newInstance();
  1615. boolean checkVerify = false;
  1616. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1617. Delegator delegator = dctx.getDelegator();
  1618. Locale locale = (Locale) context.get("locale");
  1619. String productStoreId = (String) context.get("productStoreId");
  1620. String itemID = (String) context.get("itemId");
  1621. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1622. try {
  1623. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1624. DetailLevelCodeType.RETURN_ALL,
  1625. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1626. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1627. };
  1628. VerifyAddSecondChanceItemCall verify = new VerifyAddSecondChanceItemCall(apiContext);
  1629. verify.setItemID(itemID);
  1630. verify.setDetailLevel(detailLevels);
  1631. verify.setDuration(SecondChanceOfferDurationCodeType.DAYS_1);
  1632. Map<String, Object> serviceMap = FastMap.newInstance();
  1633. serviceMap.put("itemId", itemID);
  1634. serviceMap.put("productStoreId", productStoreId);
  1635. serviceMap.put("locale", locale);
  1636. serviceMap.put("userLogin", userLogin);
  1637. Map<String, Object> bidderTest = UtilGenerics.checkMap(getEbayAllBidders(dctx, serviceMap));
  1638. List<Map<String, String>> test = UtilGenerics.checkList(bidderTest.get("allBidders"));
  1639. if (test.size() != 0) {
  1640. verify.setRecipientBidderUserID(test.get(0).get("userId"));
  1641. }
  1642. result.put("checkVerify", true);
  1643. } catch (Exception e) {
  1644. result.put("checkVerify", checkVerify);
  1645. result.put("errorMessage", "This item ( " + itemID + " ) can not add second chance offer.");
  1646. result.put("responseMessage", "error");
  1647. return result;
  1648. }
  1649. return result;
  1650. }
  1651. public static Map<String, Object> getEbayAllBidders(DispatchContext dctx, Map<String, ? extends Object> context) {
  1652. Map<String, Object> result = FastMap.newInstance();
  1653. List<Map<String, Object>> allBidders = FastList.newInstance();
  1654. Delegator delegator = dctx.getDelegator();
  1655. Locale locale = (Locale) context.get("locale");
  1656. String productStoreId = (String) context.get("productStoreId");
  1657. String itemID = (String) context.get("itemId");
  1658. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1659. try {
  1660. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1661. DetailLevelCodeType.RETURN_ALL,
  1662. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1663. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1664. };
  1665. GetAllBiddersCall api = new GetAllBiddersCall(apiContext);
  1666. api.setDetailLevel(detailLevels);
  1667. api.setItemID(itemID);
  1668. api.setCallMode(GetAllBiddersModeCodeType.VIEW_ALL);
  1669. OfferType[] bidders = api.getAllBidders();
  1670. for (int count = 0; count < bidders.length; count++) {
  1671. Map<String, Object> entry = FastMap.newInstance();
  1672. OfferType offer = bidders[count];
  1673. entry.put("userId", offer.getUser().getUserID());
  1674. entry.put("bidder", offer.getUser());
  1675. allBidders.add(entry);
  1676. }
  1677. result.put("allBidders", allBidders);
  1678. } catch (Exception e) {
  1679. Debug.logError(e.getMessage(), module);
  1680. result.put("allBidders", allBidders);
  1681. return result;
  1682. }
  1683. return result;
  1684. }
  1685. public static Map<String, Object> addEbaySecondChanceOffer(DispatchContext dctx, Map<String, ? extends Object> context) {
  1686. Delegator delegator = dctx.getDelegator();
  1687. Locale locale = (Locale) context.get("locale");
  1688. String productStoreId = (String) context.get("productStoreId");
  1689. String durationString = (String) context.get("duration");
  1690. String itemID = (String) context.get("itemId");
  1691. String sellerMessage = (String) context.get("sellerMessage");
  1692. String recipientBidderUserID = (String) context.get("recipientBidderUserId");
  1693. try {
  1694. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1695. AddSecondChanceItemCall api = new AddSecondChanceItemCall(apiContext);
  1696. SecondChanceOfferDurationCodeType duration = SecondChanceOfferDurationCodeType.valueOf(durationString);
  1697. api.setDuration(duration);
  1698. AmountType buyItNowPrice = new AmountType();
  1699. if (UtilValidate.isNotEmpty((String) context.get("buyItNowPrice"))) {
  1700. buyItNowPrice.setValue(Double.parseDouble((String) context.get("buyItNowPrice")));
  1701. buyItNowPrice.setCurrencyID(CurrencyCodeType.USD);
  1702. api.setBuyItNowPrice(buyItNowPrice);
  1703. }
  1704. api.setRecipientBidderUserID(recipientBidderUserID);
  1705. api.setItemID(itemID);
  1706. api.setSellerMessage(sellerMessage);
  1707. api.addSecondChanceItem();
  1708. } catch (Exception e) {
  1709. return ServiceUtil.returnError(e.getMessage());
  1710. }
  1711. return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreAddSecondChanceOfferSuccessful", locale));
  1712. }
  1713. @SuppressWarnings("serial")
  1714. public Map<String, Object> getMyeBaySelling(DispatchContext dctx, Map<String, ? extends Object> context) {
  1715. Map<String, Object>result = FastMap.newInstance();
  1716. Delegator delegator = dctx.getDelegator();
  1717. Locale locale = (Locale) context.get("locale");
  1718. String productStoreId = (String) context.get("productStoreId");
  1719. try {
  1720. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1721. GetMyeBaySellingCall api = new GetMyeBaySellingCall(apiContext);
  1722. ItemListCustomizationType itemListType = new ItemListCustomizationType();
  1723. itemListType.setInclude(Boolean.TRUE);
  1724. itemListType.setIncludeNotes(Boolean.TRUE);
  1725. itemListType.setSort(ItemSortTypeCodeType.ITEM_ID_DESCENDING);
  1726. String entriesPerPage = (String) context.get("entriesPerPage");
  1727. String pageNumber = (String) context.get("pageNumber");
  1728. String listingType = (String) context.get("listingType");
  1729. PaginationType page = new PaginationType();
  1730. if (UtilValidate.isNotEmpty(entriesPerPage)) {
  1731. page.setEntriesPerPage(Integer.valueOf(entriesPerPage));
  1732. }
  1733. if (UtilValidate.isNotEmpty(pageNumber)) {
  1734. page.setPageNumber(Integer.valueOf(pageNumber));
  1735. }
  1736. itemListType.setPagination(page);
  1737. if (UtilValidate.isNotEmpty(listingType)) {
  1738. itemListType.setListingType(ListingTypeCodeType.valueOf(listingType));
  1739. } else {
  1740. itemListType.setListingType(ListingTypeCodeType.FIXED_PRICE_ITEM);
  1741. }
  1742. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1743. DetailLevelCodeType.RETURN_ALL,
  1744. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1745. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1746. };
  1747. api.setDetailLevel(detailLevels);
  1748. api.setActiveList(itemListType);
  1749. api.setScheduledList(itemListType);
  1750. api.setSoldList(itemListType);
  1751. api.setUnsoldList(itemListType);
  1752. api.getMyeBaySelling();
  1753. ItemType[] tempActiveItems = null;
  1754. if (api.getReturnedActiveList() != null) tempActiveItems = (api.getReturnedActiveList().getItemArray()).getItem();
  1755. final ItemType[] activeItems = tempActiveItems;
  1756. // Display active items in table.
  1757. AbstractTableModel dataModel = new AbstractTableModel() {
  1758. public int getColumnCount() { return 0; }
  1759. public int getRowCount() { return activeItems == null ? 0 : activeItems.length;}
  1760. public Map<String, Object> getValueAt(int row, int col) {
  1761. ItemType item = activeItems[row];
  1762. return itemToColumns(item);
  1763. }
  1764. };
  1765. //add To List
  1766. List<Map<Object, Object>> activeList = getDataModelToList(dataModel);
  1767. int activeSize = dataModel.getRowCount();
  1768. ItemType[] tempItems = null;
  1769. if (api.getReturnedScheduledList() != null) tempItems = (api.getReturnedScheduledList().getItemArray()).getItem();
  1770. final ItemType[] scheItems = tempItems;
  1771. // Display Scheduled items in table.
  1772. dataModel = new AbstractTableModel() {
  1773. public int getColumnCount() { return 0; }
  1774. public int getRowCount() { return scheItems == null ? 0 : scheItems.length;}
  1775. public Map<String, Object> getValueAt(int row, int col) {
  1776. ItemType item = scheItems[row];
  1777. return schItemToColumns(item);
  1778. }
  1779. };
  1780. // set data
  1781. List<Map<Object, Object>> scheduledList = getDataModelToList(dataModel);
  1782. int scheduledSize = dataModel.getRowCount();
  1783. OrderTransactionType[] tempSoldItems = null;
  1784. if (UtilValidate.isNotEmpty(api.getReturnedSoldList())) tempSoldItems = (api.getReturnedSoldList().getOrderTransactionArray()).getOrderTransaction();
  1785. // add to list
  1786. List<Map<String, Object>> soldList = FastList.newInstance();
  1787. if (UtilValidate.isNotEmpty(tempSoldItems)) {
  1788. soldList = EbayStore.getOrderTransactions(tempSoldItems);
  1789. }
  1790. int soldSize = tempSoldItems == null ? 0 : tempSoldItems.length;
  1791. ItemType[] tempUnSoldItems = null;
  1792. if (UtilValidate.isNotEmpty(api.getReturnedUnsoldList())) tempUnSoldItems = (api.getReturnedUnsoldList().getItemArray()).getItem();
  1793. final ItemType[] unSoldItems = tempUnSoldItems;
  1794. // Display unsold items in table.
  1795. dataModel = new AbstractTableModel() {
  1796. public int getColumnCount() { return 0; }
  1797. public int getRowCount() { return unSoldItems == null ? 0 : unSoldItems.length;}
  1798. public Map<String, Object> getValueAt(int row, int col) {
  1799. ItemType item = unSoldItems[row];
  1800. return unsoldItemToColumns(item);
  1801. }
  1802. };
  1803. // add to list
  1804. List<Map<Object, Object>> unsoldList = getDataModelToList(dataModel);
  1805. int unsoldSize = dataModel.getRowCount();
  1806. //list to result
  1807. result.put("activeItems", activeList);
  1808. result.put("soldItems", soldList);
  1809. result.put("unsoldItems", unsoldList);
  1810. result.put("scheduledItems", scheduledList);
  1811. //page control to result;
  1812. result.put("activeSize", activeSize);
  1813. result.put("soldSize", soldSize);
  1814. result.put("unsoldeSize", unsoldSize);
  1815. result.put("scheduledSize", scheduledSize);
  1816. } catch (Exception e) {
  1817. return ServiceUtil.returnError(e.getMessage());
  1818. }
  1819. return result;
  1820. }
  1821. // set output data list (MyeBaySelling)
  1822. public List<Map<Object, Object>> getDataModelToList(TableModel dataModel) {
  1823. List<Map<Object, Object>> list = FastList.newInstance();
  1824. for (int rowIndex = 0; rowIndex < dataModel.getRowCount(); rowIndex++) {
  1825. list.add(UtilGenerics.checkMap(dataModel.getValueAt(rowIndex, 0)));
  1826. }
  1827. return list;
  1828. }
  1829. static Map<String, Object> itemToColumns(ItemType item) {
  1830. Map<String, Object> cols = FastMap.newInstance();
  1831. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1832. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1833. SellingStatusType sst = item.getSellingStatus();
  1834. double currentPrice = 0;
  1835. int bidCount = 0;
  1836. double reservPrice = 0;
  1837. if (UtilValidate.isNotEmpty(sst)) {
  1838. AmountType amt = sst.getCurrentPrice();
  1839. currentPrice = amt != null ? (new Double(amt.getValue())) : 0;
  1840. bidCount = sst.getBidCount() != null ? sst.getBidCount() : 0;
  1841. }
  1842. cols.put("buyItNowPrice", item.getBuyItNowPrice().getValue());
  1843. cols.put("currentPrice", currentPrice);
  1844. cols.put("bidCount", bidCount);
  1845. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1846. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1847. Integer quantity = item.getQuantity();
  1848. String quantityStr = null;
  1849. if (UtilValidate.isNotEmpty(quantity)) quantityStr = quantity.toString();
  1850. cols.put("quantity", quantityStr);
  1851. cols.put("listingType", item.getListingType().value());
  1852. cols.put("viewItemURL", item.getListingDetails().getViewItemURL());
  1853. cols.put("SKU", item.getSKU());
  1854. if (UtilValidate.isNotEmpty(item.getReservePrice())) reservPrice = item.getReservePrice().getValue();
  1855. cols.put("reservePrice", reservPrice);
  1856. cols.put("hitCount", item.getHitCount() != null ? item.getHitCount() : 0);
  1857. return cols;
  1858. }
  1859. static Map<String, Object> schItemToColumns(ItemType item) {
  1860. Map<String, Object> cols = FastMap.newInstance();
  1861. double reservPrice = 0;
  1862. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1863. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1864. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1865. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1866. AmountType amt = item.getStartPrice();
  1867. cols.put("StartPrice", amt != null ? (new Double(amt.getValue()).toString()) : "");
  1868. Integer quantity = item.getQuantity();
  1869. String quantityStr = null;
  1870. if (UtilValidate.isNotEmpty(quantity)) {
  1871. quantityStr = quantity.toString();
  1872. }
  1873. cols.put("quantity", quantityStr);
  1874. cols.put("listingType", item.getListingType().value());
  1875. cols.put("SKU", item.getSKU());
  1876. if (UtilValidate.isNotEmpty(item.getReservePrice())) reservPrice = item.getReservePrice().getValue();
  1877. cols.put("reservePrice", reservPrice);
  1878. cols.put("hitCount", item.getHitCount() != null ? item.getHitCount() : 0);
  1879. return cols;
  1880. }
  1881. static Map<String, Object> unsoldItemToColumns(ItemType item) {
  1882. Map<String, Object> cols = FastMap.newInstance();
  1883. double reservPrice = 0;
  1884. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1885. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1886. AmountType amt = item.getStartPrice();
  1887. cols.put("price", amt != null ? (new Double(amt.getValue()).toString()) : "");
  1888. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1889. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1890. java.util.Calendar endTime = item.getListingDetails() == null ? null : item.getListingDetails().getEndTime();
  1891. cols.put("endTime", endTime != null ? eBayUtil.toAPITimeString(endTime.getTime()) : "");
  1892. Integer quantity = item.getQuantity();
  1893. String quantityStr = null;
  1894. if (UtilValidate.isNotEmpty(quantity)) {
  1895. quantityStr = quantity.toString();
  1896. }
  1897. cols.put("quantity", quantityStr);
  1898. cols.put("listingType", item.getListingType().value());
  1899. cols.put("SKU", item.getSKU());
  1900. if (UtilValidate.isNotEmpty(item.getReservePrice())) reservPrice = item.getReservePrice().getValue();
  1901. cols.put("reservePrice", reservPrice);
  1902. cols.put("hitCount", item.getHitCount() != null ? item.getHitCount() : 0);
  1903. return cols;
  1904. }
  1905. public static List<Map<String, Object>> getOrderTransactions(OrderTransactionType[] orderTrans) {
  1906. List<Map<String, Object>> colsList = FastList.newInstance();
  1907. OrderTransactionType orderTran = null;
  1908. OrderType order = null;
  1909. TransactionType transaction= null;
  1910. for (int rowIndex = 0; rowIndex < orderTrans.length; rowIndex++) {
  1911. orderTran = orderTrans[rowIndex];
  1912. order = orderTran.getOrder();
  1913. transaction = orderTran.getTransaction();
  1914. if (UtilValidate.isNotEmpty(order)) {
  1915. TransactionType[] trans = order.getTransactionArray().getTransaction();
  1916. String orderId = order.getOrderID();
  1917. for (int rowIndex1 = 0; rowIndex1 < trans.length; rowIndex1++) {
  1918. Map<String, Object> transactionMap = EbayStore.getTransaction(trans[rowIndex1]);
  1919. transactionMap.put("orderId", orderId);
  1920. colsList.add(transactionMap);
  1921. }
  1922. } else {
  1923. colsList.add(EbayStore.getTransaction(transaction));
  1924. }
  1925. }
  1926. return colsList;
  1927. }
  1928. public static Map<String, Object> getTransaction(TransactionType transaction){
  1929. Map<String, Object> cols = FastMap.newInstance();
  1930. ItemType item = transaction.getItem();
  1931. String itemId = null;
  1932. String title = null;
  1933. String SKU = null;
  1934. if (UtilValidate.isNotEmpty(item)) {
  1935. itemId = item.getItemID();
  1936. title = item.getTitle();
  1937. SKU = item.getSKU();
  1938. }
  1939. cols.put("itemId", itemId);
  1940. cols.put("title", title);
  1941. cols.put("SKU", SKU);
  1942. UserType buyer = transaction.getBuyer();
  1943. String user = null;
  1944. if (UtilValidate.isNotEmpty(buyer)) user = buyer.getUserID();
  1945. cols.put("buyer", user);
  1946. cols.put("listingType", item.getListingType().value());
  1947. Date paidTime = null;
  1948. String checkoutStatus = null;
  1949. String eBayPaymentStatus = null;
  1950. String completeStatus = null;
  1951. String buyerPaidStatus = null;
  1952. Date shippedTime = null;
  1953. String transactionId = null;
  1954. double totalPrice = 0;
  1955. double transactionPrice = 0;
  1956. Date createdDate = null;
  1957. String sellerPaidStatus = null;
  1958. String orderId = null;
  1959. double adjustmentAmount = 0;
  1960. double amountPaid = 0;
  1961. if (UtilValidate.isNotEmpty(transaction.getStatus())) {
  1962. if (UtilValidate.isNotEmpty(transaction.getStatus().getCheckoutStatus())) {
  1963. checkoutStatus = transaction.getStatus().getCheckoutStatus().value();
  1964. }
  1965. if (UtilValidate.isNotEmpty(transaction.getStatus().getEBayPaymentStatus())) {
  1966. eBayPaymentStatus = transaction.getStatus().getEBayPaymentStatus().value();
  1967. }
  1968. if (UtilValidate.isNotEmpty(transaction.getStatus().getCompleteStatus())) {
  1969. completeStatus = transaction.getStatus().getCompleteStatus().value();
  1970. }
  1971. }
  1972. if (UtilValidate.isNotEmpty(transaction.getBuyerPaidStatus())) {
  1973. buyerPaidStatus = transaction.getBuyerPaidStatus().value();
  1974. }
  1975. if (UtilValidate.isNotEmpty(transaction.getPaidTime())) {
  1976. paidTime = transaction.getPaidTime().getTime();
  1977. }
  1978. if (UtilValidate.isNotEmpty(transaction.getShippedTime())) {
  1979. shippedTime = transaction.getShippedTime().getTime();
  1980. }
  1981. if (UtilValidate.isNotEmpty(transaction.getTransactionID())) {
  1982. transactionId = transaction.getTransactionID().toString();
  1983. }
  1984. if (UtilValidate.isNotEmpty(transaction.getTotalPrice())) {
  1985. totalPrice = transaction.getTotalPrice().getValue();
  1986. }
  1987. if (UtilValidate.isNotEmpty(transaction.getTransactionPrice())) {
  1988. transactionPrice = transaction.getTransactionPrice().getValue();
  1989. }
  1990. if (UtilValidate.isNotEmpty(transaction.getCreatedDate())) {
  1991. createdDate = transaction.getCreatedDate().getTime();
  1992. }
  1993. if (UtilValidate.isNotEmpty(transaction.getSellerPaidStatus())) {
  1994. sellerPaidStatus = transaction.getSellerPaidStatus().value();
  1995. }
  1996. if (UtilValidate.isNotEmpty(transaction.getContainingOrder())) {
  1997. if (UtilValidate.isNotEmpty(transaction.getContainingOrder().getCheckoutStatus())) {
  1998. checkoutStatus = transaction.getContainingOrder().getCheckoutStatus().getStatus().value();
  1999. }
  2000. orderId = transaction.getContainingOrder().getOrderID();
  2001. }
  2002. if (UtilValidate.isNotEmpty(transaction.getAdjustmentAmount())) {
  2003. adjustmentAmount = transaction.getAdjustmentAmount().getValue();
  2004. }
  2005. if (UtilValidate.isNotEmpty(transaction.getAmountPaid())) {
  2006. amountPaid = transaction.getAmountPaid().getValue();
  2007. }
  2008. cols.put("amountPaid", amountPaid);
  2009. cols.put("adjustmentAmount", adjustmentAmount);
  2010. cols.put("orderId", orderId);
  2011. cols.put("checkoutStatus", checkoutStatus);
  2012. cols.put("eBayPaymentStatus", eBayPaymentStatus);
  2013. cols.put("completeStatus", completeStatus);
  2014. cols.put("buyerPaidStatus", buyerPaidStatus);
  2015. cols.put("paidTime", paidTime);
  2016. cols.put("shippedTime", shippedTime);
  2017. cols.put("quantity", transaction.getQuantityPurchased());
  2018. cols.put("transactionId", transactionId);
  2019. cols.put("transactionPrice", transactionPrice);
  2020. cols.put("totalPrice", totalPrice);
  2021. cols.put("createdDate", createdDate);
  2022. cols.put("sellerPaidStatus", sellerPaidStatus);
  2023. return cols;
  2024. }
  2025. public Map<String, Object> getEbayStoreProductItem(DispatchContext dctx, Map<String, ? extends Object> context) {
  2026. Map<String, Object>result = FastMap.newInstance();
  2027. Delegator delegator = dctx.getDelegator();
  2028. Locale locale = (Locale) context.get("locale");
  2029. String productStoreId = (String) context.get("productStoreId");
  2030. String itemID = (String) context.get("itemId");
  2031. try {
  2032. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  2033. GetItemCall api = new GetItemCall(apiContext);
  2034. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  2035. DetailLevelCodeType.RETURN_ALL,
  2036. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  2037. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  2038. };
  2039. api.setDetailLevel(detailLevels);
  2040. api.getItem(itemID);
  2041. // Set item type.
  2042. ItemType item = api.getReturnedItem();
  2043. String title = item.getTitle();
  2044. String description = item.getDescription();
  2045. String listingType = item.getListingType().value();
  2046. if (item.getPictureDetails() != null) {
  2047. String url[] = item.getPictureDetails().getPictureURL();
  2048. if (url.length != 0) {
  2049. result.put("pictureURL", url[0]);
  2050. } else {
  2051. result.put("pictureURL", null);
  2052. }
  2053. } else {
  2054. result.put("pictureURL", null);
  2055. }
  2056. result.put("title", title);
  2057. result.put("description", description);
  2058. AmountType amt = item.getStartPrice();
  2059. result.put("price", amt != null ? (new Double(amt.getValue()).toString()) : "");
  2060. result.put("currencyId", amt.getCurrencyID().toString());
  2061. result.put("listingType", listingType);
  2062. } catch (Exception e) {
  2063. return ServiceUtil.returnError(e.getMessage());
  2064. }
  2065. return result;
  2066. }
  2067. public Map<String, Object> reviseEbayStoreProductItem(DispatchContext dctx, Map<String, ? extends Object> context) {
  2068. Delegator delegator = dctx.getDelegator();
  2069. Locale locale = (Locale) context.get("locale");
  2070. String productStoreId = (String) context.get("productStoreId");
  2071. String itemID = (String) context.get("itemId");
  2072. String title = (String) context.get("title");
  2073. String description = (String) context.get("description");
  2074. String price = (String) context.get("price");
  2075. String imageFileName = (String) context.get("_imageData_fileName");
  2076. String currencyId = (String) context.get("currencyId");
  2077. try {
  2078. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  2079. String sandboxEPSURL = "https://api.sandbox.ebay.com/ws/api.dll";
  2080. apiContext.setEpsServerUrl(sandboxEPSURL);
  2081. ReviseItemCall api = new ReviseItemCall(apiContext);
  2082. // Set item type.
  2083. ItemType itemToBeRevised = new ItemType();
  2084. itemToBeRevised.setItemID(itemID);
  2085. if (UtilValidate.isNotEmpty(title)) {
  2086. itemToBeRevised.setTitle(title);
  2087. }
  2088. if (UtilValidate.isNotEmpty(description)) {
  2089. itemToBeRevised.setDescription(description);
  2090. }
  2091. // Set startPrice value.
  2092. AmountType startPrice = new AmountType();
  2093. if (UtilValidate.isNotEmpty(price)) {
  2094. startPrice.setValue(Double.parseDouble(price));
  2095. startPrice.setCurrencyID(CurrencyCodeType.valueOf(currencyId));
  2096. itemToBeRevised.setStartPrice(startPrice);
  2097. }
  2098. // Check upload image file.
  2099. if (UtilValidate.isNotEmpty(imageFileName)) {
  2100. // Upload image to ofbiz path /runtime/tmp .
  2101. ByteBuffer byteWrap = (ByteBuffer) context.get("imageData");
  2102. File file = new File(System.getProperty("ofbiz.home"), "runtime" + File.separator + "tmp" + File.separator + imageFileName);
  2103. FileChannel wChannel = new FileOutputStream(file, false).getChannel();
  2104. wChannel.write(byteWrap);
  2105. wChannel.close();
  2106. // Set path file picture to api and set picture details.
  2107. String [] pictureFiles = {System.getProperty("ofbiz.home") + File.separator + "runtime" + File.separator + "tmp" + File.separator + imageFileName};
  2108. PictureDetailsType pictureDetails = new PictureDetailsType();
  2109. pictureDetails.setGalleryType(GalleryTypeCodeType.GALLERY);
  2110. pictureDetails.setPhotoDisplay(PhotoDisplayCodeType.NONE);
  2111. pictureDetails.setPictureSource(PictureSourceCodeType.EPS);
  2112. itemToBeRevised.setPictureDetails(pictureDetails);
  2113. api.setItemToBeRevised(itemToBeRevised);
  2114. api.uploadPictures(pictureFiles, pictureDetails);
  2115. } else {
  2116. api.setItemToBeRevised(itemToBeRevised);
  2117. }
  2118. } catch (Exception e) {
  2119. return ServiceUtil.returnError(e.getMessage());
  2120. }
  2121. return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreUpdateItemSuccessfully", locale));
  2122. }
  2123. public Map<String, Object> geteBayClosedItem(DispatchContext dctx, Map<String, ? extends Object> context) {
  2124. Map <String, Object> result = FastMap.newInstance();
  2125. Delegator delegator = dctx.getDelegator();
  2126. Locale locale = (Locale) context.get("locale");
  2127. String productStoreId = (String) context.get("productStoreId");
  2128. List <Map<String, Object>> closedItems = FastList.newInstance();
  2129. try {
  2130. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  2131. ItemListCustomizationType itemListType = new ItemListCustomizationType();
  2132. itemListType.setInclude(Boolean.TRUE);
  2133. itemListType.setSort(ItemSortTypeCodeType.ITEM_ID_DESCENDING);
  2134. String entriesPerPage = (String) context.get("entriesPerPage");
  2135. String pageNumber = (String) context.get("pageNumber");
  2136. String listingType = (String) context.get("listingType");
  2137. PaginationType page = new PaginationType();
  2138. if (UtilValidate.isNotEmpty(entriesPerPage)) {
  2139. page.setEntriesPerPage(Integer.valueOf(entriesPerPage));
  2140. }
  2141. if (UtilValidate.isNotEmpty(pageNumber)) {
  2142. page.setPageNumber(Integer.valueOf(pageNumber));
  2143. }
  2144. itemListType.setPagination(page);
  2145. if (UtilValidate.isNotEmpty(listingType)) {
  2146. itemListType.setListingType(ListingTypeCodeType.valueOf(listingType));
  2147. } else {
  2148. itemListType.setListingType(ListingTypeCodeType.FIXED_PRICE_ITEM);
  2149. }
  2150. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  2151. DetailLevelCodeType.RETURN_ALL,
  2152. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  2153. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  2154. };
  2155. GetMyeBaySellingCall getMyeBaySelling = new GetMyeBaySellingCall(apiContext);
  2156. getMyeBaySelling.setDetailLevel(detailLevels);
  2157. getMyeBaySelling.setSoldList(itemListType);
  2158. getMyeBaySelling.setUnsoldList(itemListType);
  2159. getMyeBaySelling.getMyeBaySelling();
  2160. ItemType[] tempUnSoldItems = null;
  2161. if (UtilValidate.isNotEmpty(getMyeBaySelling.getReturnedUnsoldList())) tempUnSoldItems = (getMyeBaySelling.getReturnedUnsoldList().getItemArray()).getItem();
  2162. if (UtilValidate.isNotEmpty(tempUnSoldItems)) {
  2163. for (int i = 0; i < tempUnSoldItems.length; i++) {
  2164. Map <String, Object> unsoldItemMap = getClosedItem(tempUnSoldItems[i]);
  2165. unsoldItemMap.put("sellingStatus", "unsold");
  2166. closedItems.add(unsoldItemMap);
  2167. }
  2168. }
  2169. OrderTransactionType[] tempSoldItems = null;
  2170. if (UtilValidate.isNotEmpty(getMyeBaySelling.getReturnedSoldList())) tempSoldItems = (getMyeBaySelling.getReturnedSoldList().getOrderTransactionArray()).getOrderTransaction();
  2171. if (UtilValidate.isNotEmpty(tempSoldItems)) {
  2172. for(int i = 0; i < tempSoldItems.length; i++) {
  2173. ItemType soldItem = tempSoldItems[i].getTransaction().getItem();
  2174. Map <String, Object> soldItemMap = getClosedItem(soldItem);
  2175. soldItemMap.put("sellingStatus", "sold");
  2176. closedItems.add(soldItemMap);
  2177. }
  2178. }
  2179. result.put("closedItemList", closedItems);
  2180. } catch (Exception e) {
  2181. return ServiceUtil.returnError(e.getMessage());
  2182. }
  2183. return result;
  2184. }
  2185. public static Map<String ,Object> getClosedItem(ItemType tempItems) {
  2186. Map <String, Object> result = FastMap.newInstance();
  2187. if(UtilValidate.isNotEmpty(tempItems)) {
  2188. double hitCount = 0;
  2189. int quantity = 0;
  2190. int bidCount = 0;
  2191. double reservePrice = 0;
  2192. double buyItNowPrice = 0;
  2193. String listingType = null;
  2194. String endTime = null;
  2195. String viewItemURL= null;
  2196. String itemId = tempItems.getItemID();
  2197. String SKU = tempItems.getSKU();
  2198. String title = tempItems.getTitle();
  2199. result.put("itemId", itemId);
  2200. result.put("SKU", SKU);
  2201. result.put("title", title);
  2202. if(UtilValidate.isNotEmpty(tempItems.getBuyItNowPrice())) {
  2203. buyItNowPrice = tempItems.getBuyItNowPrice().getValue();
  2204. }
  2205. if(UtilValidate.isNotEmpty(tempItems.getHitCount())) {
  2206. hitCount = tempItems.getHitCount();
  2207. }
  2208. if(UtilValidate.isNotEmpty(tempItems.getReservePrice())) {
  2209. reservePrice = tempItems.getReservePrice().getValue();
  2210. }
  2211. if(UtilValidate.isNotEmpty(tempItems.getSellingStatus().getBidCount())) {
  2212. bidCount= tempItems.getSellingStatus().getBidCount();
  2213. }
  2214. if(UtilValidate.isNotEmpty(tempItems.getListingDetails().getEndTime())) {
  2215. Calendar endTimeItem = tempItems.getListingDetails().getEndTime();
  2216. endTime = eBayUtil.toAPITimeString(endTimeItem.getTime());
  2217. }
  2218. if(UtilValidate.isNotEmpty(tempItems.getListingDetails().getViewItemURL())) {
  2219. viewItemURL = tempItems.getListingDetails().getViewItemURL();
  2220. }
  2221. if(UtilValidate.isNotEmpty(tempItems.getListingType().value())) {
  2222. listingType = tempItems.getListingType().value();
  2223. }
  2224. result.put("buyItNowPrice", buyItNowPrice);
  2225. result.put("hitCount", hitCount);
  2226. result.put("quantity", quantity);
  2227. result.put("reservePrice", reservePrice);
  2228. result.put("bidCount", bidCount);
  2229. result.put("endTime", endTime);
  2230. result.put("listingType", listingType);
  2231. result.put("viewItemURL", viewItemURL);
  2232. }
  2233. return result;
  2234. }
  2235. public static Map<String, Object> getShippingDetail(AddressType shippingAddress, Locale locale) {
  2236. if(UtilValidate.isEmpty(shippingAddress)) {
  2237. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStoreRequiredShippingAddressParameter", locale));
  2238. }
  2239. Map<String, Object> result = FastMap.newInstance();
  2240. String buyerName = null;
  2241. String street = null;
  2242. String street1 = null;
  2243. String street2 = null;
  2244. String cityName = null;
  2245. String stateOrProvince = null;
  2246. String county = null;
  2247. String countryName = null;
  2248. String phone = null;
  2249. String postalCode = null;
  2250. if(UtilValidate.isNotEmpty(shippingAddress.getName())) {
  2251. buyerName = shippingAddress.getName();
  2252. }
  2253. if(UtilValidate.isNotEmpty(shippingAddress.getStreet())) {
  2254. street = shippingAddress.getStreet();
  2255. }
  2256. if(UtilValidate.isNotEmpty(shippingAddress.getStreet1())) {
  2257. street = shippingAddress.getStreet1();
  2258. }
  2259. if(UtilValidate.isNotEmpty(shippingAddress.getStreet2())) {
  2260. street = shippingAddress.getStreet2();
  2261. }
  2262. if(UtilValidate.isNotEmpty(shippingAddress.getCityName())) {
  2263. cityName = shippingAddress.getCityName();
  2264. }
  2265. if(UtilValidate.isNotEmpty(shippingAddress.getStateOrProvince())) {
  2266. stateOrProvince = shippingAddress.getStateOrProvince();
  2267. }
  2268. if(UtilValidate.isNotEmpty(shippingAddress.getCountry())) {
  2269. county = shippingAddress.getCountry().value();
  2270. }
  2271. if(UtilValidate.isNotEmpty(shippingAddress.getCountryName())) {
  2272. countryName = shippingAddress.getCountryName();
  2273. }
  2274. if(UtilValidate.isNotEmpty(shippingAddress.getPhone())) {
  2275. phone = shippingAddress.getPhone();
  2276. }
  2277. if(UtilValidate.isNotEmpty(shippingAddress.getPostalCode())) {
  2278. postalCode = shippingAddress.getPostalCode();
  2279. }
  2280. result.put("buyerName", buyerName);
  2281. result.put("shippingAddressStreet", street);
  2282. result.put("shippingAddressStreet1", street1);
  2283. result.put("shippingAddressStreet2", street2);
  2284. result.put("shippingAddressCityName", cityName);
  2285. result.put("shippingAddressStateOrProvince", stateOrProvince);
  2286. result.put("shippingAddressCountry", county);
  2287. result.put("countryName", countryName);
  2288. result.put("shippingAddressPhone", phone);
  2289. result.put("shippingAddressPostalCode", postalCode);
  2290. return result;
  2291. }
  2292. public static boolean checkExistProduct(Delegator delegator, String productId) {
  2293. boolean checkResult = false;
  2294. try {
  2295. GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
  2296. if(UtilValidate.isNotEmpty(product)) {
  2297. checkResult = true;
  2298. }
  2299. } catch(Exception e) {
  2300. return false;
  2301. }
  2302. return checkResult;
  2303. }
  2304. public static Map<String, Object> getTransactionHelper(TransactionType transaction, Locale locale) {
  2305. Map<String, Object> orderMap = FastMap.newInstance();
  2306. if(UtilValidate.isNotEmpty(transaction)) {
  2307. String orderId = null;
  2308. String externalId = null;
  2309. String createdDate = null;
  2310. String userId = null;
  2311. String itemId = null;
  2312. String title = null;
  2313. String SKU = null;
  2314. int quantityPurchased = 0;
  2315. double transactionPrice = 0;
  2316. String buyer = null;
  2317. String eiasTokenBuyer = null;
  2318. String emailBuyer = null;
  2319. String checkoutStatus = null;
  2320. String paymentMethod = null;
  2321. String viewItemURL = null;
  2322. String currency = null;
  2323. double buyItNowPrice = 0;
  2324. double amountPaid = 0.0;
  2325. String shippingService = null;
  2326. double shippingServiceCost = 0.0;
  2327. double shippingTotalAdditionalCost = 0.0;
  2328. String shippedTime = null;
  2329. String paidTime = null;
  2330. double salesTaxAmount = 0.0;
  2331. float salesTaxPercent = 0;
  2332. Map<String, Object> itemSold = FastMap.newInstance();
  2333. Map<String, Object> address = FastMap.newInstance();
  2334. if(UtilValidate.isNotEmpty(transaction.getItem())) {
  2335. ItemType item = transaction.getItem();
  2336. itemId = item.getItemID();
  2337. title = item.getTitle();
  2338. SKU = item.getSKU();
  2339. buyItNowPrice = item.getBuyItNowPrice().getValue();
  2340. currency = item.getCurrency().value();
  2341. if(UtilValidate.isNotEmpty(item.getListingDetails())) {
  2342. viewItemURL = item.getListingDetails().getViewItemURL();
  2343. }
  2344. }
  2345. externalId = transaction.getTransactionID();
  2346. if ("0".equals(externalId)) {
  2347. // this is a Chinese Auction: ItemID is used to uniquely identify the transaction
  2348. externalId = "EBS_"+itemId;
  2349. } else {
  2350. externalId = "EBS_"+externalId;
  2351. }
  2352. if (UtilValidate.isNotEmpty(transaction.getCreatedDate())) {
  2353. createdDate = EbayStoreHelper.convertDate(transaction.getCreatedDate().getTime(), locale);
  2354. }
  2355. if (UtilValidate.isNotEmpty(transaction.getShippedTime())) {
  2356. shippedTime = EbayStoreHelper.convertDate(transaction.getShippedTime().getTime(), locale);
  2357. }
  2358. if (UtilValidate.isNotEmpty(transaction.getPaidTime())) {
  2359. paidTime = EbayStoreHelper.convertDate(transaction.getPaidTime().getTime(), locale);
  2360. }
  2361. if (UtilValidate.isNotEmpty(transaction.getQuantityPurchased())) {
  2362. quantityPurchased = transaction.getQuantityPurchased();
  2363. }
  2364. if (UtilValidate.isNotEmpty(transaction.getTransactionPrice())) {
  2365. transactionPrice = transaction.getTransactionPrice().getValue();
  2366. }
  2367. if (UtilValidate.isNotEmpty(transaction.getAmountPaid())) {
  2368. amountPaid = transaction.getAmountPaid().getValue();
  2369. }
  2370. if(UtilValidate.isNotEmpty(transaction.getBuyer())) {
  2371. UserType getBuyer = transaction.getBuyer();
  2372. buyer = transaction.getBuyer().getUserID();
  2373. if (UtilValidate.isNotEmpty(getBuyer.getEmail())) {
  2374. emailBuyer = getBuyer.getEmail();
  2375. }
  2376. if (UtilValidate.isNotEmpty(getBuyer.getEIASToken())) {
  2377. eiasTokenBuyer = getBuyer.getEIASToken();
  2378. }
  2379. if (UtilValidate.isNotEmpty(getBuyer.getBuyerInfo().getShippingAddress())) {
  2380. userId = getBuyer.getUserID();
  2381. AddressType shipping = getBuyer.getBuyerInfo().getShippingAddress();
  2382. address = getShippingDetail(shipping, locale);
  2383. }
  2384. }
  2385. if(UtilValidate.isNotEmpty(transaction.getStatus())) {
  2386. if(UtilValidate.isNotEmpty(transaction.getStatus().getPaymentMethodUsed()))
  2387. paymentMethod = transaction.getStatus().getPaymentMethodUsed().value();
  2388. if(UtilValidate.isNotEmpty(transaction.getStatus().getCheckoutStatus()))
  2389. checkoutStatus = transaction.getStatus().getCheckoutStatus().value();
  2390. }
  2391. if (UtilValidate.isNotEmpty(transaction.getShippingServiceSelected())) {
  2392. ShippingServiceOptionsType shippingServiceSelect = transaction.getShippingServiceSelected();
  2393. if (UtilValidate.isNotEmpty(shippingServiceSelect.getShippingService())) {
  2394. shippingService = shippingServiceSelect.getShippingService();
  2395. }
  2396. if (UtilValidate.isNotEmpty(shippingServiceSelect.getShippingServiceCost())) {
  2397. shippingServiceCost = shippingServiceSelect.getShippingServiceCost().getValue();
  2398. }
  2399. if (UtilValidate.isNotEmpty(shippingServiceSelect.getShippingServiceAdditionalCost())) {
  2400. shippingTotalAdditionalCost = shippingServiceSelect.getShippingServiceAdditionalCost().getValue();
  2401. }
  2402. }
  2403. if (UtilValidate.isNotEmpty(transaction.getShippingDetails().getSalesTax().getSalesTaxAmount())) {
  2404. salesTaxAmount = transaction.getShippingDetails().getSalesTax().getSalesTaxAmount().getValue();
  2405. }
  2406. if (UtilValidate.isNotEmpty(transaction.getShippingDetails().getSalesTax().getSalesTaxPercent())) {
  2407. salesTaxPercent = transaction.getShippingDetails().getSalesTax().getSalesTaxPercent();
  2408. }
  2409. orderMap.put("externalId", externalId);
  2410. orderMap.put("itemId", itemId);
  2411. orderMap.put("title", title);
  2412. orderMap.put("ebayUserIdBuyer", userId);
  2413. orderMap.put("eiasTokenBuyer", eiasTokenBuyer);
  2414. orderMap.put("productId", SKU);
  2415. orderMap.put("buyItNowPrice", buyItNowPrice);
  2416. orderMap.put("currency", currency);
  2417. orderMap.put("viewItemURL", viewItemURL);
  2418. orderMap.put("orderId", orderId);
  2419. orderMap.put("createdDate", createdDate);
  2420. orderMap.put("paidTime", paidTime);
  2421. orderMap.put("transactionPrice", transactionPrice);
  2422. orderMap.put("buyer", buyer);
  2423. orderMap.put("emailBuyer", emailBuyer);
  2424. orderMap.put("checkoutStatus", checkoutStatus.substring(8));
  2425. orderMap.put("amountPaid", amountPaid);
  2426. orderMap.put("quantityPurchased", quantityPurchased);
  2427. orderMap.put("itemSold", itemSold);
  2428. orderMap.put("paymentMethod", paymentMethod);
  2429. orderMap.put("buyerName", address.get("buyerName").toString());
  2430. orderMap.put("shippingAddressCityName", address.get("shippingAddressCityName").toString());
  2431. orderMap.put("shippingAddressCountry", address.get("shippingAddressCountry").toString());
  2432. orderMap.put("countryName", address.get("countryName").toString());
  2433. orderMap.put("shippingAddressPhone", address.get("shippingAddressPhone").toString());
  2434. orderMap.put("shippingAddressPostalCode", address.get("shippingAddressPostalCode").toString());
  2435. orderMap.put("shippingAddressStateOrProvince", address.get("shippingAddressStateOrProvince").toString());
  2436. orderMap.put("shippingAddressStreet", address.get("shippingAddressStreet").toString());
  2437. if (UtilValidate.isNotEmpty(address.get("shippingAddressStreet1"))) {
  2438. orderMap.put("shippingAddressStreet1", address.get("shippingAddressStreet1").toString());
  2439. }
  2440. if (UtilValidate.isNotEmpty(address.get("shippingAddressStreet2"))) {
  2441. orderMap.put("shippingAddressStreet2", address.get("shippingAddressStreet2").toString());
  2442. }
  2443. orderMap.put("shippingService", shippingService);
  2444. orderMap.put("shippingServiceCost", shippingServiceCost);
  2445. orderMap.put("shippingTotalAdditionalCost", shippingTotalAdditionalCost);
  2446. orderMap.put("shippedTime", shippedTime);
  2447. orderMap.put("salesTaxAmount", salesTaxAmount);
  2448. orderMap.put("salesTaxPercent", salesTaxPercent);
  2449. }
  2450. return orderMap;
  2451. }
  2452. public Map<String, Object> getEbayStoreTransaction(DispatchContext dctx, Map<String, ? extends Object> context) {
  2453. Map<String, Object> result = FastMap.newInstance();
  2454. Delegator delegator = dctx.getDelegator();
  2455. Locale locale = (Locale) context.get("locale");
  2456. List<Map<String, Object>> transactionList = FastList.newInstance();
  2457. List<String> orderIdList = FastList.newInstance();
  2458. String productStoreId = (String) context.get("productStoreId");
  2459. try {
  2460. Calendar fromDate = Calendar.getInstance();
  2461. Calendar toDate = Calendar.getInstance();
  2462. if (UtilValidate.isNotEmpty(context.get("thruDate"))) {
  2463. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  2464. dateFormat.parse(context.get("fromDate").toString());
  2465. fromDate.setTime(dateFormat.parse(context.get("fromDate").toString()));
  2466. SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  2467. dateFormat2.parse(context.get("thruDate").toString());
  2468. toDate.setTime(dateFormat.parse(context.get("thruDate").toString()));
  2469. } else {
  2470. toDate.setTime(UtilDateTime.nowDate());
  2471. fromDate = null;
  2472. }
  2473. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  2474. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  2475. DetailLevelCodeType.RETURN_ALL,
  2476. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  2477. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  2478. };
  2479. GetSellerTransactionsCall getSellerTransaction = new GetSellerTransactionsCall(apiContext);
  2480. getSellerTransaction.setIncludeContainingOrder(Boolean.TRUE);
  2481. getSellerTransaction.setDetailLevel(detailLevels);
  2482. if (UtilValidate.isEmpty(fromDate)) {
  2483. getSellerTransaction.setNumberOfDays(30);
  2484. }
  2485. TimeFilter modifiedTimeFilter = new TimeFilter(fromDate, toDate);
  2486. getSellerTransaction.setModifiedTimeFilter(modifiedTimeFilter);
  2487. TransactionType[] transactions = getSellerTransaction.getSellerTransactions();
  2488. for (int tranCount = 0; tranCount < transactions.length; tranCount++) {
  2489. TransactionType transaction = transactions[tranCount];
  2490. if (UtilValidate.isNotEmpty(transaction.getContainingOrder())) {
  2491. String orderId = transaction.getContainingOrder().getOrderID();
  2492. if (!orderIdList.contains(orderId)) {
  2493. orderIdList.add(orderId);
  2494. }
  2495. continue;
  2496. }
  2497. Map<String, Object> transactionMap = EbayStore.getTransactionHelper(transaction, locale);
  2498. transactionList.add(transactionMap);
  2499. }
  2500. } catch (Exception e) {
  2501. return ServiceUtil.returnError(e.getMessage());
  2502. }
  2503. result.put("productStoreId", productStoreId);
  2504. result.put("formSelect", "transaction");
  2505. result.put("orderIdList", orderIdList);
  2506. result.put("transactionsList", transactionList);
  2507. return result;
  2508. }
  2509. public Map<String, Object> getEbayStoreOrder(DispatchContext dctx, Map<String, ? extends Object> context) {
  2510. Map<String, Object> result = FastMap.newInstance();
  2511. Delegator delegator = dctx.getDelegator();
  2512. Locale locale = (Locale) context.get("locale");
  2513. List<Map<String, Object>> orderList = FastList.newInstance();
  2514. String productStoreId = (String) context.get("productStoreId");
  2515. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  2516. try {
  2517. Calendar fromDate = Calendar.getInstance();
  2518. Calendar toDate = Calendar.getInstance();
  2519. if (UtilValidate.isNotEmpty(context.get("thruDate"))) {
  2520. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  2521. dateFormat.parse(context.get("fromDate").toString());
  2522. fromDate.setTime(dateFormat.parse(context.get("fromDate").toString()));
  2523. SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  2524. dateFormat2.parse(context.get("thruDate").toString());
  2525. toDate.setTime(dateFormat.parse(context.get("thruDate").toString()));
  2526. } else {
  2527. toDate.setTime(UtilDateTime.nowDate());
  2528. fromDate = null;
  2529. }
  2530. GetOrdersCall getOrder = new GetOrdersCall(apiContext);
  2531. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  2532. DetailLevelCodeType.RETURN_ALL,
  2533. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  2534. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  2535. };
  2536. getOrder.setDetailLevel(detailLevels);
  2537. getOrder.setCreateTimeFrom(fromDate);
  2538. getOrder.setCreateTimeTo(toDate);
  2539. getOrder.setOrderRole(TradingRoleCodeType.SELLER);
  2540. getOrder.setOrderStatus(OrderStatusCodeType.COMPLETED);
  2541. OrderType[] orders = getOrder.getOrders();
  2542. for (int orderCount = 0; orderCount < orders.length; orderCount++) {
  2543. OrderType order = orders[orderCount];
  2544. Map<String, Object> orderMap = EbayStore.getOrderHelper(order, locale);
  2545. orderList.add(orderMap);
  2546. }
  2547. } catch (Exception e) {
  2548. result = ServiceUtil.returnFailure(e.getMessage());
  2549. }
  2550. System.out.println(orderList);
  2551. result.put("productStoreId", productStoreId);
  2552. result.put("formSelect", "order");
  2553. result.put("orderList", orderList);
  2554. return result;
  2555. }
  2556. private static Map<String, Object> getOrderHelper(OrderType order, Locale locale) {
  2557. FastMap<String, Object> orderCtx = FastMap.newInstance();
  2558. String externalOrderId = "EBS_"+order.getOrderID();
  2559. double amountPaid = 0.0;
  2560. String emailBuyer = null;
  2561. String createdTime = null;
  2562. String paidTime = null;
  2563. String paymentMethod = null;
  2564. String shippedTime = null;
  2565. String shippingService = null;
  2566. String ebayUserIdBuyer = null;
  2567. String eBayPaymentStatus = null;
  2568. String status = null;
  2569. double shippingServiceCost = 0.0;
  2570. double salesTaxAmount = 0.0;
  2571. double salesTaxPercent = 0.0;
  2572. double insuranceCost = 0.0;
  2573. double insuranceFee = 0.0;
  2574. String insuranceOption = null;
  2575. boolean insuranceWanted = false;
  2576. String salesTaxState = null;
  2577. boolean shippingIncludedInTax = false;
  2578. String externalTransactionId = null;
  2579. String externalTransactionTime = null;
  2580. double feeOrCreditAmount = 0.0;
  2581. double paymentOrRefundAmount = 0.0;
  2582. Map<String, Object> shippingServiceSelectedCtx = FastMap.newInstance();
  2583. Map<String, Object> shippingDetailsCtx = FastMap.newInstance();
  2584. Map<String, Object> shippingAddressMap = FastMap.newInstance();
  2585. Map<String, Object> checkoutStatusCtx = FastMap.newInstance();
  2586. Map<String, Object> externalTransactionCtx = FastMap.newInstance();
  2587. if (UtilValidate.isNotEmpty(order.getTotal())) {
  2588. amountPaid = order.getTotal().getValue();
  2589. }
  2590. if (UtilValidate.isNotEmpty(order.getCreatedTime())) {
  2591. createdTime = EbayStoreHelper.convertDate(order.getCreatedTime().getTime(), locale);
  2592. }
  2593. if (UtilValidate.isNotEmpty(order.getPaidTime())) {
  2594. paidTime = EbayStoreHelper.convertDate(order.getPaidTime().getTime(), locale);
  2595. }
  2596. if (UtilValidate.isNotEmpty(order.getShippedTime())) {
  2597. shippedTime = EbayStoreHelper.convertDate(order.getShippedTime().getTime(), locale);
  2598. }
  2599. if (UtilValidate.isNotEmpty(order.getBuyerUserID())) {
  2600. ebayUserIdBuyer = order.getBuyerUserID();
  2601. }
  2602. if (UtilValidate.isNotEmpty(order.getShippingAddress())) {
  2603. AddressType shippingAddress = order.getShippingAddress();
  2604. shippingAddressMap = EbayStore.getShippingDetail(shippingAddress, locale);
  2605. }
  2606. if (UtilValidate.isNotEmpty(order.getShippingServiceSelected())) {
  2607. ShippingServiceOptionsType shippingServiceSelected = order.getShippingServiceSelected();
  2608. if (UtilValidate.isNotEmpty(shippingServiceSelected.getShippingService())) {
  2609. shippingService = shippingServiceSelected.getShippingService();
  2610. }
  2611. if (UtilValidate.isNotEmpty(shippingServiceSelected.getShippingServiceCost())) {
  2612. shippingServiceCost = shippingServiceSelected.getShippingServiceCost().getValue();
  2613. }
  2614. if (UtilValidate.isNotEmpty(shippingServiceSelected.getShippingInsuranceCost())) {
  2615. insuranceCost = shippingServiceSelected.getShippingInsuranceCost().getValue();
  2616. }
  2617. }
  2618. shippingServiceSelectedCtx.put("shippingService", shippingService);
  2619. shippingServiceSelectedCtx.put("shippingServiceCost", shippingServiceCost);
  2620. shippingServiceSelectedCtx.put("shippingTotalAdditionalCost", insuranceCost);
  2621. if (UtilValidate.isNotEmpty(order.getShippingDetails())) {
  2622. ShippingDetailsType shippingDetail = order.getShippingDetails();
  2623. if (UtilValidate.isNotEmpty(shippingDetail.getInsuranceFee())) {
  2624. insuranceFee = shippingDetail.getInsuranceFee().getValue();
  2625. }
  2626. if (UtilValidate.isNotEmpty(shippingDetail.getInsuranceOption())) {
  2627. insuranceOption = shippingDetail.getInsuranceOption().value();
  2628. }
  2629. if (UtilValidate.isNotEmpty(shippingDetail.isInsuranceWanted())) {
  2630. insuranceWanted = shippingDetail.isInsuranceWanted();
  2631. }
  2632. if (UtilValidate.isNotEmpty(shippingDetail.getSalesTax())) {
  2633. SalesTaxType salesTax = shippingDetail.getSalesTax();
  2634. if (UtilValidate.isNotEmpty(salesTax.getSalesTaxAmount())) {
  2635. salesTaxAmount = salesTax.getSalesTaxAmount().getValue();
  2636. }
  2637. if (UtilValidate.isNotEmpty(salesTax.getSalesTaxPercent())) {
  2638. salesTaxPercent = salesTax.getSalesTaxPercent().doubleValue();
  2639. }
  2640. if (UtilValidate.isNotEmpty(salesTax.getSalesTaxState())) {
  2641. salesTaxState = salesTax.getSalesTaxState();
  2642. }
  2643. if (UtilValidate.isNotEmpty(salesTax.isShippingIncludedInTax())) {
  2644. shippingIncludedInTax = salesTax.isShippingIncludedInTax();
  2645. }
  2646. }
  2647. }
  2648. shippingDetailsCtx.put("insuranceFee", insuranceFee);
  2649. shippingDetailsCtx.put("insuranceOption", insuranceOption);
  2650. shippingDetailsCtx.put("insuranceWanted", insuranceWanted);
  2651. shippingDetailsCtx.put("salesTaxAmount", salesTaxAmount);
  2652. shippingDetailsCtx.put("salesTaxPercent", salesTaxPercent);
  2653. shippingDetailsCtx.put("salesTaxState", salesTaxState);
  2654. shippingDetailsCtx.put("shippingIncludedInTax", shippingIncludedInTax);
  2655. if (UtilValidate.isNotEmpty(order.getCheckoutStatus())) {
  2656. CheckoutStatusType checkoutStatus = order.getCheckoutStatus();
  2657. if (UtilValidate.isNotEmpty(checkoutStatus.getEBayPaymentStatus())) {
  2658. eBayPaymentStatus = checkoutStatus.getEBayPaymentStatus().value();
  2659. }
  2660. if (UtilValidate.isNotEmpty(checkoutStatus.getStatus())) {
  2661. status = checkoutStatus.getStatus().value();
  2662. }
  2663. if (UtilValidate.isNotEmpty(checkoutStatus.getPaymentMethod())) {
  2664. paymentMethod = checkoutStatus.getPaymentMethod().value();
  2665. }
  2666. }
  2667. checkoutStatusCtx.put("eBayPaymentStatus", eBayPaymentStatus);
  2668. checkoutStatusCtx.put("paymentMethodUsed", paymentMethod);
  2669. checkoutStatusCtx.put("completeStatus", status);
  2670. if (UtilValidate.isNotEmpty(order.getExternalTransaction())) {
  2671. ExternalTransactionType[] externalTransactions = order.getExternalTransaction();
  2672. for (int count = 0; count < externalTransactions.length; count++) {
  2673. ExternalTransactionType externalTransaction = externalTransactions[count];
  2674. if (UtilValidate.isNotEmpty(externalTransaction.getExternalTransactionID())) {
  2675. externalTransactionId = externalTransaction.getExternalTransactionID();
  2676. }
  2677. if (UtilValidate.isNotEmpty(externalTransaction.getExternalTransactionTime())) {
  2678. externalTransactionTime = EbayStoreHelper.convertDate(externalTransaction.getExternalTransactionTime().getTime(), locale);
  2679. }
  2680. if (UtilValidate.isNotEmpty(externalTransaction.getFeeOrCreditAmount())) {
  2681. feeOrCreditAmount = externalTransaction.getFeeOrCreditAmount().getValue();
  2682. }
  2683. if (UtilValidate.isNotEmpty(externalTransaction.getPaymentOrRefundAmount())) {
  2684. paymentOrRefundAmount = externalTransaction.getPaymentOrRefundAmount().getValue();
  2685. }
  2686. }
  2687. }
  2688. externalTransactionCtx.put("externalTransactionID", externalTransactionId);
  2689. externalTransactionCtx.put("externalTransactionTime", externalTransactionTime);
  2690. externalTransactionCtx.put("feeOrCreditAmount", feeOrCreditAmount);
  2691. externalTransactionCtx.put("paymentOrRefundAmount", paymentOrRefundAmount);
  2692. List<Map<String, Object>> orderItemList = FastList.newInstance();
  2693. if (UtilValidate.isNotEmpty(order.getTransactionArray().getTransaction())) {
  2694. TransactionType[] transactions = order.getTransactionArray().getTransaction();
  2695. for (int tranCount = 0; tranCount < transactions.length; tranCount++) {
  2696. Map<String, Object> orderItemCtx = FastMap.newInstance();
  2697. TransactionType transaction = transactions[tranCount];
  2698. int quantityPurchased = 0;
  2699. double transactionPrice = 0.0;
  2700. String createdDate = null;
  2701. if (UtilValidate.isNotEmpty(transaction.getQuantityPurchased())) {
  2702. quantityPurchased = transaction.getQuantityPurchased();
  2703. }
  2704. if (UtilValidate.isNotEmpty(transaction.getTransactionPrice())) {
  2705. transactionPrice = transaction.getTransactionPrice().getValue();
  2706. }
  2707. if (UtilValidate.isNotEmpty(transaction.getCreatedDate())) {
  2708. createdDate = EbayStoreHelper.convertDate(transaction.getCreatedDate().getTime(), locale);
  2709. }
  2710. if (UtilValidate.isNotEmpty(transaction.getBuyer().getEmail())) {
  2711. emailBuyer = transaction.getBuyer().getEmail();
  2712. }
  2713. String itemId = null;
  2714. String productId = null;
  2715. double startPrice = 0.0;
  2716. String title = null;
  2717. if (UtilValidate.isNotEmpty(transaction.getItem())) {
  2718. ItemType item = transaction.getItem();
  2719. if (UtilValidate.isNotEmpty(item.getSKU())) {
  2720. productId = item.getSKU();
  2721. }
  2722. if (UtilValidate.isNotEmpty(item.getItemID())) {
  2723. itemId = item.getItemID();
  2724. }
  2725. if (UtilValidate.isNotEmpty(item.getStartPrice())) {
  2726. startPrice = item.getStartPrice().getValue();
  2727. }
  2728. if (UtilValidate.isNotEmpty(item.getTitle())) {
  2729. title = item.getTitle();
  2730. }
  2731. }
  2732. orderItemCtx.put("orderId", externalOrderId);
  2733. orderItemCtx.put("closedDate", createdDate);
  2734. orderItemCtx.put("goodIdentificationIdValue", itemId);
  2735. orderItemCtx.put("quantity", quantityPurchased);
  2736. orderItemCtx.put("startPrice", startPrice);
  2737. orderItemCtx.put("title", title);
  2738. orderItemCtx.put("productId", productId);
  2739. orderItemCtx.put("transactionPrice", transactionPrice);
  2740. orderItemList.add(orderItemCtx);
  2741. }
  2742. }
  2743. orderCtx.put("externalId", externalOrderId);
  2744. orderCtx.put("emailBuyer", emailBuyer);
  2745. orderCtx.put("amountPaid", amountPaid);
  2746. orderCtx.put("createdDate", createdTime);
  2747. orderCtx.put("paidTime", paidTime);
  2748. orderCtx.put("shippedTime", shippedTime);
  2749. orderCtx.put("ebayUserIdBuyer", ebayUserIdBuyer);
  2750. orderCtx.put("shippingAddressCtx", shippingAddressMap);
  2751. orderCtx.put("shippingServiceSelectedCtx", shippingServiceSelectedCtx);
  2752. orderCtx.put("shippingDetailsCtx", shippingDetailsCtx);
  2753. orderCtx.put("checkoutStatusCtx", checkoutStatusCtx);
  2754. orderCtx.put("externalTransactionCtx", externalTransactionCtx);
  2755. orderCtx.put("orderItemList", orderItemList);
  2756. return orderCtx;
  2757. }
  2758. }