Cart Pages (Before)

This action manipulates the HTTP request or response before a Cart page loads on the live site.

Action TypeHTTP
Full Action IDhttp.storefront.pages.cart.request.before
Runs multiple custom functions?Yes

JavaScript File Structure

Action files share the following basic structure:

module.exports = function(context, callback) {
   // Your custom code here
   callback();
};

When you code the custom function for an action, you have access to two arguments:

callback—This argument follows the established JavaScript callback pattern: it takes an error as the first argument (or null if there is no error) and a result as the second argument (if required).

context—This argument provides the function access to relevant objects and methods that interface with Kibo eCommerce.

Context: HTTP

The following methods and objects are available to this action through the use of the context argument.

Storefront Operation
This action occurs during the storefront operation that obtains and renders view and model data from Hypr particular to the requested page.

Context Objects Available to All HTTP Actions

Context Methods Available to Storefront Actions

Context Methods Available to All HTTP Actions

Context Objects Available to All Actions

Context Objects Available to All HTTP Actions

request

Accesses the current HTTP request. In the case of Before actions, updates can be made to the request before Kibo eCommerce processes it.

PropertiesTypeDescription
paramsobjectThe input parameters to the service or webpage.
headersobjectThe request headers.
methodstringThe request method.
urlstringThe request URL.
pathstringThe request path.
cookiesobject

The request cookies.

*Available only for Storefront HTTP actions.

queryobjectThe request query.
hrefstringThe request href.
secureBooleanIndicates whether the request uses HTTPS.
ipstringThe request IP address.
ipsstringThe request secure IP address.
bodyobjectThe request body of the API operation associated with this action.

Example:

context.request.url;

response

Accesses the current HTTP response. For both Before and After actions, updates can be made to the response before Kibo eCommerce processes it.

PropertiesTypeDescription
headerobjectThe response header collection.
viewDataobject

The viewData collection used by the storefront rendering engine.

*Available only for Storefront HTTP actions.

viewNamestring

The response viewName value.

*Available only for Storefront HTTP actions.

bodyobjectThe response body of the API operation associated with this action.
statusintegerThe response status code.
messagestringThe response message.
lengthintegerThe response length.
typestringThe response type.

Example:

context.response.header;

items.siteContext

Accesses the current site context.

PropertiesTypeDescription
tenantIdintegerUnique identifier for the tenant.
siteIdintegerUnique identifier for the site.
hashStringstringA string to append to URLs that will change when cache is invalidated, either by a change to catalog or a publish of content.
labelsobjectThe theme labels, which are key-value pairs used for localization.
themeIdstringUnique identifier for the theme.
generalSettingsGeneralSettings

An object the includes the following properties:

  • websiteName (string)—Name of the site as configured in the Admin general settings.
  • timeZone (string)—The site time zone as configured in general settings in admin. Stored as human-readable string, e.g. “Mountain Standard Time”.
  • allowInvalidAddresses (Boolean)—TRUE if address validation is enabled and invalid addresses are allowed, as configured in the Admin general settings.
  • googleAnalyticsEcomEnabled (Boolean)—TRUE if Google Analytics is enabled and Google Analytics eCom tracking parameters are also enabled. In the Core theme and Core-derived themes, this results in a set of extra calls to the Google Analytics tracking beacon on the Order Confirmation page.
  • googleAnalyticsEnabled (Boolean)—TRUE if Google Analytics is enabled. In the Core theme and Core-derived themes this results in a call to the Google Analytics tracking beacon on every page.
  • googleAnalyticsId (string)—The UA number provided by the Google Analytics account as configured by the site.
  • isAddressValidationEnabled (Boolean)—TRUE if address validation is enabled as configured in the Admin general settings.
checkoutSettingsCheckoutSettings

An object with the following properties:

  • payByMail (Boolean)—TRUE if pay-by-mail is enabled in the Admin checkout settings.
  • isPayPalEnabled (Boolean)—TRUE if PayPal Express is enabled in Admin checkout settings.
  • supportedCards (Dictionary<string, string>)—List of credit cards enabled in the Admin checkout settings.
themeSettingsobjectAn object that contains the theme settings available in theme.json.
isEditModeBooleanTRUE if the current site is being rendered inside an editor frame. Use this to display preview content in widgets or templates that would not work properly in an editing session.
cdnPrefixstringThe URL prefix for CDN content, composed of the host name plus a unique CDN identifier for the site.
secureHoststringHTTPS version of the requested host name.
supportsInStorePickupBooleanTRUE if store pickup is enabled in the Admin location settings.
domainssiteDomains

An object that lists the Current domain and the Primary domain, each of which has the following properties:

  • domainName (string)—the name of the domain.
  • isPrimary (Boolean)—TRUE if the given domain is the primary one.
currencyInfoCurrency

An object with the following properties:

  • EnglishName (string)—the currency name.
  • symbol (string)—the currency symbol.
  • precision (integer)—the number of digits to display after the period.
  • roundingType (string)—the rounding type value: "UpToCurrencyPrecision", "NearestNickel", "DownToNearestNickel", "DownToCurrencyPrecisionMinusOne", or "NearestHalfUnit".
  • currencyCode (string)—for example, "USD" for U.S. dollars. Other values include: "EGP", "GBP", "TZS", "UYU", "UZS", "WST", "YER", "ZMK", "TWD", "GHS", "VEF", "SDG", "RSD", "MZN", and "AZN".

Example:

context.items.siteContext.siteId;

items.pageContext

Accesses the current page context.

PropertiesTypeDescription
queryobjectRead-only object of the key-value pairs in the current URL.
themeIdstringUnique identifier for the theme.
isDebugModeBooleanIndicates whether debug mode is enabled.
cdnCacheBustKeystringThe randomly generated number appended to the URL of CDN content. This number changes in order to refresh cached content every time a Kibo eCommerce Admin user clicks the Bust Cache button available in the General Settings.
isSecureBoolean

TRUE if the current page is a secure (HTTPS) page.

pageTypestringThe documentType of the current page, such as "web_page", "cart", "search", etc.
isCrawlerBooleanTRUE if the current page is requested by a search engine crawler.
isMobileBooleanTRUE if the current page is requested by a mobile device.
isTabletBooleanTRUE if the current page is requested by a tablet.
isDesktopBooleanTRUE if the visitor’s browser does not identify itself as a mobile or tablet device.
cmsContextCmsPageContext

An object with the following the Page, Template, and Site, which each have the following properties:

  • path (string)—name or ID of the CMS document.
  • documentTypeFQN (string)—the documentType such as "web_page".
  • document (pointer)—a pointer to the CMS document.
searchSearchContext

An object related to URL paging and URL queries of product collections on Search pages and Category pages. It contains the following properties:

  • pageSize (int)—the maximum number of items to return in the collection.
  • query (string)—A filter expression for Kibo eCommerce collections. You can filter products based on their properties by writing a string expression as your argument. For example: properties.firstname eq "Brenda".
  • sortBy (string)—A string representing how to sort the collection. You can sort on any property, date (such as createDate), or document name. After specifying the name of the property you are sorting on, include a space followed by "asc" or "desc" to specify sorting in ascending or descending order.
  • categoryId (int)—the category to facet products for.
  • A keyed collection of facets to filter on.
visitVisitThe unique visitor ID.
titlestringThe title of the current page.
metaDescriptionstringThe contents of the description field entered into the SEO settings for the current page.
metaTitlestringThe contents of the title field entered into the SEO settings for the current page.
metaKeywordsstringThe contents of the keywords field entered into the SEO settings for the current page.
userUser

An object with the following properties:

  • isAuthenticated (Boolean)—TRUE if the user is logged in.
  • userId (string)—the unique identifier for the user.
  • firstName (string)—the user's first name.
  • lastName (string)—the user's last name.
  • email (string)—the user's email address.
  • isAnonymous (Boolean)—TRUE if the user is not logged in.
  • accountId (int)—the unique identifier of the user's account.
isEditModeBooleanTRUE if the current site is being rendered inside an editor frame. Use this to display preview content in widgets or templates that would not work properly in an editing session.
urlstringThe canonical URL for the current page.
dataViewModestringEither "live" or "pending".
secureHoststringThe fully-qualified secure CDN domain for the site.
nowDateTimeThe current server date/time when the page is viewed. 
categoryCodestringThe category code for the current page if the page is a Category page or Search page.
categoryIdintegerThe category ID for the current page if the page is a Category page or Search page.

Example:

context.items.pageContext.categoryCode;

items.navigation

Accesses the current navigation context.

PropertiesTypeDescription
treeNavigationNode array

The navigation tree used to build the main navigation bar for the site. Consists of a list of navigation nodes, each of which may contain children nodes which also are a list of nodes, and so on. The navigation nodes contain the following properties:

  • name (string)—the name of the node.
  • url (string)—the URL to which the node links.
  • index (int)—the unique identifier for the node.
  • isHidden (Boolean)—TRUE if the node does not display in the site's navigation bar.
  • parent (NavigationNode)—the parent of the current node.
  • items (list of NavigationNode)—the children of the current node.
rootCategoriesNavigationNode arrayThis is the same as the tree, except it only includes the root-level or top level of the tree, and also excludes CMS pages and external links.
currentNodeNavigationNodeThe current node in the tree.
breadcrumbsNavigationNode arrayShows the "breadcrumbs" that navigate to the current page. This is the same as the tree but it excludes the parent and items properties.

Example:

context.items.navigation.breadcrumbs;

Context Methods Available to All Storefront Actions

exec.loginUser

Asynchronously retrieves a user, creates an authentication ticket, and sets the authentication cookies.

PropertiesTypeDescription
configobjectAn object that contains the following fields:
  • userId (string)—The 32-character alphanumeric ID of the user to authenticate.
  • userName (string)—The username of the user to authenticate (this field is not required if you provide a userId).
  • rememberUser (Boolean)—Specifies whether the authentication cookie should be persistent.
callbackfunctionA callback function that contains the following fields:
  • err An error object if the user is not found.
  • data The authentication ticket for the user.

Example:

var config = {
   rememberUser:true,
   userId: '48577d74a86044bfb2872a4c184ce33c'
};

context.exec.loginUser(config, function (err, result){
//handle the possible error and call the callback
//if successful the result should be the customer auth ticket.
   if (err){
   //bubble up error to the platform
      callback (err);
      return;
   }

//return control flow to the platform
callback();
});

Response: NA

exec.logOut

Synchronously logs out the current user by resetting the user context to an anonymous user and updating the associated cookies.

N/AN/AN/A
PropertiesTypeDescription

Example:

context.exec.logOut();

Response: NA

Context Methods Available to All HTTP Actions

request.get

Returns an HTTP header value for the specified header key.

ParametersTypeDescription
keystringThe header key.

Example:

context.request.get(field);

Response:

"object"

response.get

Gets a field from the response.

ParametersTypeDescription
keyobjectThe field to obtain.

Example:

context.response.get(field);

Response:

"string"

response.set

Sets the HTTP headers for the response.

ParametersTypeDescription
valuesobjectThe values for the HTTP headers.

Example:

context.response.set({ myCustomHeader: "howdy" });

Response: N/A

response.set2

Updates a field in the response.

ParametersTypeDescription
keystringThe key of the field.
valuestringThe value of the field.

Example:

context.response.set("name", "stuff");

Response: N/A

response.remove

Removes an HTTP header from the response.

ParametersTypeDescription
keystringThe HTTP header to remove.

Example:

context.response.remove(header);

Response: N/A

response.redirect

Redirects the incoming URL.

ParametersTypeDescription
urlstringThe destination URL.

Example:

context.response.redirect("http://someOtherSite/foo");

Response: N/A

response.end

Ends the response so that other actions or Kibo eCommerce logic can run. Also, signals the callback to complete.

ParametersTypeDescription
N/AN/AN/A

Example:

context.response.end();

Response: N/A

get.resource

Returns the currently persisted value of the requested resource. **Not available for all calls.

ParametersTypeDescription
N/AN/AN/A

Example:

context.get.resource();

Response: N/A

get.resourceStatus

Gets the HTTP resource status.

ParametersTypeDescription
N/AN/AN/A

Example:

context.get.resourceStatus();

Response: N/A

items.urlHelper.getUrl

Gets the current URL.

ParametersTypeDescription
type

object

config

Example:

context.items.urlHelper.getUrl(type, object, config);

Context Objects Available to All Actions

apiContext

Accesses Kibo eCommerce tenant information.

PropertiesTypeDescription
baseUrlstringThe base URL for the site.
basePciUrlstringThe base PCI URL for the site.
tenantPodstringThe name of the tenant pod in which the tenant resides.
appClaimsstringThe application claims token.
appKeystringThe application key.
tenantIdintegerUnique identifier for the tenant.
siteIdintegerUnique identifier for the site. This ID is used at all levels of a store, catalog, and tenant to associate objects to a site.
masterCatalogIdintegerUnique identifier for the master catalog.
catalogIdintegerThe unique identifier for the product catalog. Catalogs are part of a master catalog.
currencyCodestringThe default three-letter ISO currency code for monetary amounts.
previewDatedate/timeThe date and time that the content is being viewed. This might be a future date if the content is previewed with an active date range set in the future.
localeCodestringThe locale code per the country code provided. This code determines the localized content to use and display.
correlationIdstringThe unique identifier of the API request associated with the event action, which might contain multiple actions.
isAuthorizedAsAdminBooleanIndicates whether the Dev Account user is authorized as an admin.
userClaimsstringThe user claims token.

Example:

context.apiContext.baseUrl;

configuration

Receives a JSON response that contains information about the configuration data set in the Action Management JSON editor.

PropertiesTypeDescription
VariesobjectCustom fields and values that you can set in the Action Management JSON Editor.

Example:

context.configuration.customData;