Context (Commerce Engine)

This is for:

Developer
Important

The Headless commerce engine, controllers, and actions are in open beta and therefore under active development. Reach out to your Coveo team for support in adopting them.

The Context controller exposes methods for managing the global context in a commerce interface.

Methods

setCountry

Sets the country.

Parameters

  • country: string

    The new country.

setCurrency

Sets the currency.

Parameters

  • currency: CurrencyCodeISO4217

    The new currency.

setLanguage

Sets the language.

Parameters

  • language: string

    The new language.

setUser

Sets the user.

Parameters

  • user: { userAgent?: string; }

    The new user.

setView

Sets the view.

Parameters

  • view: View

    The new view.

subscribe

Adds a callback that’s invoked on state change.

Parameters

  • listener: () => void

    A callback that’s invoked on state change.

Returns Unsubscribe: A function to remove the listener.

Attributes

state

A scoped and simplified part of the headless state that is relevant to the Context controller.

Properties

  • country: string

  • currency: CurrencyCodeISO4217

  • language: string

  • view: View

  • user?: { userAgent?: string; }

Initialize

buildContext

Creates a Context controller instance.

Parameters

  • engine: CommerceEngine

    The headless commerce engine.

  • props: ContextProps

    The configurable Context properties.

Returns Context

ContextProps

The configurable Context properties.

Properties

  • options?: ContextOptions

    The initial options that should be applied to this Context controller.

ContextOptions

The initial options that should be applied to this Context controller.

Properties

  • country: string

  • currency: CurrencyCodeISO4217

  • language: string

  • view: View

  • user?: { userAgent?: string; }

Unsubscribe

Call signatures

  • (): void;

View

Properties

  • url: string

  • referrer?: string