ShopperContext
ShopperContextErrorCodes
ShopperContextException
ShopperContextMgr
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
Provides static helper methods for managing Shopper Context.
Shopper Context is used to personalize shopper experiences with context values such as custom session attributes, assignment qualifiers, geolocation, effective datetime, source code and more. When Shopper Context is set for a shopper, it can activate promotions or price books assigned to customer groups, source codes, or stores (via assignments) in the subsequent requests, not the current request.
Shopper Context is used to personalize the shopper experience in case of Composable/Headless or Hybrid storefront implementations that use Shopper Login and API Access Service (SLAS).
NOTE: This script API is not intended to be used for standard server-side storefront implementations. Only for Composable/Headless or Hybrid storefront implementations.
Unlike CustomerContextMgr which is used to set just Effective Time for which the customer is shopping at, Shopper Context API provides a way to set many types of contexts such as custom session attributes, assignment qualifiers, geolocation, effective datetime, source code etc.
The following feature toggles and site preferences must be enabled in order to use this script API:
For more details on Shopper Context please refer to: Shopper Context API Overview
For more details on Hybrid Authentication for Hybrid storefronts please refer to: Hybrid Authentication
ShopperContextMgr is used to create, access and delete Shopper Context.
Typical usage:
// get the ShopperContext if it exists ShopperContext context = ShopperContextMgr.getShopperContext(); if (context == null) { context = new ShopperContext(); } // set the values in the ShopperContext object context.setSourceCode( "sourcecode" ); var customQualifiers = new dw.util.HashMap(); customQualifiers.put( "deviceType", "iPad" ); context.setCustomQualifiers( customQualifiers ); // Save the ShopperContext ShopperContextMgr.setShopperContext( context, true );
NOTE: Ensure the ShopperContext object is saved using setShopperContext(ShopperContext, Boolean)after setting or updating the context values.
| Property | Description |
|---|---|
geolocation: Geolocation (read-only) | Gets the Geolocation object for the clientIP set in ShopperContext or null if no shopperContext is found, or no clientIP was set or Geolocation for the clientIP was not found. |
| shopperContext: ShopperContext | Returns the ShopperContext if it exists for the customer. |
This class does not have a constructor, so you cannot create it directly.
| Method | Description |
|---|---|
| static getGeolocation() | Gets the Geolocation object for the clientIP set in ShopperContext or null if no shopperContext is found, or no clientIP was set or Geolocation for the clientIP was not found. |
| static getShopperContext() | Returns the ShopperContext if it exists for the customer. |
| static removeShopperContext() | Removes the ShopperContext for the customer. |
| static setShopperContext(ShopperContext, Boolean) | Sets new ShopperContext for the customer or overwrites the existing context. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
(read-only)Gets the Geolocation object for the clientIP set in ShopperContext or null if no shopperContext is found, or no clientIP was set or Geolocation for the clientIP was not found.
The method throws an exception if the call fails.
Returns the ShopperContext if it exists for the customer. Returns null if it does not exist.
Gets the Geolocation object for the clientIP set in ShopperContext or null if no shopperContext is found, or no clientIP was set or Geolocation for the clientIP was not found.
The method throws an exception if the call fails.
Throws:
Returns the ShopperContext if it exists for the customer. Returns null if it does not exist.
Returns:
Throws:
Removes the ShopperContext for the customer.
The method throws an exception if the deletion of Shopper Context fails.
Throws:
Sets new ShopperContext for the customer or overwrites the existing context.
Note: This method does not save the attributes from the given Shopper Context such as - custom session attributes, source code, effective date time etc., - in the current session object. These attributes are read from Shopper Context and stored in the corresponding session attributes during subsequent requests and not in the current request. Hence, promotions, price books etc., are triggered in subsequent requests.
If clientIP is set in ShopperContext, the geolocation information
is retrieved and set in x-geolocation header.
And if the parameter evaluateContextWithClientIP is set to true, the clientIP will be
saved to the Shopper Context.
If parameter evaluateContextWithClientIP is set to false, the clientIP will not be
saved to the Shopper Context.
If the geoLocation attribute is set, it overrides any geolocation context set by
clientIP.
Parameters:
Throws: