Part 1: Adding language insensitive properties in the Catalogs tool
In this lesson, you are customizing the Catalogs tool
to support more UserData
information that is added
to the CatalogEntry
noun. In this tutorial, you are
adding support for catalog entry warranty details information. You
can follow the same procedure for any language insensitive properties
of a noun.
About this task
- Updating the WebSphere Commerce schema to store new information.
- Customizing the catalog service to include new information as user data in the CatalogEntry noun.
- Adding custom queries to a custom query template file.
- Customizing Management Center UI and customizing store UI with
<wcf:getData>
tag.
Procedure
- Update the wc-query-MyCompanyCatalogEntry-get.tpl
query template file to add data to the CatalogEntry noun. The wc-query-MyCompanyCatalogEntry-get.tpl
query template file contains the following information:
- A symbol definition section that defines the tables included in the query template. In this tutorial you are including the CATENTRY, CATENTDESC, XWARRANTY, XCAREINSTRUCTION database tables in the symbol definition section.
- Definition of a new association SQL statement that seeks the new custom data.
- Definition of a new access profile
MyCompany_All
, which extends the default CatalogEntry Summary access profile:IBM_Admin_Summary
.Note:IBM_Admin_
prefixes as used in the access profileIBM_Admin_Summary
are intended to be used by admin/Management Center services calls. Access profiles that do not follow the new naming conventions continue to function correctly, as compatibility is maintained with earlier versions. It is recommended, however, that they are followed for existing access profiles, and when you change future access profiles.
The data service layer tutorial that you completed as a prerequisite before you began this tutorial uses a simple query template to add new data. In this tutorial, you are updating a Management Center query that displays catalog entries. Depending on how the query is defined by using associated queries, you might have to extend the access profile and add an associated query.
- Open the WebSphere Commerce Developer.
- In the Enterprise Explorer view, navigate to WC > xml > config > com.ibm.commerce.catalog-ext.
- Open the wc-query-MyCompanyCatalogEntry-get.tpl file for editing.
- Locate the following code:
BEGIN_XPATH_TO_SQL_STATEMENT name=/CatalogEntry[CatalogEntryIdentifier[(UniqueID=)]]+MyCompany_All base_table=CATENTRY sql= SELECT CATENTRY.$COLS:CATENTRY$, CATENTDESC.$COLS:CATENTDESC$, XWARRANTY.$COLS:XWARRANTY$, XCAREINSTRUCTION.$COLS:XCAREINSTRUCTION$ FROM CATENTRY LEFT OUTER JOIN XWARRANTY ON (CATENTRY.CATENTRY_ID = XWARRANTY.CATENTRY_ID) LEFT OUTER JOIN CATENTDESC ON (CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID AND CATENTDESC.LANGUAGE_ID = $CTX:LANG_ID$) LEFT OUTER JOIN XCAREINSTRUCTION ON (CATENTRY.CATENTRY_ID = XCAREINSTRUCTION.CATENTRY_ID AND XCAREINSTRUCTION.LANGUAGE_ID = $CTX:LANG_ID$) WHERE CATENTRY.CATENTRY_ID IN (?UniqueID?) AND CATENTRY.MARKFORDELETE = 0 END_XPATH_TO_SQL_STATEMENT
- Replace it with the following code:
BEGIN_ASSOCIATION_SQL_STATEMENT name=MyCompanyWarrantygetCatalogEntryDetailsByParentCatalogGroupId base_table=CATENTRY additional_entity_objects=true SQL= SELECT CATENTRY.$COLS:CATENTRY$, CATENTDESC.$COLS:CATENTDESC$, XWARRANTY.$COLS:XWARRANTY$, XCAREINSTRUCTION.$COLS:XCAREINSTRUCTION$ FROM CATENTRY LEFT OUTER JOIN XWARRANTY ON (CATENTRY.CATENTRY_ID = XWARRANTY.CATENTRY_ID) LEFT OUTER JOIN CATENTDESC ON (CATENTDESC.CATENTRY_ID = CATENTRY.CATENTRY_ID AND CATENTDESC.LANGUAGE_ID in ($CONTROL:LANGUAGES$)) LEFT OUTER JOIN XCAREINSTRUCTION ON (CATENTRY.CATENTRY_ID = XCAREINSTRUCTION.CATENTRY_ID AND XCAREINSTRUCTION.LANGUAGE_ID in ($CONTROL:LANGUAGES$)) WHERE CATENTRY.CATENTRY_ID IN ($ENTITY_PKS$) AND CATENTRY.MARKFORDELETE = 0 END_ASSOCIATION_SQL_STATEMENT
- Extend the default access profile
IBM_Admin_Summary
in the profile definition. Add the following code at the bottom of the wc-query-MyCompanyCatalogEntry-get.tpl file:<!-- ========================================================================= --> <!-- =============================PROFILE DEFINITIONS========================= --> <!-- ========================================================================= --> BEGIN_PROFILE name=MyCompany_All extends = IBM_Admin_Summary BEGIN_ENTITY associated_sql_statement=MyCompanyWarrantygetCatalogEntryDetailsByParentCatalogGroupId END_ENTITY END_PROFILE
Where:-
name
- Specify the name of your custom profile, for example
MyCompany_All
. extends
- Specify which default access profile you are going to extend,
for example
IBM_Admin_Summary
. associated_sql_statement
- Specify the new associated SQL statement for fetching your custom
data for example,
MyCompanyWarrantygetCatalogEntryDetailsByParentCatalogGroupId
.
Note: To define a new access profile, see Access profiles. You do not have to copy all associated queries that are defined in the defaultCatalogEntry
Details access profile, such asIBM_Admin_Summary
. By following the proceeding steps, both the existing catalog entry data and the new custom data are returned. -
- Register the custom access profile on the client side.
In this step, you configure the Management Center client to get the Warranty data.
To register the custom access profile on the client side, create a custom configuration file, get-data-config.xml. The get-data-config.xml file configures how the Management Center retrieves the data from the server with the foundation tag library
<wcf:getData>
. The extension version of this file in the com.ibm.commerce.catalog-ext directory overrides the original definition.The GetData tag configuration tag is configured by the WebSphere CommercegetData
action. This action searches for configuration files that are named get-data-config.xml in the WEB-INF/config directory. The configuration files must adhere to the following rules:- The root element is
get-data-config
. - Each component has one configuration file that is used with the
getData
action. - Base component configuration file locations are in the following directory: LOBTools > WebContent > WEB-INF > config > base > component. Where component is a directory that is unique to the component.
- Client extension locations are in the following directory: LOBTools > WebContent > WEB-INF > config > component-ext. Client extensions are loaded after base component configurations.
In the get-data-config.xml file, you must specify the expression builder and the access profile information. The access profile is
MyCompany_All
. An expression builder is a helper class, or a template, declared in the WebSphere Commerce get-data-config.xml file. It is used by thegetData
tag in a JSP file to construct an XPath expression that retrieves data.- Determine the service URL name. To find the service
URL name, you enable tracing in the Management Center.
- Open the WebSphere Application Server administrative console. Right-click your test server: select Administration > Run administrative console.
- Expand Troubleshooting and select Logs and Trace.
- Choose Server1.
- Select Change Log detail Levels
- Enable trace,
com.ibm.commerce.lobtools.*=all
, in either the Configuration or Runtime tab:- Configuration tab
The log messages display after you restart the server. When the server restarts, BOD message display without re-enabling trace in the administrative console.
- Runtime tab
The log message display without restarting the server. After you restart the server, trace must be re-enabled, otherwise the log message is not displayed.
Note: The preceding line must be terminated with a colon.
- Configuration tab
- Save the change.
- Open Management Center with logging enabled:
-
https://host_name:8000/lobtools?logger.display=true
wherehost_name
is the host name for your development environment.
-
- Click Management Center Tools > Logging and Tracing.
- In the Logging and Tracing dialog, set the
following options:
- In the Default Log Level field select CONFIG.
- Click Enable.
Trace is enabled. Do not close the Logging and Tracing dialog
- Open the Catalogs tool in Management Center, navigate to a product display page.
- Click Send Now in the Logging and Tracing panel.
- Open WCDE_installdir\wasprofile\logs\server1\trace.log
to view the trace log file. The service URL is
/cmc/GetCatalogGroupChildren-CatalogEntry
.
- Determine the controller JSP file.
- In the Enterprise Explorer view, navigate
to LOBTools > WebContent > WEB-INF and open the following
file:
- struts-ibm-tools.xml
- struts-ibm-catalog.xml
- Search for the following code:
The controller JSP file is GetChildCatalogEntryForCatalogGroup.jsp.<action path="/GetCatalogGroupChildren-CatalogEntry" forward="/jsp/commerce/catalog/restricted/GetChildCatalogEntryForCatalogGroup.jsp" />
- In the Enterprise Explorer view, navigate
to LOBTools > WebContent > WEB-INF and open the following
file:
- Determine which expression builder to use.Open the GetChildCatalogEntryForCatalogGroup.jsp file. Note the value of the expression builder,
getCatalogEntryDetailsByParentCatalogGroupId:
<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[] "var="catalogEntryChildren" expressionBuilder="getCatalogEntryDetailsByParentCatalogGroupId" varShowVerb="showVerb" recordSetStartNumber="${param.recordSetStartNumber}" recordSetReferenceId="${param.recordSetReferenceId}" maxItems="${param.maxItems}"> <wcf:contextData name="storeId" data="${param.storeId}"/> <wcf:contextData name="catalogId" data="${param.catalogId}"/> <wcf:contextData name="langId" data="${param.languageId}"/> <wcf:param name="catGroupId" value="${param.parentId}"/> </wcf:getData>
The name of expression builder that you declare in the custom get-data-config.xml file is
getCatalogEntryDetailsByParentCatalogGroupId
. - Locate the IBM provided expression builder to override
it.
- In the Enterprise Explorer view , navigate to LOBTools > WebContent > WEB-INF > config > com.ibm.commerce.catalog.
- Open the get-data-config.xml file.
- Search for the expression builder name:
getCatalogEntryDetailsByParentCatalogGroupId
.<expression-builder> <name>getCatalogEntryDetailsByParentCatalogGroupId</name> <data-type-name>CatalogEntry</data-type-name> <expression-template>{_wcf.ap=$accessProfile$}/CatalogEntry[ParentCatalogGroupIdentifier[(UniqueID='$catGroupId$')]]</expression-template> <param> <name>accessProfile</name> <value>IBM_Admin_Summary</value> </param> </expression-builder>
The default access profile is
IBM_Admin_Summary
. You override the expression builder by changing the value of the access profile. - Create a custom, get-data-config.xml configuration
file.
Warranty information is added to the
CatalogEntry
nounUserData
element. To fetch extra Warranty information from theCatalogEntry
noun, create a custom configuration file that overrides the base component configuration file.- In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > config.
- Right-click config then click New > Folder.
- In the Folder name field, enter com.ibm.commerce.catalog-ext
- Click Finish. The folder com.ibm.commerce.catalog-ext is created under the config directory.
- Right-click com.ibm.commerce.catalog-ext then click New > File.
- In the File name field, enter get-data-config.xml
- Click Finish. The get-data-config.xml file opens.
- Copy the following code to the extended get-data-config.xml:
<?xml version="1.0" encoding="UTF-8"?> <_config:get-data-config xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config ../../xsd/get-data-config.xsd "> <expression-builder> <name>getCatalogEntryDetailsByParentCatalogGroupId</name> <data-type-name>CatalogEntry</data-type-name> <param> <name>accessProfile</name> <value>MyCompany_All</value> </param> </expression-builder> </_config:get-data-config>
Note: In this code, the expression template is not included. This expression builder uses the access profile that you defined and the expression template from the IBM provided definition. This behavior is because you extended the expression builder and the name,getCatalogEntryDetailsByParentCatalogGroupId
remains the same. - You can also declare the expression builder
findAllCatentriesBasicSearch
. ThefindAllCatentriesBasicSearch
ensures that your new custom data displays in the product details that return from shopper searches on your storefront. To use this expression builder, add the code for this expression builder after the code for thegetCatalogEntryDetailsByParentCatalogGroupId
expression builder in the get-data-config.xml file.<expression-builder> <name>findAllCatentriesBasicSearch</name> <data-type-name>CatalogEntry</data-type-name> <param> <name>accessProfile</name> <value>MyCompany_All</value> </param> </expression-builder>
- The root element is