Ebay component:

- updated export categories function to export and update categories on eBay store.
- updated export categories screen display only catalog in store.
- updated export categories help screen.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@903049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hans Bakker
2010-01-26 02:15:31 +00:00
parent 5670faacca
commit a79c4b32a1
5 changed files with 4 additions and 236 deletions
@@ -20,7 +20,7 @@
<title>Ebay Store Export categories to ebay store screen.</title>
<para>
The screen allow user to export categories and product to eBay store.
First you should select catalog,add your location that product located, select your default payment methods for your product and your listing duration days.
First you should select catalog and click on Export to eBay store button to complete function.
When you click Export to eBay store button, this function will add your categories that in catalog selected to eBay store also add product to categories too.</para>
</section>
-3
View File
@@ -183,9 +183,6 @@ under the License.
<description>Export categories in store to eBay store</description>
<attribute name="productStoreId" type="String" mode="IN" optional="false"/>
<attribute name="prodCatalogId" type="String" mode="IN" optional="false"/>
<attribute name="paymentMethods" type="String" mode="IN" optional="false"/>
<attribute name="listingDuration" type="String" mode="IN" optional="false"/>
<attribute name="location" type="String" mode="IN" optional="false"/>
</service>
<!-- Store output -->
+1 -1
View File
@@ -82,7 +82,7 @@ public class EbayHelper {
return ServiceUtil.returnError(errMsg);
}
if (UtilValidate.isNotEmpty(eBayConfig)) {
buildEbayConfigContext.put("devId", eBayConfig.getString("devId"));
buildEbayConfigContext.put("devID", eBayConfig.getString("devId"));
buildEbayConfigContext.put("appID", eBayConfig.getString("appId"));
buildEbayConfigContext.put("certID", eBayConfig.getString("certId"));
buildEbayConfigContext.put("token", eBayConfig.getString("token"));
+2 -207
View File
@@ -113,10 +113,7 @@ import com.ebay.soap.eBLBaseComponents.SellingManagerSoldTransactionType;
public class EbayStore {
private static final String resource = "EbayUiLabels";
private static final String configFileName = "ebayExport.properties";
private static final String module = ProductsExportToEbay.class.getName();
private static List<String> productExportSuccessMessageList = FastList.newInstance();
private static List<String> productExportFailureMessageList = FastList.newInstance();
public static ProductsExportToEbay productExportEbay = new ProductsExportToEbay();
private static void appendRequesterCredentials(Element elem, Document doc, String token) {
@@ -182,8 +179,6 @@ public class EbayStore {
public static Map exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map context) {
Locale locale = (Locale) context.get("locale");
Delegator delegator = dctx.getDelegator();
productExportSuccessMessageList.clear();
productExportFailureMessageList.clear();
Map<String, Object> result = FastMap.newInstance();
Map response = null;
Map<String, Object> eBayConfigResult = EbayHelper.buildEbayConfig(context, delegator);
@@ -195,13 +190,8 @@ public class EbayStore {
response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataStoreXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetStore", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
String successMessage = (String)response.get("successMessage");
if (successMessage != null) {
//returnResult = readEbayGetStoreCategoriesResponse(successMessage, locale);
String isSuccess = readEbayResponse(successMessage, context.get("productStoreId").toString());
if (isSuccess == "success"){
GenericValue catalogStore = null;
if(UtilValidate.isNotEmpty(context.get("productStoreId"))){
catalogStore = EntityUtil.getFirst(delegator.findByAnd("ProductStoreCatalog",UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(), "prodCatalogId", context.get("prodCatalogId").toString())));
}
List<GenericValue> catalogCategories = null;
if(UtilValidate.isNotEmpty(context.get("prodCatalogId"))){
catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString()));
@@ -223,114 +213,6 @@ public class EbayStore {
}
}
}
// Get categories list from GetStore
Map<String, Object> returnResult = FastMap.newInstance();
StringBuffer dataGetStoreXml = new StringBuffer();
Map resultStoreMap = buildGetStoreXml(context, dataGetStoreXml, eBayConfigResult.get("token").toString(), eBayConfigResult.get("siteID").toString());
if (!ServiceUtil.isFailure(resultStoreMap)) {
response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataGetStoreXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetStore", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
String successStoreMessage = (String)response.get("successMessage");
if (successStoreMessage != null) {
returnResult = readEbayGetStoreCategoriesResponse(successStoreMessage, locale);
}
}
if (returnResult.size() > 0){
List catetoriesList = FastList.newInstance();
catetoriesList = (List) returnResult.get("categories");
Iterator categoriesIter = catetoriesList.iterator();
while (categoriesIter.hasNext()) {
Map category = (Map) categoriesIter.next();
String CategoryID = category.get("CategoryID").toString();
String CategoryName = category.get("CategoryName").toString();
String CategorySeq = category.get("CategorySeq").toString();
context.put("webSiteUrl", "http://demo.ofbiz.org");
context.put("primaryCategoryId", CategoryID);
//context.put("listingDuration", "Days_1");
context.put("country", "US");
context.put("location",context.get("location").toString());
String paymentMethods = context.get("paymentMethods").toString();
context.put(""+paymentMethods, "on");
context.put("Currency", "USD");
context.put("UseTaxTable", "false");
context.put("DispatchTimeMax", "3");
GenericValue categoryFound = EntityUtil.getFirst(delegator.findByAnd("ProductCategory", UtilMisc.toMap("categoryName", CategoryName)));
if (UtilValidate.isNotEmpty(categoryFound)){
GenericValue catalogCategory = EntityUtil.getFirst(delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString(), "productCategoryId", categoryFound.get("productCategoryId").toString())));
List<GenericValue> categoryMemberList = null;
if (UtilValidate.isNotEmpty(catalogCategory)){
categoryMemberList = delegator.findByAnd("ProductCategoryMember",UtilMisc.toMap("productCategoryId", catalogCategory.get("productCategoryId").toString()));
if ((categoryMemberList == null) || (categoryMemberList.size() < 1)){
GenericValue getChildCategory = EntityUtil.getFirst(delegator.findByAnd("ProductCategoryRollup",UtilMisc.toMap("parentProductCategoryId", catalogCategory.get("productCategoryId").toString())));
if (UtilValidate.isNotEmpty(getChildCategory)){
categoryMemberList = delegator.findByAnd("ProductCategoryMember",UtilMisc.toMap("productCategoryId", getChildCategory.get("productCategoryId").toString()));
}
}
}
if (categoryMemberList != null){
Iterator categoryMemberListIter = categoryMemberList.iterator();
while (categoryMemberListIter.hasNext()) {
// build AddItem request ***
StringBuffer dataItemsXml = new StringBuffer();
GenericValue productCategoryMem = (GenericValue) categoryMemberListIter.next();
GenericValue product = productCategoryMem.getRelatedOne("Product");
GenericValue startPriceValue = EntityUtil.getFirst(EntityUtil.filterByDate(product.getRelatedByAnd("ProductPrice", UtilMisc.toMap("productPricePurposeId", "EBAY", "productPriceTypeId", "MINIMUM_PRICE"))));
if (UtilValidate.isEmpty(startPriceValue)) {
String startPriceMissingMsg = "Unable to find a starting price for auction of product with id (" + product.getString("productId") + "), So Ignoring the export of this product to eBay.";
return ServiceUtil.returnFailure(startPriceMissingMsg);
// Ignore the processing of product having no start price value
}else{
context.put("startPrice", startPriceValue.get("price").toString());
}
Map resultItem = productExportEbay.buildDataItemsXml(dctx, context, dataItemsXml, eBayConfigResult.get("token").toString(), product);
if (!ServiceUtil.isFailure(resultItem)) {
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());
String successMessage4 = (String)response.get("successMessage");
if (successMessage4 != null) {
isSuccess2 = readEbayResponse(successMessage4, context.get("productStoreId").toString());
}
if (UtilValidate.isNotEmpty(response)) {
// build ReviseItem request ***
String itemID = exportItemIDResponse((String) response.get("successMessage"));
if (itemID != ""){
StringBuffer dataRevItemsXml = new StringBuffer();
Map resultRevItem = buildReviseItemXml(dctx, context, dataRevItemsXml, eBayConfigResult.get("token").toString(), eBayConfigResult.get("siteID").toString(), itemID, CategoryID);
if (!ServiceUtil.isFailure(resultRevItem)) {
response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataRevItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "ReviseItem", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
String successMessage3 = (String)response.get("successMessage");
if (successMessage3 != null) {
isSuccess2 = readEbayResponse(successMessage3, context.get("productStoreId").toString());
}
if (ServiceUtil.isFailure(response)) {
return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response));
}
}
if (UtilValidate.isNotEmpty(productExportEbay.getProductExportSuccessMessageList())) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
result.put(ModelService.SUCCESS_MESSAGE_LIST, productExportEbay.getProductExportSuccessMessageList());
}
if (UtilValidate.isNotEmpty(productExportEbay.getproductExportFailureMessageList())) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
result.put(ModelService.ERROR_MESSAGE_LIST, productExportEbay.getproductExportFailureMessageList());
}
}
}
} else {
return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultItem));
}
}
}
}
//buildDataItemsXml(DispatchContext dctx, Map context, StringBuffer dataItemsXml, String token, GenericValue prod) {
}
}
}
}
} else {
@@ -339,7 +221,7 @@ public class EbayStore {
} else {
return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap));
}
//result = ServiceUtil.returnSuccess();
result.put(ModelService.SUCCESS_MESSAGE, "Export categories success...");
} catch (Exception e) {
Debug.logError("Exception in exportCategoriesSelectedToEbayStore : " + e, module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionInGetEbayCategories", locale));
@@ -414,32 +296,7 @@ public class EbayStore {
}
return result;
}
// --- GetStoreOptions request method -------------- //
public static Map buildGetStoreOptionsXml(Map context, StringBuffer dataStoreXml, String token) {
Locale locale = (Locale)context.get("locale");
try {
StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
// Get the list of products to be exported to eBay
try {
Document storeDocument = UtilXml.makeEmptyXmlDocument("GetStoreOptionsRequest");
Element storeRequestElem = storeDocument.getDocumentElement();
storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
appendRequesterCredentials(storeRequestElem, storeDocument, token);
dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
} catch (Exception e) {
Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
}
} catch (Exception e) {
Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
}
return ServiceUtil.returnSuccess();
}
// --- GetStore request method -------------- //
public static Map buildGetStoreXml(Map context, StringBuffer dataStoreXml, String token, String siteID) {
Locale locale = (Locale)context.get("locale");
try {
@@ -466,7 +323,6 @@ public class EbayStore {
return ServiceUtil.returnSuccess();
}
// --- SetStoreCategoriesRequest method -------------- //
public static Map buildSetStoreCategoriesXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID, String productCategoryId) {
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale)context.get("locale");
@@ -510,40 +366,6 @@ public class EbayStore {
return ServiceUtil.returnSuccess();
}
public static Map buildReviseItemXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID, String productId, String primaryCategoryId) {
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale)context.get("locale");
try {
StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
// Get the list of products to be exported to eBay
try {
Document itemDocument = UtilXml.makeEmptyXmlDocument("ReviseItemRequest");
Element itemRequestElem = itemDocument.getDocumentElement();
itemRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
appendRequesterCredentials(itemRequestElem, itemDocument, token);
UtilXml.addChildElementValue(itemRequestElem, "Version", "643", itemDocument);
UtilXml.addChildElementValue(itemRequestElem, "ErrorLanguage", "en_US", itemDocument);
UtilXml.addChildElementValue(itemRequestElem, "WarningLevel", "High", itemDocument);
Element ItemCategoriesElem = UtilXml.addChildElement(itemRequestElem, "Item", itemDocument);
UtilXml.addChildElementValue(ItemCategoriesElem, "ItemID", productId, itemDocument);
Element customCategoryElem = UtilXml.addChildElement(ItemCategoriesElem, "PrimaryCategory", itemDocument);
UtilXml.addChildElementValue(customCategoryElem, "CategoryID", primaryCategoryId, itemDocument);
dataStoreXml.append(UtilXml.writeXmlDocument(itemDocument));
} catch (Exception e) {
Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
}
} catch (Exception e) {
Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
}
return ServiceUtil.returnSuccess();
}
public static Map readEbayGetStoreCategoriesResponse(String msg, Locale locale) {
Map results = null;
List categories = FastList.newInstance();
@@ -595,32 +417,6 @@ public class EbayStore {
return results;
}
public static String exportItemIDResponse(String msg) {
String itemID = "";
try {
Document docResponse = UtilXml.readXmlDocument(msg, true);
Element elemResponse = docResponse.getDocumentElement();
String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
if (ack != null && "Failure".equals(ack)) {
String errorMessage = "";
List errorList = UtilXml.childElementList(elemResponse, "Errors");
Iterator errorElemIter = errorList.iterator();
while (errorElemIter.hasNext()) {
Element errorElement = (Element) errorElemIter.next();
errorMessage = UtilXml.childElementValue(errorElement, "LongMessage");
}
return "";
} else {
itemID = UtilXml.childElementValue(elemResponse, "ItemID");
String productSuccessfullyExportedMsg = "Product successfully exported with ID (" + itemID + ").";
return itemID;
}
} catch (Exception e) {
Debug.logError("Error in processing xml string" + e.getMessage(), module);
return "";
}
}
public static Map<String, Object> getEbayStoreUser(DispatchContext dctx, Map<String, ? extends Object> context){
Map<String, Object>result = FastMap.newInstance();
String errorMsg = null;
@@ -671,7 +467,6 @@ public class EbayStore {
}
}
} catch (GenericEntityException e1) {
e1.printStackTrace();
}
@@ -680,7 +475,7 @@ public class EbayStore {
//call.setSite(EbayHelper.getSiteCodeType((String)context.get("productStoreId"), locale, delegator));
call.setCategoryStructureOnly(false);
call.setUserID(userLoginId);
try {
resp = (GetStoreResponseType)call.execute(req);
if(resp != null && "SUCCESS".equals(resp.getAck().toString())){
-24
View File
@@ -287,30 +287,6 @@ under the License.
</entity-options-->
</drop-down>
</field>
<field name="location"><text size="40"></text></field>
<field name="paymentMethods" title="Default Payment Methods">
<drop-down>
<option key="paymentPayPal" description="${uiLabelMap.FormFieldTitle_paymentPayPal}"/>
<option key="paymentVisaMC" description="${uiLabelMap.FormFieldTitle_paymentVisaMC}"/>
<option key="paymentAmEx" description="${uiLabelMap.FormFieldTitle_paymentAmEx}"/>
<option key="paymentDiscover" description="${uiLabelMap.FormFieldTitle_paymentDiscover}"/>
<option key="paymentMOCC" description="${uiLabelMap.FormFieldTitle_paymentMOCC}"/>
<option key="paymentPersonalCheck" description="${uiLabelMap.FormFieldTitle_paymentPersonalCheck}"/>
<option key="paymentCCAccepted" description="${uiLabelMap.FormFieldTitle_paymentCCAccepted}"/>
<option key="paymentCashInPerson" description="${uiLabelMap.FormFieldTitle_paymentCashInPerson}"/>
<option key="paymentCashOnPickup" description="${uiLabelMap.FormFieldTitle_paymentCashOnPickup}"/>
<option key="paymentCOD" description="${uiLabelMap.FormFieldTitle_paymentCOD}"/>
<option key="paymentCODPrePayDelivery" description="${uiLabelMap.FormFieldTitle_paymentCODPrePayDelivery}"/>
<option key="paymentMoneyXferAccepted" description="${uiLabelMap.FormFieldTitle_paymentMoneyXferAccepted}"/>
</drop-down>
</field>
<field name="listingDuration">
<drop-down>
<option key="Days_1" description="1 ${uiLabelMap.CommonDay}"/>
<option key="Days_3" description="3 ${uiLabelMap.CommonDays}"/>
<option key="Days_7" description="7 ${uiLabelMap.CommonDays}"/>
</drop-down>
</field>
<field name="submitButton" title="${uiLabelMap.EbayExportToEbayStore}"><submit button-type="button"/></field>
</form>
<form name="NewEbayAccount" type="single" target="createEbayAccount">