Connector for Salesforce Commerce Cloud Manual / Version 2404
Table Of ContentsTo render personalized or contextualized info in content areas it is important to have relevant shop context info available during CAE rendering. It will be most likely user session related info, that is available in the Commerce system only and must now be provided to the backend CAE. Examples are the user id of a logged in user, gender, the date the user was logged in the last time or the names of the customer groups the user belongs to, up to the info which campaign should be applied. Of course these are just examples and you can imagine much more. So it is important to have a place in order to extend the transferred shop context information flexibly.
The relevant shop context will be transmitted to the CoreMedia CAE automatically as HTTP header parameters and can there be accessed for using it as "personalization filter". It is a big advantage of the dynamic rendering of a CoreMedia CAE that you can easily process this information at rendering time.
The transmission of the context will be done automatically. You do not have to take care of it.
On the one end, at the commerce system, there is a context provider script where the context
info is gathered. To add custom information to the context please extend the prepared
scripts/context/cmContextProvider.js
script in the
CoreMedia Cartridge for Salesforce. The exported functions in this script are called by the
cmFragmentService
when the context is built to pass it to the backend
CAE. The packing, transmitting and unpacking of the values happen automatically.
Extending the ContextProvider
To extend the shop context you have to edit the cmContextProvider.js
. There
are three prepared exported function that are called by the
cmFragmentService
to build up the context information. By default, a base
set of context information is already gathered and can be extended with custom values.
Alternatively you can implement your own cmContextProvider
by overwriting
this module in your own customization cartridge and prepending it in the cartridge path.
Function | Description |
---|---|
|
Gathers all preview related context information that should be sent as request
headers. By default, an existing preview date is provided in the format
|
|
Gathers all preview related context information that should be sent as request
parameters. By default, an existing test persona ( |
|
Gathers all user session related context information that should be sent as request
headers. By default, current customer groups of a logged in user are provided. The
used request header is: |
|
Gathers all user session related URL parameters. By default, this list is empty. |
Table 5.3. Functions of the cmContextProvider.js script
Note
The prefixes wc.preview
and wc.user
are
automatically added by the connector and must not be provided as prefixes.
Caution
As a rough upper limit you should not exceed 4k bytes for all parameters, as they will be transmitted via HTTP headers. You should also note that this data must be transmitted with each backend call.
Read shop context values on the CAE side
On the backend CAE side the shop context values will be automatically provided via a
Context
API. You can access the context values during rendering via a Java
API call.
All fragment requests are processed by the
FragmentCommerceContextInterceptor
in the CAE. This
interceptor creates and stores a Context
object in the request.
You can access the Context
object via
LiveContextContextHelper.fetchContext(HttpServletRequest request)
.
Example 5.2. Access the Shop Context in CAE via Context API