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
-
Modify the user data field name mapping to map the profit marging field to a user data.
-
Open IBM WebSphere Commerce Developer and switch to the Enterprise Explorer view.
-
Expand . If this directory does not exist, create the directory.
-
Open the wc-component.xml file for editing.
-
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>
-
Save your changes and close the file.
-
Modify the search configuration file so that the value of the profit margin field can return in
a new search profile.
-
In the com.ibm.commerce.catalog-ext directory, open the
wc-search.xml file for editing.
-
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.
-
Save and close the file.
-
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.
-
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.
-
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>
-
Save your changes and close the file.
-
Restart the WebSphere Commerce Test Server.
To ensure that WebSphere Commerce picks up the changes that you made in this lesson and
earlier lessons, you must restart the test server.