new Environment()

Description

The Environment component class provides access to information about the SuiteCommerce environment, including information such as configuration details, site settings, and user session details. Information retrieved is read only; any changes made to the returned objects or data will not affect the original objects or data.

Get an instance of this component by calling container.getComponent("Environment").

Members


componentName :String

Description

A unique name that identifies the component. Use the component name when getting a component, for example, application.getComponent(componentName).

Details
String

application :ComponentContainer

Description

The name which identify this kind of component. This name is used both for registering a new component and
getting a component implementation with ComponentContainer

Details

Methods


cancelableOn( event_name, handler ) → {void}

Description

Attaches an event handler to an event.

Parameters
Name Type Description
event_name String

The name of the event to which the event handler will be attached.

handler function

The event handler method that will be invoked when event_name is triggered. This function can receive optionally one parameter representing the action parameter. Besides optionally can return a Deferred to details the execution of the trigger's callback. If the returned Deferred is rejected the trigger's callback wont be called

Returns
Details

cancelableOff( event_name, handler ) → {void}

Description

Detaches an event handler from an event.

Parameters
Name Type Description
event_name String

The name of the event from which to detach the event handler. This argument is required.

handler function

The event handler that will be removed from the list of handlers attached to the event. This argument is required.

Returns
Details

extend( componentDefinition ) → {BaseComponent}

Description

Extends the current component and creates a child component.

Parameters
Name Type Description
componentDefinition Object

An object with the appropriate properties and methods to create the component.

Returns
Details

cancelableDisable( event_name ) → {void}

Description

Disables all the event handlers attached to an event.

Parameters
Name Type Description
event_name String

The name of the event.

Returns
Details

on( event_name, handler ) → {void}

Description

Attaches an event handler to an event name. Alias for CancelableEvents#cancelableOn.

Parameters
Name Type Description
event_name String

The name of the event to attach to

handler function
Returns
Details

cancelableEnable( event_name ) → {Void}

Description

Re-enables all the event handlers attached to an event.

Parameters
Name Type Description
event_name String

The name of the event.

Returns
Details

off( event_name, handler ) → {void}

Description

Detaches an event handler from an event name. Alias for CancelableEvents#cancelableOff.

Parameters
Name Type Description
event_name String

The name of the event from which to detach the event handler.

handler function
Returns
Details

cancelableTrigger( event_name, ...args ) → {Deferred}

Description

Triggers an event with a set of arguments. If an event handler is rejected, the event handler callbacks will not be executed.

Parameters
Name Type Attributes Description
event_name String

The name of the event to trigger.

args params <repeatable>

One or more arguments that will be broadcast to all event handlers attached to the event.

Returns

Returns a Deferred object. Because event handlers are sometimes asynchronous, any callbacks in the event handlers will also be asynchronous.

Details

cancelableTriggerUnsafe( event_name, ...args ) → {Deferred}

Description

Triggers an event with a set of unsanitized arguments. If an event handler is rejected, the event handler callbacks will not be executed.

Parameters
Name Type Attributes Description
event_name String

The name of the event to trigger.

args params <repeatable>

One or more arguments that will be broadcast to all event handlers attached to the event.

Returns

Returns a Deferred object. Because event handlers are sometimes asynchronous, any callbacks in the event handlers will also be asynchronous.


getConfig( key ) → {any}

Description

Gets the value of the specified configuration key. Use dot notation to access child objects and properties, for example, component.getConfig('CheckoutApp.skipLogin'). The getConfig() method returns a copy of the original object. Any changes made to the retrieved object or key/value pair will not affect the original object.

Note: You should always call this method with a configuration key. If you use this method without a key, the application attempts to return the entire Configuration object. On some pages in the application, this may return a very large object, which will result in an internal error (InternalError: too much recursion) or a range error (RangeError: Maximum call stack size exceeded).

			var environment_component = container.getComponent("Environment");
			if (environment_component) {
				var environment_cookiewarningsave = environment_component.getConfig("cookieWarningBanner.saveInCookie");
			
				if (environment_cookiewarningsave === true) {
					// Do something here.
				}
				else {
					// Do something else here.
				}
			}
			
Parameters
Name Type Description
key String

The key you want to get the value of.

Returns

Returns the value of the key, or the entire Configuration object if key is empty.


isPageGenerator() → {boolean}

Description

Checks whether the code is currently run by the SEO Page Generator or whether it is run by the web browser. See the SEO Page Generator topic in the NetSuite Help Center for more information.

Returns

Returns true if the code is run by the SEO Page Generator; otherwise, it returns false.


getSiteSetting( [ key ] ) → {any}

Description

Gets the value of a key in the sitesettings JSON object. See the sitesettings help topic for more information about individual site settings.

			var environment_component = container.getComponent("Environment");
			
			if (environment_component) {
				var decimal_separator = environment_component.getSiteSetting("decimalseparator");
				var logout_URL = environment_component.getSiteSetting("touchpoints.logout");
			}
			
Parameters
Name Type Attributes Description
key String <optional>

The key you want to get the value of. Use dot notation to access child objects and properties. If key is empty, the entire sitesettings object is returned.

Returns

Returns the value of the key, or the entire sitesettings object if key is empty.


getSession() → {Session}

Description

Gets current session information, including currency information, language settings, and price level.

		var environment_component = container.getComponent("Environment");
			var session = environment_component.getSession();
			
			if (session.currency.code == "USD") {
				// Do something based on the currency code
			}
			

Example of the object returned by this method:

		{	
				currency: {
					code: "USD",
					currencyname: "USD",
					internalid: "1",
					isdefault: "T",
					name: "USD",
					symbol: "$",
					symbolplacement: 1
				}
				language: {
					isDefault: "T",
					languagename: "English (U.S.)",
					locale: "en_US",
					name: "English (U.S.)"
				},
				pricelevel: "5"
			}
			
Returns

setTranslation( locale, keys )

Description

Adds or updates a translation key for the specified locale. Translations are added to the SC.Translations dictionary. If the key exists, this method overwrites its value. To avoid overwriting existing keys, you can use prefixes for the translation keys in your extension, for example MY.This promotion has expired.

See the Localize Text in an Extension topic for more information about translations in extensions.

		var environment_component = container.getComponent('Environment');
			var translations_frfr = [
				{key: 'Pre-Orders', value: 'Précommandes'},
				{key: 'View Preorders', value: 'Visualiser précommandes'},
				{key: 'Expected On', value: 'Date prévu'}
			];
			
			environment_component.setTranslation('fr_FR', translations_frfr);
			
Parameters
Name Type Description
locale string

The language and region identifier of the translation. The locale is usually in the format [language]_[region], for example, en_US or fr_FR.

keys Array.<TranslationEntry>

An array of objects containing the translation keys and their values.