Feature Pack 7 or later

Customizing the User Data field Name Mapping and search configuration to include custom data

Note: The CatalogNavigationViewType noun is replaced by the CatalogEntryView noun in Feature Pack 7.

In this lesson, the User Data field Name Mapping is modified to map the new columns to the user data field of the CatalogEntryView noun.

About this task

You also create a search profile to return you profit margin data. As a result, the search results in the Aurora starter store include the newly added profit margin data.

There are several updates that are related to the Commerce Composer tool and WebSphere Commerce search. For more information, see Highlights of Version 7 Feature Pack 7.

The business object mediator is replaced by user data field name mapping in Feature Pack 7. For more information, see Migrating WebSphere Commerce search customization assets.

Procedure

Modify the user data field name mapping to map the profit margin field to a user data.
  1. Navigate to the com.ibm.commerce.catalog-ext directory under the search server. If this directory does not exist, you must create the directory.

    Search_eardir\xml\config\com.ibm.commerce.catalog-ext

  2. Open the wc-component.xml file. If it does not exist, you must create this file. For more information, see Changing properties in the component configuration file (wc-component.xml) (Search EAR).
  3. Add the following mapping:
    
    <_config:valuemapping externalName="CatalogEntryUserDataFieldNameMapping" 
      internalName="CatalogEntryUserDataFieldNameMapping">
    <_config:valuemap externalValue="ProfitMargin" internalValue="profitMargin" />
    </_config:valuemapping>
    
    If you must create this file, your complete file can resemble the following code:
    <?xml version="1.0" encoding="UTF-8"?>
    <_config:DevelopmentComponentConfiguration
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.ibm.com/xmlns/prod/commerce/foundation/config ../xsd/wc-component.xsd "
    	xmlns:_config="http://www.ibm.com/xmlns/prod/commerce/foundation/config">
    	
    	<_config:valuemappingservice>
    		<_config:valuemapping externalName="CatalogEntryUserDataFieldNameMapping" 
         internalName="CatalogEntryUserDataFieldNameMapping">
    				<_config:valuemap externalValue="ProfitMargin" internalValue="profitMargin" />
    		</_config:valuemapping>
    	</_config:valuemappingservice>
    </_config:DevelopmentComponentConfiguration>
    
  4. Save your changes and close the file.
Then, modify the search configuration file to let it return the value of the profit margin field in a new search profile.
  1. Navigate to the com.ibm.commerce.catalog-ext directory under the search server.

    Search_eardir\xml\config\com.ibm.commerce.catalog-ext

  2. Open the wc-search.xml file. If it does not exist, you must create this file.
    For an example of changing properties in search configuration file, see the task: Changing properties in the WebSphere Commerce search configuration file (wc-search.xml) (Search EAR)

    Add the following profile configuration before the end tag </_config:search-config>:

    <_config:profile name="X_findCatalogEntryProfitMargin" extends="IBM_findProductByIds_Summary">
       <_config:query inherits="true">
           <_config:postprocessor 
           classname="com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchCatalogEntryViewUserDataQueryPostprocessor" />         
       </_config:query>
       <_config:result inherits="true">
    	<_config:field name="profitMargin" />
       </_config:result> 	
    </_config:profile>
    
    • This code defines a new search profile that is called X_findCatalogEntryProfitMargin. This name includes the prefix 'X_' that indicates that this is a customized search profile.
    • This new profile extends an existing search profile IBM_findProductByIds_Summary. This profile is used in your store JSP file to retrieve the price data. This profile is defined in the following file: Stores\WebContent\widgetdir\com.ibm.commerce.store.widgets.CatalogEntryRecommendation\CatalogEntryRecommendation_Data.jspf. You modify this file to use your new profile in the next lesson.
      Note: IBM_findProductByIds_Summary replaces IBM_findCatalogEntryPriceWithAttributes_PriceMode in Feature Pack 7. For more information, see Mapping between WebSphere Commerce search profiles.
    • This code adds the com.ibm.commerce.foundation.server.services.rest.search.postprocessor.solr.SolrRESTSearchCatalogEntryViewUserDataQueryPostprocessor postprocessor into the specified search profile. The purpose of this postprocessor is to populate and map the user data that is defined in the wc-componemt.xml file into the final catalog entry REST response.
    • In your newly defined profile X_findCatalogEntryProfitMargin, you also add the field profitMargin in the result so that the profit margin is returned.
    Note: profitMargin is the example index field name that is used in this tutorial. Ensure that you add the index field name that you defined when you updated your search schema.xml file.
  3. Save your changes and close the file.
Finally, add your custom profile to the byIds service under productview.

Each REST service takes a predefined list of search profiles. Since the product recommendation widget uses the byIds service, you must append the custom profile to the byIds service originally defined within the Search-Rest\WebContent\WEB-INF\config\com.ibm.commerce.rest\wc-rest-resourceconfig.xml file.

  1. Navigate to the Search-Rest\WebContent\WEB-INF\config\com.ibm.commerce.rest-ext directory. You must create the directory if it is not exist.
  2. Open the wc-rest-resourceconfig.xml file. Under the productview resource, add the custom profile to the end of the searchProfile list for both byId services:
    
    <GetUri uri="store/{storeId}/productview/byId/{productId}" 
            description="Get product by unique ID" 
            searchProfile="IBM_IBfindProductByIds_Details,IBM_findProductByIdsWithAttributesAndAttachments,
            IBM_findProductByIds_Summary_WithNoEntitlementCheck,IBM_Admin_findProductByIds,X_findCatalogEntryProfitMargin"/>
    
        <GetUri uri="store/{storeId}/productview/byIds" 
            description="Get products by unique IDs" 
            searchProfile="IBM_IBfindProductByIds_Details,IBM_findProductByIdsWithAttributesAndAttachments,
            IBM_findProductByIds_Summary_WithNoEntitlementCheck,IBM_Admin_findProductByIds, X_findCatalogEntryProfitMargin"/>
    
    If you do not have the wc-rest-resourceconfig.xml file under the com.ibm.commerce.rest-ext directory, you can create the file to resemble the following code:
    
    <ResourceConfig>
    <Resource name="productview">
      <GetUri uri="store/{storeId}/productview/byId/{productId}" 
          description="Get product by unique ID" 
          searchProfile="IBM_IBfindProductByIds_Details,IBM_findProductByIdsWithAttributesAndAttachments,
          IBM_findProductByIds_Summary_WithNoEntitlementCheck,IBM_Admin_findProductByIds, X_findCatalogEntryProfitMargin"/>
    
      <GetUri uri="store/{storeId}/productview/byIds" 
          description="Get products by unique IDs"         
          searchProfile="IBM_IBfindProductByIds_Details,IBM_findProductByIdsWithAttributesAndAttachments,
          IBM_findProductByIds_Summary_WithNoEntitlementCheck,IBM_Admin_findProductByIds, X_findCatalogEntryProfitMargin"/>
    </Resource>
    </ResourceConfig>
    
  3. Save your changes and close the file.

    To ensure that WebSphere Commerce picks up the changes you made in your User Data field Name Mapping and search configuration file, you must restart your WebSphere Commerce server.