svn commit: r1095024 - in /ofbiz/trunk/specialpurpose/ebaystore: src/org/ofbiz/ebaystore/ webapp/ebaystore/WEB-INF/ webapp/ebaystore/WEB-INF/actions/store/ webapp/ebaystore/store/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1095024 - in /ofbiz/trunk/specialpurpose/ebaystore: src/org/ofbiz/ebaystore/ webapp/ebaystore/WEB-INF/ webapp/ebaystore/WEB-INF/actions/store/ webapp/ebaystore/store/

jleroux@apache.org
Author: jleroux
Date: Tue Apr 19 10:54:01 2011
New Revision: 1095024

URL: http://svn.apache.org/viewvc?rev=1095024&view=rev
Log:
A patch from Arun Patidar "Some misc issues in ebayStore component." (https://issues.apache.org/jira/browse/OFBIZ-4118) - OFBIZ-4118

Fixes issue of getting store categories in ebay store component during product export functionality. Added a new method to get store categories and made fixes in existing code.

Modified:
    ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayEvents.java
    ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java
    ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/actions/store/PrepareProductListing.groovy
    ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml
    ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl

Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayEvents.java?rev=1095024&r1=1095023&r2=1095024&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayEvents.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayEvents.java Tue Apr 19 10:54:01 2011
@@ -427,6 +427,7 @@ public class EbayEvents {
 
     public static List<StoreCustomCategoryType> getStoreChildCategories(HttpServletRequest request) throws ApiException, SdkException, Exception {
         List<StoreCustomCategoryType> categories = FastList.newInstance();
+        List<StoreCustomCategoryType> csCateList = FastList.newInstance();
         EbayStoreSiteFacade sf = null;
         String categoryId = null;
 
@@ -445,22 +446,21 @@ public class EbayEvents {
         sf = getSiteFacade(apiContext,request);
         if (UtilValidate.isNotEmpty(sf)) {
             Map<SiteCodeType, List<StoreCustomCategoryType>> csCateMaps = sf.getSiteStoreCategoriesMap();
-            List<StoreCustomCategoryType> csCateList = csCateMaps.get(apiContext.getSite());
+            csCateList = csCateMaps.get(apiContext.getSite());
             if (UtilValidate.isNotEmpty(csCateList)) {
-                for (StoreCustomCategoryType csCate : csCateList) {
-                    StoreCustomCategoryType[] categoryChildCategories = csCate.getChildCategory();
-                    if (categoryChildCategories.length > 0) {
-                        for (StoreCustomCategoryType childCategory : categoryChildCategories) {
-                            StoreCustomCategoryType[] categoryChild2 = childCategory.getChildCategory();
-                            if (categoryChild2.length > 0) {
-                                for (StoreCustomCategoryType categoryChild3 : categoryChild2) {
-                                    categories.add(categoryChild3);
-                                }
-                            } else {
-                                categories.add(childCategory);
+                if (UtilValidate.isNotEmpty(categoryId)) {
+                    // find child of selected ebay categories
+                    for (StoreCustomCategoryType csCate : csCateList) {
+                        if (categoryId.equals(String.valueOf(csCate.getCategoryID()))) {
+                            StoreCustomCategoryType [] childCategories = csCate.getChildCategory();
+                            for (StoreCustomCategoryType childCategoryId : childCategories) {
+                                categories.add(childCategoryId);
                             }
                         }
-                    } else {
+                    }
+                } else {
+                    // find first level of ebay categories
+                    for (StoreCustomCategoryType csCate : csCateList) {
                         categories.add(csCate);
                     }
                 }
@@ -832,12 +832,27 @@ public class EbayEvents {
                         }
                         StorefrontType storeFront = new StorefrontType();
                         if (UtilValidate.isNotEmpty(requestParams.get("ebayStore1Category"))) {
-                            storeFront.setStoreCategoryID(new Long(requestParams.get("ebayStore1Category").toString()));
-                            attributeMapList.put("StoreCategoryID", requestParams.get("ebayStore1Category").toString());
+                            String ebayStore1Category = (String)requestParams.get("ebayStore1Category");
+                            if (ebayStore1Category.contains("false")) {
+                                request.setAttribute("_ERROR_MESSAGE_","Please select ebay store category with low level of categories.");
+                                return "error";
+                            } else {
+                                if (ebayStore1Category.contains("true")) ebayStore1Category = ebayStore1Category.substring(0,ebayStore1Category.indexOf(":"));
+                            }
+                            storeFront.setStoreCategoryID(new Long(ebayStore1Category));
+                            attributeMapList.put("StoreCategoryID", ebayStore1Category);
+
                         }
                         if (UtilValidate.isNotEmpty(requestParams.get("ebayStore2Category"))) {
-                            storeFront.setStoreCategory2ID(new Long(requestParams.get("ebayStore2Category").toString()));
-                            attributeMapList.put("StoreCategory2ID", requestParams.get("ebayStore2Category").toString());
+                            String ebayStore2Category = (String)requestParams.get("ebayStore2Category");
+                            if (ebayStore2Category.contains("false")) {
+                                request.setAttribute("_ERROR_MESSAGE_","Please select ebay store category with low level of categories.");
+                                return "error";
+                            } else {
+                                if (ebayStore2Category.contains("true")) ebayStore2Category = ebayStore2Category.substring(0,ebayStore2Category.indexOf(":"));
+                            }
+                            storeFront.setStoreCategory2ID(new Long(ebayStore2Category));
+                            attributeMapList.put("StoreCategory2ID", ebayStore2Category);
                         }
                         if (UtilValidate.isNotEmpty(requestParams.get("ebayStore1Category")) || UtilValidate.isNotEmpty(requestParams.get("ebayStore2Category"))) {
                             item.setStorefront(storeFront);

Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java?rev=1095024&r1=1095023&r2=1095024&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java Tue Apr 19 10:54:01 2011
@@ -56,6 +56,7 @@ import com.ebay.soap.eBLBaseComponents.S
 import com.ebay.soap.eBLBaseComponents.StoreFontType;
 import com.ebay.soap.eBLBaseComponents.StoreThemeArrayType;
 import com.ebay.soap.eBLBaseComponents.StoreThemeType;
+import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryType;
 
 public class EbayStoreOptions {
 
@@ -276,4 +277,64 @@ public class EbayStoreOptions {
             }
         }
     }
+    
+    public static String retrieveEbayStoreCategoryByParent(HttpServletRequest request, HttpServletResponse response) {
+        List<StoreCustomCategoryType> results = FastList.newInstance();
+        try {
+            Map paramMap = UtilHttp.getCombinedMap(request);
+            if (paramMap.get("productStoreId") != null) {
+                String ebayStoreCategory = (String)paramMap.get("ebayCategoryId");
+                // when change category should be remove old category from session
+                if (ebayStoreCategory.indexOf("CH_") != -1) {
+                    ebayStoreCategory = ebayStoreCategory.replace("CH_", "");
+                    if (UtilValidate.isNotEmpty(ebayStoreCategory)) {
+                        ApiContext apiContext = EbayEvents.getApiContext(request);
+                        Map<String,Object> addItemObject = EbayEvents.getAddItemListingObject(request, apiContext);
+                        String refName = "itemCateFacade_".concat(ebayStoreCategory);
+                        if (UtilValidate.isNotEmpty(addItemObject.get(refName))) {
+                            addItemObject.remove(refName);
+                        }
+                    }
+                    ebayStoreCategory = "";
+                }
+                request.setAttribute("productStoreId", paramMap.get("productStoreId"));
+                request.setAttribute("categoryId", ebayStoreCategory);
+                ApiContext apiContext = EbayEvents.getApiContext(request);
+                EbayStoreSiteFacade sf = EbayEvents.getSiteFacade(apiContext,request);
+                results = EbayEvents.getStoreChildCategories(request);
+                if (UtilValidate.isNotEmpty(results)) {
+                    List<Map<String,Object>> categories = FastList.newInstance();
+                    for (StoreCustomCategoryType category : results) {
+                        Map<String,Object> context = FastMap.newInstance();
+                        context.put("CategoryCode", category.getCategoryID());
+                        context.put("CategoryName", category.getName());
+                        String isLeaf = "false";
+                        if (category.getChildCategory().length == 0) {
+                            isLeaf = "true";
+                        } else {
+                            isLeaf = "false";
+                        }
+                        //String isLeaf = String.valueOf(category.getChildCategory().!= null ? "true" : "false");
+                        context.put("IsLeafCategory", isLeaf);
+                        categories.add(context);
+                    }
+                    if (categories.size() > 0) {
+                        toJsonObjectList(categories,response);
+                    }
+                }
+            }
+        } catch (GenericServiceException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (EventHandlerException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (ApiException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (Exception e) {
+            Debug.logError(e.getMessage(), module);
+        }
+        return "success";
+    }
+
 }

Modified: ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/actions/store/PrepareProductListing.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/actions/store/PrepareProductListing.groovy?rev=1095024&r1=1095023&r2=1095024&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/actions/store/PrepareProductListing.groovy (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/actions/store/PrepareProductListing.groovy Tue Apr 19 10:54:01 2011
@@ -81,7 +81,8 @@
      request.setAttribute("productStoreId", productStoreId);
      categories = EbayEvents.getChildCategories(request);
      context.categories = categories;
-    
+     storeCategories = EbayEvents.getStoreChildCategories(request);
+     context.storeCategories = storeCategories;
     
      // point product tab id
      productId = null;

Modified: ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml?rev=1095024&r1=1095023&r2=1095024&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml Tue Apr 19 10:54:01 2011
@@ -294,7 +294,7 @@
     <request-map uri="retrieveEbayStoreCategoryByParent">
         <security https="true" auth="true"/>
         <event type="java" path="org.ofbiz.ebaystore.EbayStoreOptions" invoke="retrieveEbayStoreCategoryByParent"/>
-        <response name="success" type="view" value="main"/>
+        <response name="success" type="request" value="json"/>
     </request-map>
     <request-map uri="clearExpListing">
         <security https="true" auth="true"/>

Modified: ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl?rev=1095024&r1=1095023&r2=1095024&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl Tue Apr 19 10:54:01 2011
@@ -233,6 +233,7 @@ under the License.
                  <#assign requireEbayInventory = addItemObj.requireEbayInventory?if_exists>
                  <#assign item = addItem.getItem()?if_exists>
                  <#assign primaryCate = item.getPrimaryCategory()?if_exists>
+                 <#assign storeFront = item.getStorefront()?if_exists>
                  <#if isProductId == item.getSKU()?if_exists>
                      <input type="hidden" name="productId" value="${item.getSKU()?if_exists}"/>
                      <#assign smallImageUrl = "">
@@ -320,24 +321,25 @@ under the License.
                                             <td>
                                               <div>
                                                   <div id="loading"></div>
-                                                  <select id="ebayStore1Category" name="ebayStore1Category">
+                                                  <select id="ebayStore1Category" name="ebayStore1Category" onchange="retrieveEbayCategoryByParent('<@ofbizUrl>retrieveEbayStoreCategoryByParent</@ofbizUrl>',this.value,'${productStoreId}','ebayStore1Category')">
                                                         <option value="">Please select</option>
+                                                        <option value="">------</option>
                                                         <#if storeCategories?exists>
                                                             <#if storeFront?has_content>
-                                                                <#if !storeFront.isLeafCategory()?has_content>
+                                                                <#--if !storeFront.isLeafCategory()?has_content>
                                                                     <#assign  leafCate  = "false">
                                                                 <#else>
                                                                     <#assign  leafCate  = "true">
-                                                                </#if>
+                                                                </#if-->
                                                                 <#assign storeCate1Id  = storeFront.getStoreCategoryID()?if_exists>
                                                                  <option selected="selected" value="${storeFront.getStoreCategoryID()?if_exists}" >${storeFront.getStoreCategoryID()?if_exists}</option>
                                                             <#else>
                                                                 <#list storeCategories as csCate>
-                                                                    <#if !csCate.IsLeafCategory?has_content>
+                                                                    <#--if !csCate.IsLeafCategory?has_content>
                                                                         <#assign  leafCate  = "false">
                                                                     <#else>
                                                                         CH_${storeFront.getStoreCategoryID()?if_exists}<#assign  leafCate  = "true">
-                                                                    </#if>
+                                                                    </#if-->
                                                                     <#assign categoryId = csCate.getCategoryID()?if_exists>
                                                                     <option value="${csCate.getCategoryID()?if_exists}" >${csCate.getName()?if_exists}</option>
                                                                 </#list>
@@ -353,24 +355,24 @@ under the License.
                                             <td>
                                               <div>
                                                   <div id="loading"></div>
-                                                  <select id="ebayStore2Category" name="ebayStore2Category">
+                                                  <select id="ebayStore2Category" name="ebayStore2Category" onchange="retrieveEbayCategoryByParent('<@ofbizUrl>retrieveEbayStoreCategoryByParent</@ofbizUrl>',this.value,'${productStoreId}','ebayStore2Category')">
                                                         <option value="">Please select</option>
                                                         <#if storeCategories?exists>
                                                             <#if storeFront?has_content>
-                                                                <#if !storeFront.isLeafCategory()?has_content>
+                                                                <#--if !storeFront.isLeafCategory()?has_content>
                                                                     <#assign  leafCate  = "false">
                                                                 <#else>
                                                                     <#assign  leafCate  = "true">
-                                                                </#if>
-                                                                <#assign storeCate1Id  = storeFront.getStoreCategoryID()?if_exists>
-                                                                 <option selected="selected" value="${storeFront.getStoreCategoryID()?if_exists}" >${storeFront.getStoreCategoryID()?if_exists}</option>
+                                                                </#if-->
+                                                                <#assign storeCate2Id  = storeFront.getStoreCategory2ID()?if_exists>
+                                                                 <option selected="selected" value="${storeFront.getStoreCategory2ID()?if_exists}" >${storeFront.getStoreCategory2ID()?if_exists}</option>
                                                             <#else>
                                                                 <#list storeCategories as csCate>
-                                                                    <#if !csCate.IsLeafCategory?has_content>
+                                                                    <#--if !csCate.IsLeafCategory?has_content>
                                                                         <#assign  leafCate  = "false">
                                                                     <#else>
                                                                         CH_${storeFront.getStoreCategoryID()?if_exists}<#assign  leafCate  = "true">
-                                                                    </#if>
+                                                                    </#if-->
                                                                     <#assign categoryId = csCate.getCategoryID()?if_exists>
                                                                     <option value="${csCate.getCategoryID()?if_exists}" >${csCate.getName()?if_exists}</option>
                                                                 </#list>
@@ -378,7 +380,7 @@ under the License.
                                                         </#if>
                                                   </select>
                                               </div>
-                                              <input type="hidden" name="storeCate2Id" value="${storeCate1Id?if_exists}"/>
+                                              <input type="hidden" name="storeCate2Id" value="${storeCate2Id?if_exists}"/>
                                             </td>
                                         </tr>
                                         <tr>