Personalization in Commerce Web Services

Commerce web services support personalization, allowing you to personalize the request responses for specific customers.

This is handled by CxOccPersonalizationFilter and based on the personalization identifier.
  • If a request does not have a personalization identifier, it is created for this request and returned in the response header.
  • If a request already contains a personalization identifier, the occ voters decide what recalculation action is executed. By default the LOAD action is executed to load the previously calculated personalization results. If there are no results for a specific customer or personalization identifier, the default results are loaded.
  • If a request contains a cmsTicketId parameter, the recalculation is done based on preview ticket data. Related documentation: previewwebservices Extension, previewpersonalizationweb Extension.
Personalization for Commerce Web Services is disabled by default, so you have to enable it: Configure Personalization for Commerce Web Services.
Personalization calculation results can influence the following requests:
Request Example Action Performed
GET https://localhost:9002/rest/v2/electronics/products/search?query=camera search for products
GET https://localhost:9002/rest/v2/electronics/users/john.doe@mail.com/carts/00001002 cart actions (for example turn on the promotion)
GET https://localhost:9002/rest/v2/electronics/cms/components/Section1SlotHomepageCxContainer cms components on page

OCC Voters

The occ voter mechanism allows you to determine when and how the personalization is recalculated for commerce web services. The logic of handling votes is defined in CxOccPersonalizationFilter. When you run the CxOccPersonalizationFilter, the system evaluates the voters (classes implementing the CxOccVoter according to their order). For each voter, it checks the corresponding vote. If it encounters a conclusive vote, the first vote is considered. If there is no conclusive vote, it merges the actions returned by each voter into one set of actions.

Time Voter

The CxOccTimeVoter triggers the asynchronous recalculation process if the value set for personalization calculation validity time parameter is exceeded. The default value for this parameter is 60000 milliseconds, but you can change it to suit your needs.

Custom Voter

You can create a custom voter to perform the following actions:
  • Create a class implementing de.hybris.platform.personalizationservices.occ.voters.CxOccVoter.
  • Define this class as a bean in the Spring context to be automatically used by the CxOccPersonalizationFilter.

Interceptors

You can influence the personalization process for commerce web services either by implementing the CxOccInterceptor interface or extending the AbstractCxOccInterceptor.
package de.hybris.platform.personalizationservices.occ;

import de.hybris.platform.personalizationservices.voters.CxOccInterceptorVote;
import de.hybris.platform.personalizationservices.voters.Vote;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.integration.context.Orderable;


/**
 * Interceptor for personalization process called in Commerce Web Services (OCC)
 */
public interface CxOccInterceptor extends Orderable
{
	/**
	 * Method to determine if personalization process should be executed for this request
	 * 
	 * @param request
	 *           Http request
	 * @return true - when personalization process should be continued<br/>
	 *         false - when personalization process should be omitted
	 * 
	 * @deprecated since 1905. Please use {@link CxOccInterceptor#shouldPersonalizeRequestVote(HttpServletRequest)} instead.
	 */
	@Deprecated
	default boolean shouldPersonalizeRequest(final HttpServletRequest request)
	{
		return true;
	}

	/**
	 * Method to determine if personalization process should be executed for this request
	 *
	 * @param request
	 *           Http request
	 * @return CxOccInterceptorVote - vote with information if personalization process should be continued<br/>
	 */
	default CxOccInterceptorVote shouldPersonalizeRequestVote(final HttpServletRequest request)
	{
		final CxOccInterceptorVote result = new CxOccInterceptorVote();
		result.setVote(true);
		result.setConclusive(false);
		return result;
	}

	/**
	 * Method called before voters will be asked about recalculation actions
	 * 
	 * @param request
	 *           Http request
	 */
	default void beforeGetVote(final HttpServletRequest request)
	{
	}

	/**
	 * Method called before final vote will be executed
	 * 
	 * @param request
	 *           Http request
	 * @param vote
	 *           Final vote which will be executed
	 */
	default void beforeVoteExecution(final HttpServletRequest request, final Vote vote)
	{
	}

	/**
	 * Method called after final vote execution
	 * 
	 * @param request
	 *           Http request
	 * @param response
	 *           Http response
	 * @param vote
	 *           final vote which was executed
	 */
	default void afterVoteExecution(final HttpServletRequest request, final HttpServletResponse response, final Vote vote)
	{
	}

}