Customizing the UserData property name mapping and search configuration

In this lesson, you modify the UserData field name mapping to map the new columns to the UserData field of the CatalogEntryView noun. You also create a search profile to return the profit margin data. As a result, the search results in your store can include the profit margin data.

Procedure

  1. Modify the user data field name mapping to map the profit margin field to a user data.
    1. Open HCL Commerce Developer and switch to the Enterprise Explorer view.
    2. Expand Search > xml > config > com.ibm.commerce.catalog-ext. If this directory does not exist, create the directory.
    3. Open the wc-component.xml file for editing.
      If this file does not exist, you must create this file. For more information, see Changing properties in the HCL Commerce configuration file (wc-component.xml).
    4. Add the following mapping into your file before the end of the </_config:valuemappingservice> element.
      
      <_config:valuemapping externalName="CatalogEntryUserDataFieldNameMapping" internalName="CatalogEntryUserDataFieldNameMapping">
        <_config:valuemap externalValue="ProfitMargin" internalValue="profitMargin" />
      </_config:valuemapping>
      
      If you created the file as part of completing this tutorial, 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>
    5. Save your changes and close the file.
  2. Modify the search configuration file so that the value of the profit margin field can return in a new search profile.
    1. In the com.ibm.commerce.catalog-ext directory, open the wc-search.xml file for editing.
      If this file does not exist, you must create this file. For more information, see HCL Commerce Search configuration file (wc-search.xml).
    2. Add the following code to configure the new search profile for the profit margin before the end tag of the file, </_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. The prefix 'X_' indicates that this profile is a custom 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.
      • 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 x-schema.xml file.
    3. Save and close the file.
  3. 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. If this file does not exist, you must create the 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.
  4. Restart the HCL Commerce Test Server.
    To ensure that HCL Commerce picks up the changes that you made in this lesson and earlier lessons, you must restart the test server.