Search This Blog

Wednesday, July 2, 2014

Using seourlkeywordgen for store locator and physical stores


Out of the box commerce seourlkeywordgen utility is meant for product, items and categories. It can be extended for generating tokens for physical stores as well specially when you have hundreds of physical stores.

Here are the steps..

1. Extract SEO-BaseComponentLogic-FEP.jar and create new configuration file (stores.xml) for stores in com.ibm.commerce.seo.loader pacakage. You will find configuration files for product, item and category in same package.

2. Copy following content in stores.xml. Update sqls if there is any customization in your store locator implementation.

<?xml version="1.0" encoding="UTF-8"?>

<!--
 =================================================================
  Licensed Materials - Property of IBM

  WebSphere Commerce

  (C) Copyright IBM Corp. 2010, 2011 All Rights Reserved.

  US Government Users Restricted Rights - Use, duplication or
  disclosure restricted by GSA ADP Schedule Contract with
  IBM Corp.
 =================================================================
-->

<loaderConfig batchSize="10">

    <parameter    generatorId="paramShareLanguage"      subClass="EnvParameterGenerator"    seed="shareURLKeywordForAllLanguages"  />
    <parameter    generatorId="paramStoreId"            subClass="EnvParameterGenerator"    seed="storeId"    />
    <parameter    generatorId="paramCatalogId"          subClass="EnvParameterGenerator"    seed="catalogId"  />
    <parameter    generatorId="paramStoreNameKeyword"    subClass="EnvParameterGenerator"    default="IDENTIFIER" />
    <parameter    generatorId="paramStoreNameKeyword2"       subClass="EnvParameterGenerator"    default="IDENTIFIER" />

    <parameter    generatorId="paramChangeF"            subClass="ValueGenerator"   seed="N"    isString="true" />
    <parameter    generatorId="paramPriority"           subClass="ValueGenerator"   seed="0" />


    <dbprepare>
        <condition>CREATE TABLE SEOURLKEYWORD( ID BIGINT NOT NULL )</condition>
        <update>DROP TABLE SEOURLKEYWORD</update>
        <update>DROP TABLE SEOURL</update>
        <update>delete from KEYS  where  KEYS_ID=-600</update>
        <update>delete from KEYS  where  KEYS_ID=-601</update>
        <update>CREATE TABLE SEOURLKEYWORD (
                    SEOURLKEYWORD_ID   BIGINT NOT NULL,
               SEOURL_ID   BIGINT NOT NULL,
                    STOREENT_ID   INTEGER NOT NULL,
                    LANGUAGE_ID   INTEGER NOT NULL,
                    URLKEYWORD   VARCHAR(254) NOT NULL,
                    MOBILEURLKEYWORD   VARCHAR(254),
                    STATUS   INTEGER NOT NULL DEFAULT 1,
                    OPTCOUNTER   SMALLINT NOT NULL DEFAULT 0)</update>
        <update>CREATE TABLE SEOURL (                  
                    SEOURL_ID   BIGINT NOT NULL,
                    TOKENNAME   VARCHAR(254) NOT NULL,
               TOKENVALUE   VARCHAR(254),
                    PRIORITY   DOUBLE,
                    CHANGE_FREQUENCY   VARCHAR(3),
                    MOBILE_PRIORITY   DOUBLE,
                    MOBILE_CHG_FREQ   VARCHAR(3),
                    OPTCOUNTER   SMALLINT NOT NULL DEFAULT 0)</update>
        <update>insert into KEYS  (
                            KEYS_ID,TABLENAME,          COLUMNNAME,           COUNTER, PREFETCHSIZE, LOWERBOUND, UPPERBOUND,          OPTCOUNTER
                        ) values (
                            -600,   'seourlkeyword',    'seourlkeyword_id',   0,       20,           0,          9223372036850000000, 0
                        )</update>
        <update>insert into KEYS  (
                            KEYS_ID,TABLENAME,          COLUMNNAME,           COUNTER, PREFETCHSIZE, LOWERBOUND, UPPERBOUND,          OPTCOUNTER
                        ) values (
                            -601,   'seourl',           'seourl_id',          0,       20,           0,          9223372036850000000, 0
                        )</update>
    </dbprepare>




    <loader>
        <generator    generatorId="generatorSEOURLKDId" subClass="IdGenerator"      seed="SEOURLKEYWORD"/>
        <generator    generatorId="generatorSEOURLId"   subClass="IdGenerator"      seed="SEOURL"       exclusive="true" />
        <generator    generatorId="generatorLanguageId" subClass="ValueGenerator" seed="-1"  exclusive="true" />

        <generator    generatorId="paramTokenName"      subClass="ValueGenerator"   seed="StoreDetailsToken" isString="true" />
        <generator    generatorId="generatorTokenValue" subClass="ContentGenerator" seed="STLOC_ID"  isString="true" />
        <generator    generatorId="generatorURLKeyword" subClass="ContentGenerator" seed="paramStoreNameKeyword"  fix="true" isString="true" />
        <generator    generatorId="generatorURLKwd2"    subClass="ContentGenerator" seed="paramStoreNameKeyword2"     fix="true" isString="true" />

        <exclusive source="STLOC_ID" target="SEOURL_ID" >
        select  TOKENVALUE, SEOURL_ID  from  SEOURL  where TOKENNAME='StoreDetailsToken'
        </exclusive>
       
        <query>
            <select>
                STLOC.STLOC_ID, STLOC.IDENTIFIER
            </select>
            <from>
                STLOC
            </from>
            <where>
                <section generatorId="paramStoreId">
                    STLOC.STOREENT_ID=_PARA_VAL_
                </section>
                <section>
                    and  STLOC.ACTIVE='1'
                </section>
            </where>
            <order>
                order by STLOC.STLOC_ID asc
            </order>
        </query>


        <targetTable tableId="SEOURL" exclusive="true">
            <column generatorId="generatorSEOURLId">SEOURL_ID</column>
            <column generatorId="paramTokenName">TOKENNAME</column>
            <column generatorId="generatorTokenValue">TOKENVALUE</column>
            <column generatorId="paramPriority" >PRIORITY</column>
            <column generatorId="paramChangeF"  >CHANGE_FREQUENCY</column>
            <column generatorId="paramPriority" >MOBILE_PRIORITY</column>
            <column generatorId="paramChangeF"  >MOBILE_CHG_FREQ</column>
        </targetTable>

        <targetTable tableId="SEOURLKEYWORD" exclusive="false">
            <column generatorId="generatorSEOURLKDId">SEOURLKEYWORD_ID</column>
            <column generatorId="generatorSEOURLId">SEOURL_ID</column>
            <column generatorId="paramStoreId"  >STOREENT_ID</column>
            <column generatorId="generatorLanguageId">LANGUAGE_ID</column>
            <column generatorId="generatorURLKeyword"  backupGeneratorId="generatorURLKwd2" >URLKEYWORD</column>
        </targetTable>

    </loader>

</loaderConfig >


3. Update jar with this new stores.xml file.
4. Add stores.xml in infrastructure admin component config (WC/xml/config/com.ibm.commerce.infrastructure-fep/wc-admin-component.xml)
5. Execute seourlkeywordgen and validate token and seo url data in seourl and seourlkeyword tables.