svn commit: r1128192 - in /ofbiz/trunk/applications/product: script/org/ofbiz/product/catalog/CatalogServices.xml servicedef/services.xml

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

svn commit: r1128192 - in /ofbiz/trunk/applications/product: script/org/ofbiz/product/catalog/CatalogServices.xml servicedef/services.xml

hansbak-2
Author: hansbak
Date: Fri May 27 08:21:30 2011
New Revision: 1128192

URL: http://svn.apache.org/viewvc?rev=1128192&view=rev
Log:
add a service to create seo friendly alternative url's for the categories and products in a catalog. using the descriptions as a base

Modified:
    ofbiz/trunk/applications/product/script/org/ofbiz/product/catalog/CatalogServices.xml
    ofbiz/trunk/applications/product/servicedef/services.xml

Modified: ofbiz/trunk/applications/product/script/org/ofbiz/product/catalog/CatalogServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/catalog/CatalogServices.xml?rev=1128192&r1=1128191&r2=1128192&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/script/org/ofbiz/product/catalog/CatalogServices.xml (original)
+++ ofbiz/trunk/applications/product/script/org/ofbiz/product/catalog/CatalogServices.xml Fri May 27 08:21:30 2011
@@ -520,4 +520,123 @@ under the License.
         <call-simple-method method-name="catalogPermissionCheck"/>
     </simple-method>
 
+    <simple-method method-name="createMissingCategoryAndProductAltUrls" short-description="create missing category and product alternative urls.">
+        <now-timestamp field="now"/>
+        <entity-and list="prodCatalogCategoryList" entity-name="ProdCatalogCategory" filter-by-date="false">
+            <field-map field-name="prodCatalogId" from-field="parameters.prodCatalogId"/>
+        </entity-and>
+        
+        <!-- Get all categories -->
+        <call-class-method method-name="newInstance" class-name="javolution.util.FastList" ret-field="parameters.productCategories"/>
+        <iterate entry="prodCatalogCategory" list="prodCatalogCategoryList">
+            <set field="rootProductCategoryId" from-field="prodCatalogCategory.productCategoryId"/>
+            <entity-and list="productCategoryRollupList" entity-name="ProductCategoryRollup" filter-by-date="true">
+                <field-map field-name="parentProductCategoryId" from-field="rootProductCategoryId"/>
+            </entity-and>
+             <set field="parameters.parentProductCategoryId" from-field="rootProductCategoryId"/>
+             <call-simple-method method-name="createMissingCategoryAltUrlInline"/>
+        </iterate>
+        
+        <iterate entry="productCategoryList" list="parameters.productCategories">
+        
+            <!-- Create Product Category Alternative URLs -->
+            <entity-condition list="productCategoryContentAndInfoList" entity-name="ProductCategoryContentAndInfo" filter-by-date="true" use-cache="true">
+                <condition-list combine="and">
+                    <condition-expr field-name="productCategoryId" from-field="productCategoryList.productCategoryId"/>
+                    <condition-expr field-name="prodCatContentTypeId" value="ALTERNATIVE_URL"/>
+                </condition-list>
+                <order-by field-name="-fromDate"/>
+            </entity-condition>
+            
+            <if-empty field="productCategoryContentAndInfoList">
+                <set field="createSimpleTextContentForCategoryCtx.fromDate" from-field="now"/>
+                <set field="createSimpleTextContentForCategoryCtx.prodCatContentTypeId" value="ALTERNATIVE_URL"/>
+                <set field="createSimpleTextContentForCategoryCtx.localeString" value="en"/>
+                <set field="createSimpleTextContentForCategoryCtx.productCategoryId" from-field="productCategoryList.productCategoryId"/>
+                
+                <if-empty field="productCategoryList.categoryName">
+                    <entity-condition list="productCategoryContentList" entity-name="ProductCategoryContentAndInfo" filter-by-date="true" use-cache="true">
+                        <condition-list combine="and">
+                            <condition-expr field-name="productCategoryId" from-field="productCategoryList.productCategoryId"/>
+                            <condition-expr field-name="prodCatContentTypeId" value="CATEGORY_NAME"/>
+                        </condition-list>
+                        <order-by field-name="-fromDate"/>
+                    </entity-condition>
+                    <if-not-empty field="productCategoryContentList">
+                        <first-from-list entry="productCategoryContent" list="productCategoryContentList"/>
+                        <set field="getContentAndDataResourceCtx.contentId" from-field="productCategoryContent.contentId"/>
+                        <call-service service-name="getContentAndDataResource" in-map-name="getContentAndDataResourceCtx">
+                            <result-to-field result-name="resultData" field="resultMap"/>
+                        </call-service>
+                        
+                        <set field="electronicText" from-field="resultMap.electronicText"/>
+                        <set field="createSimpleTextContentForCategoryCtx.text" from-field="electronicText.textData"/>
+                    </if-not-empty>
+                <else>
+                    <set field="createSimpleTextContentForCategoryCtx.text" from-field="productCategoryList.categoryName"/>
+                </else>
+                </if-empty>
+                <if-not-empty field="createSimpleTextContentForCategoryCtx.text">
+                    <call-service service-name="createSimpleTextContentForCategory" in-map-name="createSimpleTextContentForCategoryCtx"/>
+                </if-not-empty>
+                <check-errors/>
+            </if-empty>
+            
+            <!-- Create Product Alternative URLs -->
+            <entity-condition list="productCategoryMemberList" entity-name="ProductCategoryMember" filter-by-date="true" use-cache="true">
+                <condition-list combine="and">
+                    <condition-expr field-name="productCategoryId" from-field="productCategoryList.productCategoryId"/>
+                </condition-list>
+                <order-by field-name="-fromDate"/>
+            </entity-condition>
+            
+            <iterate entry="productCategoryMember" list="productCategoryMemberList">
+                <set field="product.productId" from-field="productCategoryMember.productId"/>
+                <entity-condition list="ProductContentAndInfoList" entity-name="ProductContentAndInfo" filter-by-date="true" use-cache="true">
+                    <condition-list combine="and">
+                        <condition-expr field-name="productId" from-field="product.productId"/>
+                        <condition-expr field-name="productContentTypeId" value="ALTERNATIVE_URL"/>
+                    </condition-list>
+                    <order-by field-name="-fromDate"/>
+                </entity-condition>
+                
+                <if-empty field="ProductContentAndInfoList">
+                    <entity-one value-field="productMap" entity-name="Product">
+                        <field-map field-name="productId" from-field="product.productId"/>
+                    </entity-one>
+                    <set field="createSimpleTextContentForProductCtx.fromDate" from-field="now"/>
+                    <set field="createSimpleTextContentForProductCtx.productContentTypeId" value="ALTERNATIVE_URL"/>
+                    <set field="createSimpleTextContentForProductCtx.localeString" value="en"/>
+                    <set field="createSimpleTextContentForProductCtx.productId" from-field="product.productId"/>
+                    <if-empty field="productMap.internalName">
+                       <set field="createSimpleTextContentForProductCtx.text" from-field="productMap.productName"/>
+                    <else>
+                       <set field="createSimpleTextContentForProductCtx.text" from-field="productMap.internalName"/>
+                    </else>
+                    </if-empty>
+                    <if-not-empty field="createSimpleTextContentForProductCtx.text">
+                        <call-service service-name="createSimpleTextContentForProduct" in-map-name="createSimpleTextContentForProductCtx"/>
+                    </if-not-empty>
+                    <check-errors/>
+                </if-empty>
+            </iterate>
+        </iterate>
+    </simple-method>
+    <simple-method method-name="createMissingCategoryAltUrlInline" short-description="create missing category alternative inline">
+        <entity-and list="productCategoryRollups" entity-name="ProductCategoryRollup" filter-by-date="true">
+            <field-map field-name="parentProductCategoryId" from-field="parameters.parentProductCategoryId"/>
+        </entity-and>
+        <iterate entry="productCategoryRollup" list="productCategoryRollups">
+            <!-- append product category to list -->
+            <entity-one value-field="productCategory" entity-name="ProductCategory">
+                <field-map field-name="productCategoryId" from-field="productCategoryRollup.productCategoryId"/>
+            </entity-one>
+            <field-to-list list="parameters.productCategories" field="productCategory"/>
+            
+            <!-- find rollup product categories -->
+            <set field="parameters.parentProductCategoryId" from-field="productCategoryRollup.productCategoryId"/>
+            <call-simple-method method-name="createMissingCategoryAltUrlInline"/>
+            <check-errors/>
+        </iterate>
+    </simple-method>
 </simple-methods>

Modified: ofbiz/trunk/applications/product/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?rev=1128192&r1=1128191&r2=1128192&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services.xml Fri May 27 08:21:30 2011
@@ -1607,4 +1607,10 @@ under the License.
         <attribute name="productCategoryId" mode="OUT" type="String" optional="true"/>
     </service>
     
+    <!-- Alternative URLs -->
+    <service name="createMissingCategoryAndProductAltUrls" engine="simple"
+                location="component://product/script/org/ofbiz/product/catalog/CatalogServices.xml" invoke="createMissingCategoryAndProductAltUrls" auth="true" use-transaction="false">
+        <description>Create missing Category and Product Alternative URLs</description>
+        <attribute name="prodCatalogId" mode="IN" type="String" optional="false"/>
+    </service>
 </services>