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
-
getCookieOptions() → {Deferred}
-
Description
Gets the cookie preferences of a customer from the customer record in NetSuite. Cookie preferences are a list of key/value pairs that correspond to the cookie names and a boolean value (
true
orfalse
), as well as the last date the customer updated the preferences.Note: The SuiteCommerce Analytics Data feature must be enabled in the NetSuite account to use this method. See the NetSuite Help Center (login required) for more information.
This method only affects the cookie preferences of website visitors who are logged in. If the visitor is not logged in, it returns
null
.In the following example,
getCookieOptions
is used to get the value of the cookie preference with the name 'ADVERTISING'.var userProfile = container.getComponent('UserProfile'); userProfile.getCookieOptions().then(function(cookieOptions) { if (cookieOptions.ADVERTISING === true) { // ... } }); // Example of the object returned { PERFORMANCE: true, ANALYTICS: true, ADVERTISING: false, consentLastUpdate: 1506878040000 }
Returns
Details
-
getCreditCards() → {Array.<CreditCardInfo>}
-
Description
Gets read-only credit card information associated with the customer who is currently logged in. You can only use this method on a secure domain; if you use it on a non-secure domain, it returns an error.
In the following example,
getCreditCards()
is used to obtain all credit cards. We then check if any of the credit cards have expired based on theexpirationDate
property of each card in the returned array.// Basic validation of credit card expiry date. Returns True if credit card has expired. function creditCardExpired(ccDate) { var now = new Date(); var currentMonth = now.getMonth() + 1; var currentYear = now.getFullYear(); var regExpCard = /^(\d{1,2})\/(\d{1,2})\/(\d{4})/; var regExpCardMatched = ccDate.match(regExpCard); var ccCardMonth = regExpCardMatched[1]; var ccCardYear = regExpCardMatched[3]; if (ccCardYear < currentYear) { return true; } else if (ccCardMonth <= currentMonth) { return true; } else { return false; } } var userProfile = container.getComponent('UserProfile'); userprofile.getCreditCards().then(function(creditCards) { for (i = 0; i <= creditCards.length; i++) { if (creditCardExpired(creditCards[i].expirationDate)) { alert("Credit card " + creditCards[i].number + " has expired."); break; } } }).fail(function(error) { console.log(error); });
Returns
Details
-
getCustomerSegments() → {Deferred.<Array.<CustomerSegment>>}
-
Description
Gets the customer segments to which a website visitor belongs. Visitors usually belong to at least two customer segments and may belong to additional customer segments depending on the configuration of the NetSuite account. A customer segment is a group of customers to which you can assign a personalized catalogue view (a specific set of items in NetSuite).
Note: The Personalized Catalogue Views (PCV) feature must be enabled in the NetSuite account to use this method. See the Personalized Catalogue Views topic in the NetSuite Help Center for more information about PCV.
When you enable the feature and use this method in an extension, you can access a number of default customer segments. The default customer segments are accessible with the
DEFAULT_SEGMENTS
constant. See the Defining Customer Segments topic in the NetSuite Help Center for more information.Name ID ALL_USERS -1 ANONYMOUS_USERS -2 RECOGNIZED_AND_LOGGED_IN_USERS -3 var userProfile = container.getComponent('UserProfile'); console.log(userProfile.DEFAULT_SEGMENTS); // {ALL_USERS: -1, ANONYMOUS_USERS: -2, RECOGNIZED_AND_LOGGED_IN_USERS: -3} console.log(userProfile.DEFAULT_SEGMENTS.ALL_USERS); // -1
Use the
getCustomerSegments()
method when you want to do something based on the customer segments to which a website visitor belongs. For example, you might set up a customer segment for customers who reside in a particular jurisdiction. In an extension, you could then show products that can only be sold in that jurisdiction.In the following example,
getCustomerSegments()
is used to check if the visitor is in a customer segment with the id '123'.var userProfile = container.getComponent('UserProfile'); userProfile.getCustomerSegments().then(function(customerSegments) { for (i = 0; i < customerSegments.length; i++) { if (customerSegments[i].id == '123') { // ... } } });
Returns
Details
-
getUserProfile() → {UserProfileInfo}
-
Description
Gets read-only information about the current web store visitor. If the visitor is logged in as a user, you can get details such as the user's first name and last name, the user's addresses, credit limit, current balance, and more. Refer to the UserProfileInfo object for a list of all properties.
If a web store visitor is not logged in, this method returns a smaller set of properties. Note that visitors may be recognised even if they are not logged in. You can check for this with the
isrecognized
property of the UserProfileInfo object.This method returns a predefined set of fields from the customer record in NetSuite, as specified in the
UserProfileInfo
object definition. It may also return custom fields from the customer record. Custom fields are returned only if the Web Site box is checked on the Applies To tab on the custom field record. See Creating a Custom Field in the NetSuite Help Center for more information about how to create custom fields.var userprofilecomponent = container.getComponent("UserProfile"); userprofilecomponent.getUserProfile().then(function(profile) { firstname = profile.firstname; lastname = profile.lastname; fullname = firstname + " " + lastname; console.log("User: Full Name: " + fullname); });
Returns
Details
-
setCookieOptions( cookieOptions ) → {Deferred}
-
Description
Lets you set a customer's cookie preferences on the customer record. Cookie preferences relate to the customer's consent as regards data collection about the customer's behavior on the website after the customer has logged in.
Note: The SuiteCommerce Analytics Data feature must be enabled in the NetSuite account to use this method. See the NetSuite Help Center (login required) for more information.
To set cookie preferences, you pass in an object that contains a set of key/value pairs. The key is the cookie preference name, which must be an alphanumeric string. The value must be either
true
orfalse
. True generally means the customer agrees to the use of a certain type of cookie, whereas false means the customer does not agree. You can use any valid text string for the cookie preference name.If you use the text string 'ANALYTICS' as the cookie preference name, however, and its value is
true
, it indicates that the customer's user behavior data will be processed in NetSuite.var userProfile = SC.Application.getComponent('UserProfile'); var cookieoption = { ANALYTICS: true, PERFORMANCE: true, ADVERTISING: false }; userProfile.setCookieOptions(cookieoption).then(function(response) { console.log('setCookieOptions was successful.'); }).catch(function(error) { console.log('setCookieOptions failed.'); console.log(error); });
The cookie preferences you set with this method are stored on the customer record for the logged in user. You cannot view the cookie preferences directly on the customer record, but you can access the stored preferences with SuiteScript - see the NetSuite Help Center for more information.
Parameters
Name Type Description cookieOptions
CookieOptions The customer's cookie preferences that will be stored on the customer record. You should not include the
consentLastUpdate
key in the cookieOptions object when setting the cookie options.Returns
Details
-
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
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
Details