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
-
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 ComponentContainerDetails
Methods
-
cancelableOn( event_name, handler ) → {void}
-
Description
Attaches an event handler to an event.
Parameters
Name Type Description event_nameString The name of the event to which the event handler will be attached.
handlerfunction 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_nameString The name of the event from which to detach the event handler. This argument is required.
handlerfunction 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 componentDefinitionObject An object with the appropriate properties and methods to create the component.
Returns
Details
-
closeMessage( messageId )
-
Description
Lets you close a message on the page. To close a message, you must have the ID of the message, as returned by showMessage() when the message was first shown.
var layout = container.getComponent('Layout'); var message_vat_no; if (layout) { // Check if a VAT number was entered. If not, display a message. if ($('#vat_no').val() == '') { message_vat_no = layout.showMessage({message: 'You must enter a VAT number to register as a business customer.', type: 'error'}); } } // Clear the VAT number error message when the VAT number field gets focus. $('#vat_no').focus(function() { layout.closeMessage(message_vat_no); });Parameters
Name Type Description messageIdstring The ID of the message to close. Get the ID of a message by assigning the return value of
showMessage()to a variable.Details
-
cancelableDisable( event_name ) → {void}
-
Description
Disables all the event handlers attached to an event.
Parameters
Name Type Description event_nameString 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_nameString The name of the event to attach to
handlerfunction Returns
Details
-
cancelableEnable( event_name ) → {Void}
-
Description
Re-enables all the event handlers attached to an event.
Parameters
Name Type Description event_nameString 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_nameString The name of the event from which to detach the event handler.
handlerfunction 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_nameString The name of the event to trigger.
argsparams <repeatable> One or more arguments that will be broadcast to all event handlers attached to the event.
Returns
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_nameString The name of the event to trigger.
argsparams <repeatable> One or more arguments that will be broadcast to all event handlers attached to the event.
Returns
Details
-
modifyViewJsonLd( view_id, callback ) → {void}
-
Description
Lets you modify JSON-LD data embedded in the
<head>element of a SuiteCommerce product details page. JSON-LD data on SuiteCommerce websites adheres to the structured data schemas, as specified on https://schema.org/Product.If your extension modifies a view or adds a child view on the product details page, you can use
modifyViewJsonLd()to update the related JSON-LD. For example, if you add a child view that displays additional product information, you can update the JSON-LD to ensure the page and its metadata are consistent.In general, the embedded JSON-LD data should be consistent with the content in the view. SuiteCommerce creates JSON-LD data when a view is rendered. For this reason, you need to pass in a view ID to
modifyViewJsonLd()when modifying JSON-LD data.Note: To use this method, JSON-LD must be selected as the markup type on the SuiteCommerce Configuration page in the NetSuite account. See Structured Data Markup in the NetSuite Help Center for more information.
In the following example, we create an instance of the Layout component and use
modifyViewJsonLd()to add a property to the JSON-LD object. We pass in 'ProductDetails.Full.View' as the view ID and a function that returns a Promise. The_.extendfunction enables you to copy an object and add new properties to it.var layout = container.getComponent('Layout'); layout.modifyViewJsonLd('ProductDetails.Full.View', function(json) { json = _.extend(json, { manufacturer: 'NetSuite Industrial' }); return jQuery.Deferred().resolve(json); });Parameters
Name Type Description view_idstring The identifier of the view that will update the JSON-LD data. For example, if you use the Layout component to modify the ProductDetails.Full.View view in the base theme template, pass in "ProductDetails.Full.View" as the
view_id.callbackfunction A function that modifies the JSON-LD data. It must return a Promise that resolves with an object.
Returns
Throws
Details
-
setChildViewIndex( view_id, placeholder_selector, view_name, index ) → {void}
-
Description
Changes the position of a child view inside a container.
Parameters
Name Type Description view_idstring The identifier of the view of the current component that contains the child view whose position will be changed.
placeholder_selectorstring The identifier of a location in the specified view (view_id) where the child view will be added.
view_namestring The identifier of a view in the placeholder.
indexnumber The index of the child view's position.
Returns
Throws
Details
-
showMessage( data ) → {string}
-
Description
Shows a message in the notifications area of a SuiteCommerce page. The message is displayed by default in the Notifications placeholder (a DIV element in the base theme template with the custom data attribute
data-view="Notifications"). You can also choose to display the message in any other placeholder that uses either of the following custom data attributes:data-viewordata-cms-area.Messages can be closed by the user, by setting a timeout in the method, or with the closeMessage() method. If you want to use
closeMessage(), first assign the return value ofshowMessage()to a variable, and then pass the variable tocloseMessage().In the following example, the message is shown and then closed after 5 seconds by setting a timeout.
var layout = container.getComponent('Layout'); if (layout) { var message_shown = false; layout.on('afterShowContent', function() { if (message_shown != false) { layout.showMessage({ message: '', type: 'info', selector: 'Notifications', timeout: 5000 }); message_shown = true; } }); }In the following example, a message is shown if an invalid VAT number is entered. When the user enters a valid number, the message is closed.
var layout = container.getComponent('Layout'); var message_vat_no; $('#vat_number').blur(function() { var vat_number = $(this).val(); if (message_vat_no !== undefined) { layout.closeMessage(message_vat_no); } // checkVatNumber() returns false if the number entered is invalid. if (!checkVatNumber(vat_number)) { message_vat_no = layout.showMessage({ message: 'You must enter a VAT number to register as a business customer.', type: 'error' }); } });Parameters
Name Type Description dataObject Data required to display the message.
datais an object, which can have the following properties:- message - Required. The text of the message.
- type - Required. The type of message. It also determines the appearance of the message on the page. Type can be one of the following:
info,warning,error, orsuccess. - selector - A placeholder on the page where you want the message to appear.
- timeout - Specifies the duration in milliseconds of the message on the page. If you do not specify a timeout, you can use closeMessage() to remove the message.
Returns
Details
-
addChildViews( view_id, child_views ) → {void}
-
Description
Adds one or more child views to an existing view. The existing view must already be in the DOM and must have the 'data-view' HTML attribute.
The
addChildViewsmethod is flexible, but more complex thanaddChildView. Use the simpler addChildView() where possible.checkout.addChildViews( checkout.WIZARD_VIEW , { 'Wizard.StepNavigation': { 'CheckoutView': { childViewIndex: 1 , childViewConstructor: function () { return new CheckoutExtensionView({checkout:checkout}); } } } } );Parameters
Name Type Description view_idstring The identifier of the view of the current component to which the child views will be added.
child_viewsobject Returns
Throws
Details
-
addChildView( data_view, view_constructor ) → {Void}
-
Description
Adds a child view to a view that already exists in the DOM. Child views can be added to elements that have the
data-viewordata-cms-areadata attribute. If there are multiple elements in a template that have a data-view attribute value ofview_id, the child view is added to all elements with that ID. Elements with the data-view attribute act as placeholders in the application. If there is content in the view (which is typically the case), the child view replaces the current content.If you want to add multiple views at the same time, or if you want to add a child view while preserving the current content in the existing view, use addChildViews.
layout.addChildView('Header.View', function () { return new HolidayBannerView({}); });In the above example, the view
HolidayBannerViewwill be added as a child view of an element in any template that has a data-view attribute ofHeader.View.layout.addChildView('cms:header_banner_top', function () { return new HolidayBannerView({}); });In the above example, a child view is added to a predefined SMT area called 'header_banner_top'. In the template, the header_banner_top SMT area might be in a div tag in the following way:
<div data-cms-area="header_banner_top"></div>. Because header_banner_top is a predefined SMT area, thecms:prefix is used before theview_idargument.Parameters
Name Type Description data_viewString The view to which the child view will be added.
data_viewis the value of the 'data-view' or 'data-cms-area' data attributes of an element on the page. For example, the header logo view uses the following data-view data attribute:<div data-view="Header.Logo">.view_constructorSimpleChildViewConstructor An instance of a view. Use a constructor function to get an instance of a view.
Returns
Throws
Details
-
removeChildView( view_id, placeholder_selector [, view_name ] ) → {void}
-
Description
Removes a child view from a view.
Parameters
Name Type Attributes Description view_idstring The identifier of the view of the current component from which the child view will be removed.
placeholder_selectorstring The identifier of the location in the specified view (view_id) from which the child view will be removed.
view_namestring <optional> The identifier of the view to be removed.
Returns
Throws
Details
-
addToViewContextDefinition( view_id, property_name, type, callback ) → {void}
-
Description
Adds a property to the UI context of a view to extend interaction with its template.
Parameters
Name Type Description view_idstring The identifier of the view of the current component to which the context property will be added.
property_namestring The name of the property.
typestring The type of the property. The value returned by the callback function must be of the same type.
callbackfunction A function that sets the value of the property (property_name).
Returns
Throws
Details
-
removeToViewContextDefinition( view_id, property_name ) → {void}
-
Description
Removes a property from the UI context of a view.
Parameters
Name Type Description view_idstring The identifier of the view of the current component from which the context property will be removed.
property_namestring The name of the property.
Returns
Throws
Details
-
addToViewEventsDefinition( view_id, event_selector, callback ) → {void}
-
Description
Adds an event handler to an event in a view.
Parameters
Name Type Description view_idstring The identifier of the view of the current component to which the event handler will be added.
event_selectorstring callbackfunction The event handler function to call when the specified event occurs.
Returns
Throws
Details
-
removeToViewEventsDefinition( view_id, event_selector ) → {void}
-
Description
Removes an event handler from an event in a view.
Parameters
Name Type Description view_idstring The identifier of the view of the current component to which the event handler will be added.
event_selectorstring Returns
Throws
Details
Events
-
beforeLogin
-
Description
A cancelable event triggered before a user is logged in. The event occurs after the Log In button is clicked and before any data is sent to the NetSuite backend. Login data is passed to the event as an object with the following structure:
{ email: "johnsmith@example.com", password: "password", redirect: true }If there are custom fields on the login form, they are passed as additional properties of the object. For example, if a two-factor authentication code field is included on the login form and the value of its name attribute is
twofacode, the object will include a property calledtwofacode.
Note: With thebeforeLoginevent, data from custom fields is discarded and is not saved in NetSuite.{ email: "johnsmith@example.com", password: "password", redirect: true, twofacode: "123456" } -
beforeRegister
-
Description
A cancelable event triggered before a visitor is registered in the system. The event occurs after the Register button is clicked and before any data is sent to the NetSuite backend. Registration data is passed to the event as an object with the following structure:
{ firstname: "John", lastname: "Smith", company: "NetSuite", email: "johnsmith@example.com", password: "123-abc-*&%", password2: "123-abc-*&%", emailsubscribe: "T" }If there are custom fields on the registration form, they are passed as additional properties of the object. The data from custom fields are persisted in NetSuite, provided the corresponding custom field records exist in the system. The field names on the registration form must match the internal ID of the fields in NetSuite.
-
afterRegister
-
Description
A cancelable event triggered after registration has been completed successfully. If you use the
afterRegisterevent, you must explicitly redirect to the registration success page or to another landing page.In the following example, the web store visitor is redirected to a different URL if the value of the custom field
custentity_vatnostarts with the stringDE.var loginRegisterPageComponent = container.getComponent('LoginRegisterPage'); if (loginRegisterPageComponent) { loginRegisterPageComponent.on('afterRegister', function(formFields) { if (formFields.custentity_vatno.indexOf('DE') == 0) { location.href = 'https://example.com/de/'; } else { location.href = 'https://example.com/'; } }) } -
afterShowContent
-
Description
Event triggered after content has been rendered in the main view. This event is available in components that extend VisualComponent (such as PDP, PLP, or Layout) and is triggered by the showContent() method.
See the Work with Events help topic in the NetSuite Help Center for more information.
Details
-
beforeShowContent
-
Description
Event triggered before content in the main view is rendered. This event is available in components that extend VisualComponent (such as PDP, PLP, or Layout) and is triggered by the showContent() method. For example, if the URL changes in the application, the showContent() method is called, which triggers the event.
Details