ShoppingSession Methods

This topic applies to

Applies to

SuiteCommerce Web Stores

A shoppingSession object tracks context.

The following methods are available:

constructDomainBridgingUrl(link)

Converts cross-domain link to domain bridging URL containing encrypted parameters. This method provides a secure way to transfer shopper data between different domains.

Note

Do not change or extract data from the domain bridging URL as the format of the URL may change. Only use the URL in the browser to retrieve and apply the shopper session data from the original domain.


Parameters
  • link [required] {String} – Absolute or relative URL of link targeting a different shopping or checkout domain from the one the shopper is currently on

Returns
  • link {String} – Domain bridging URL; the original URL is returned if bridging is either not possible or not necessary

  • null – Returned if the input parameter is invalid

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

doChangePassword(Params, newPassword)

Changes the password for the customer identified by email. Returns true if the password is changed correctly.

Throws the following errors:

  • ERR_WS_INVALID_LINK – if parameters contain a token that is expired or incomplete. Note that it is not possible to determine if the link is expired or incomplete. The same error is thrown in either case.

  • ERR_WS_INVALID_PASSWORD – if the password is empty or exceeds the maximum allowed length of 255 characters.

  • ERR_WS_WEAK_PASSWORD – if the password at least 6 characters.

Parameters
  • Params – pass parameters from original request

  • newPassword – {String} value for new password to be set

Returns

Boolean

Supported Domains

Checkout

Login Required?

no

Back toShoppingSession Methods | Back toShopping Objects

getAbsoluteUrl(domaintype,path)

Important

In certain scenarios, the getAbsoluteUrl(domaintype,path) method returns a relative URL instead of an absolute URL. For example, the getAbsoluteUrl(domaintype,path) method returns a relative URL when the target domain is same as the current domain.

Therefore, the getAbsoluteUrl(domaintype,path) method has been deprecated as of NetSuite Release 2017.1. Use the getAbsoluteUrl2(domaintype,path) method instead.


Gets absolute URL for given path and domain type.

Parameters
  • domaintype [optional] {String} - value should be either “shopping” or “checkout”

  • path [required] {String}

Returns

String

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getAbsoluteUrl2(domaintype,path)

Gets absolute URL for given path and domain type.

Note

This method should be used instead of the deprecated getAbsoluteUrl(domaintype,path) method.


Parameters
  • domaintype [optional] {String} - value should be either “shopping” or “checkout”

  • path [required] {String}

Returns

String

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getCampaignID()

Gets the campaign ID of the leadsource parameter from the current session.

Parameters

No parameters to set.

Returns

campaignid {String}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getCorrelatedItems(item)

Gets array of correlated items for given item.

Note

Item details will be returned only if the correlated item is available in the store from which the API was called from.


Parameters
  • item [required]{object with values for fields}

    • internalid [required]

    • itemtype [required]

    • itemfields [optional] {array of item field names to query}

Note

For better performance limit the number of queried fields by specifying only fields you need in the itemfields array.


Returns

Array of objects of type item

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getCountries()

Gets all countries

Parameters

No parameters to set.

Returns

Array of objects with fields:

  • name {string}

  • code {string}

  • isziprequired {boolean}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getCustomer()

Gets the Customer details from the current session.

Parameters

No parameters to set.

Returns

Returns the customer shopping object. For more information, see Customer Methods.

Note

The customer object holds information within the given shopping session only and is different from the NetSuite customer record.


Supported Domains

Checkout, Shopping

Login Required?

Yes

Back toShoppingSession Methods | Back toShopping Objects

getCountryTaxPreferences()

Returns a JSON object with tax preferences related a shopper’s country. The values returned are based on the default shopper subsidiary derived from the site or the country selected by the shopper.

Parameters

No parameters to set.

Returns
  • vatregistration {boolean} — When set to T, the VAT registration field can be displayed during checkout and the vatregistration can be set on the customer object.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getEffectiveShoppingDomain()

Returns name of shopping domain associated with current session.

Parameters

No parameters to set.

Returns

domainname {String} – The shopping domain related to the current session. For example: shopping.corp.netsuite.com.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getInformationItemFieldValues(infoItems)

Gets attribute values for given information items.

Parameters
  • infoItems [required] {Array}

Each object in array has values for field:

  • internalid [required]

Returns

Array of objects of type item.

Note

Depending on item fields configured, the array of objects returned might differ.


Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getItemFieldValues(items)

Gets attribute values for given items.

Parameters
  • items [required] {Array} Each object in array has values for fields:

    • internalid [required]

    • itemtype [required]

Returns

Array of objects of type item.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getPartnerID()

Gets the Partner ID of the leadsource parameter from the current session.

Parameters

No parameters to set.

Returns

partnerid {String}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getPasswordHint(customerEmail)

Retrieves password hint for customer with given email address.

Important

Password hints are no longer necessary. The password retrieval email message includes a URL with a password reset code. Therefore, the getPasswordHint() method has been deprecated as of NetSuite Release 2017.2. As of 2017.2, the method will return an empty string, but generate no errors.


Parameters
  • customerEmail [required] {String}

Returns

An empty string

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getPaymentMethod(paymentMethodId, fields)

Gets payment method for given ID.

Parameters
  • paymentMethodId [required] {String}

  • fields [optional] Array of field names to be included in returned JSON object; if omitted, all supported fields are returned

Returns

Object of type paymentmethod.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getPaymentMethods(fields)

Gets payment methods accepted by the web store.

Parameters
  • fields [optional] Array of field names to be included in returned JSON object; if omitted, all supported fields are returned

Returns

Array of objects of type paymentmethod.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getRedirectURL()

 Gets the URL which is the result of a redirect given the input. Returns null if there is no redirect. Wildcards are also supported (*).

Parameters
  • url [required] {String}

Returns

String

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getRelatedItems(item)

Gets array of related items for given item.

Parameters
  • item [required]{object with values for fields}

    • internalid [required]

    • itemtype [required]

    • itemfields [optional] {array of item field names to query}

Note

For better performance limit the number of queried fields by specifying only fields you need in the itemfields array.


Returns

Array of objects of type item.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getRelatedCorrelatedItems()

Gets a list of related and/or correlated items for a given item id.

Parameters
  • type: [required]{string} Available options are RELATED, CORRELATED, or BOTH.

  • fieldsetid : set of fields returned.

  • items: list of item IDs. When not specified, items from the cart are returned.

  • limit : Maximum count of returned items. When not specified, the default 10 is used. -1 sets no limit.

    Important

    Use caution when setting the limit to -1 as this can have an impact on performance.


Example

function service(request, response)
{
  var session = nlapiGetWebContainer().getShoppingSession();
  items = ['101'];
  response.writeLine("Related Items: " + JSON.stringify(session.getRelatedCorrelatedItem'RELATED', 'relateditems', items, 10)));
  response.writeLine("Correlated Items: " + JSON.stringify(session.getRelatedCorrelatedItems('CORRELATED', 'relateditems', items, 10))); 
  response.writeLine("Related & Correlated Items: " + JSON.stringify(session.getRelatedCorrelatedItems('BOTH', 'relateditems', items, 10)));
}
Returns

Array of correlated or related items.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toOrder Methods | Back toShopping Objects

getShipToCountries()

Gets countries to which web store can ship.

Parameters

No parameters to set.

Returns

Array of objects with fields:

  • name{string}

  • code{string}

  • isziprequired {boolean}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getShopperCurrency()

Gets currency for current shopping session.

Parameters

No parameters to set.

Returns

Object with values for fields:

  • internalid {String}

  • name {String}

  • symbol {String}

  • precision {Number}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getShopperLanguageLocale()

Gets language and locale for current shopping session.

Parameters

No parameters to set.

Returns

localeid {String}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getShopperPreferences()

Gets language, subsidiary, and currency preferences for the current shopping session.

Parameters

No parameters to set.

Returns

Object with values for fields:

  • language {String}

  • subsidiary{String}

  • currency{String}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getShopperSubsidiary()

Gets subsidiary for current shopping session.

Parameters

No parameters to set.

Returns

subsidiaryid {String}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getSiteCategoryContents(siteCategory, recursive)

Important

The getSiteCategoryContents() API has been deprecated as of NetSuite Release 2014.2. Use the getSiteCategoryTree() method instead. See getSiteCategoryTree(siteCategory).


Gets contents of given site category.

If not provided, siteCategory will be defaulted to the root category, and recursive will be defaulted to false. When recursive is set to false, the API returns the category contents that include subcategories and items; when recursive is set to true, the API returns the complete tree of subcategories but not items. 

Note

To get the complete category tree from the root, use getSiteCategoryContents(true).


Parameters
  • siteCategory [optional] {Array} Each object in array has values for field: internalid [required]

  • recursive [optional]

Returns

Array of objects of type sitecategory or item.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getSiteCategoryFieldValues(siteCategories)

Gets attribute values of given site categories.

Parameters
  • siteCategories [required] {Array} Each object in array has values for field:

    • internalid [required]

Returns

Array of objects of type sitecategory.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getSiteCategoryTree(siteCategory)

When the internalid attribute is present in the siteCategory object, then the method returns the category sub-tree from this category. When the internalid attribute is not specified, then the whole category tree of the specified site is returned.

When calling this API, you must specify which fields to return. When no fields are specified, then no fields are returned except the internalids of categories. Specify fields using the itemfields attribute on the siteCategory object.

Examples

  • The following example returns the entire category tree for the current site. Each category record contains the fields internalid, pagetitle2, and urlcomponent.

    getSiteCategoryTree({ itemfields : ["pagetitle2","urlcomponent"] });
  • The following example returns the category sub-tree of category 65. Each category record contains only the internalid field.

    getSiteCategoryTree({ id : 65 });

Note

The examples above return only the category tree, not the category contents.


Parameters
  • siteCategory [optional] {Array} Each object in array has values for field: internalid [required]

Returns

Array of objects of type sitecategory

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getSiteSettings(fields)

Gets settings of current web store.

Parameters
  • fields [optional] Array of field names to be included in returned JSON object; if omitted, all supported fields are returned

Returns

Object with fields listed for sitesettings JSON object.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getSSPApplication()

Gets URL root of SSP application powering the current touchpoint.

Parameters

No parameters to set.

Returns

urlroot field value for sitesettings JSON object.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

getStates(countries)

Gets states and/or provinces.

Parameters
  • countries [optional] Array of strings for country codes

Returns

Returns an array of state/province names and state/province codes in the following format:

{"states":[{"name":"Alabama","code":"AL"},{"name":"Alaska","code":"AK"},...], "countrycode":"US"}

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

isChangePasswordRequest()

Returns true if all page parameters from the current request are valid for the password reset.

Throws the error "ERR_WS_INVALID_LINK" if all page parameters from the current request contain required parameters for password reset but the link has expired or is incomplete.

Parameters

No parameters to set.

Returns

Boolean

Supported Domains

Checkout

Login Required?

no

Back toShoppingSession Methods | Back toShopping Objects

isLoggedIn()

Important

This method is no longer supported or recommended. For new implementations, use the isLoggedIn2() method. The isLoggedIn() method works correctly in the Checkout domain but may return false when used in the Shopping domain even when the user is logged in. If you encounter session issues when using this API, contact support to migrate to using the isLoggedIn2() method.


Checks whether customer has logged in. This method can be used with the isRecognized() method. See Using isRecognized() with isLoggedIn2().

Parameters

No parameters to set.

Returns

Boolean

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

isLoggedIn2()

Checks whether customer has logged in. This method can be used with the isRecognized() method. See Using isRecognized() with isLoggedIn2().

Note

This method should be used instead of the deprecated isLoggedIn() method.


Parameters

No parameters to set.

Returns

Boolean

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

isRecognized()

Determines whether a user is recognized. This method can be used with the isLoggedIn2() method. See Using isRecognized() with isLoggedIn2().

Parameters

No parameters to set.

Returns

Boolean

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

logIn(customer)

Logs in a customer.

Parameters
  • customer [required]{object with values for fields}

    • email [required]

    • password [required]

Returns

Object with fields:

  • customerid {String} - internal id of customer record for logged in customer

  • redirecturl{String} - URL to which user is redirected after logging in

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

logout()

Logs out a customer.

Note

If logout() is attempted from a shopping context, it does not succeed and an error is returned.


Parameters

No parameters to set.

Returns

Object with field:

  • redirecturl

The field redirecturl has the complete home URL to redirect to after logout. If not using the redirecturl field returned from logout(), the custom redirecturl should have the logoff=T parameter.

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

proceedToCheckout(checkoutSettings)

Used for integration with a third party checkout provider such as PayPal Express. This API can only be called from a secure scheme (https).

Parameters
  • checkoutSettings Object with values for fields:

    • type; either “paypalexpress” or “google”

    • continueurl

    • cancelurl

Returns

No value returned.

Supported Domains

Checkout

Note

Must have at least one order.


Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

registerCustomer(customer)

Registers the customer and logs them in.

Parameters
  • customer [required]{object with values for fields}

    • firstname [required] {String}

    • lastname [required] {String}

    • companyname [optional] {String}

    • email [required] {String}

    • password [required] {String}

    • password2 [required] {String}

    • passwordhint [optional] {String}

    • emailsubscribe [optional] {String}

    • leadsource [optional] {String}

Returns

Object with values for fields:

  • customerid {String} - internal id of record for registered customer

  • redirecturl {String} - URL to which user is redirected after registering

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

registerGuest(guest)

Registers a guest.

Note

Throws exception if register guest with password.


Parameters
  • guest [optional]{object with values for fields}

    • firstname [optional] {String}

    • lastname [required] {String}

Returns

Object with values for fields:

  • customerid {String} - internal id of record for registered customer

  • redirecturl {String} - URL to which user is redirected after registering

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

sendPasswordRetrievalEmail(customeremail)

Sends password retrieval email message to the given email address.

Important

The password reset link generated by the sendPasswordRetrievalEmail() includes the customer’s email address. Therefore the method has been deprecated as of NetSuite Release 2017.2. Use the sendPasswordRetrievalEmail2(customeremail) method instead.


Parameters
  • customerEmail [required] {String}

Returns

No value returned.

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

sendPasswordRetrievalEmail2(customeremail)

Sends password retrieval email message to the given email address.

Note

This method does not include the customer’s email address in the reset password link. Use this method instead of the deprecated sendPasswordRetrievalEmail(customeremail).


Parameters
  • customerEmail [required] {String}

Returns

No value returned.

Supported Domains

Checkout

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

setShopperCurrency(currencyid)

Sets currency for current shopping session

Note

Multiple Currencies feature must be enabled, specified currency must be supported in sitesettings, and logged in user must have permission to change currency.


Parameters
  • currencyid [required] {string}

Returns

No value returned.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

setShopperLanguageLocale(localeid)

Sets language and locale for current shopping session

Note

Multi-Language feature must be enabled, and specified language must be supported in sitesettings.


Parameters
  • localeid [required]{String}

Returns

No value returned.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

setShopperPreferences(prefs)

Sets language, subsidiary and currency for current shopping session.

Parameters
  • prefs [required]{object with values for fields}

    • language [optional] {String}

    • subsidiary [optional] {String}

    • currency [optional] {String}

Returns

No value returned.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

setShopperSubsidiary(subsidiary)

Sets subsidiary for current shopping session (for NetSuite OneWorld users).

Important

The subsidiary set in a session is not currently supported out-of-the-box for One World in the SuiteCommerce Advanced SuiteApp. For the SuiteCommerce Advanced SuiteApp, further customization is necessary. Also, the subsidiary for an existing recognized customer can not be changed using this API.


Parameters
  • subsidiary [required]{String}

Returns

No value returned.

Supported Domains

Checkout, Shopping

Login Required?

No

Back toShoppingSession Methods | Back toShopping Objects

verifyEmailChange(key)

 Takes an email change key, verifies it, and then changes the email. If the request can't be processed, an exception is thrown.

Parameters
  • key [required]{String} — value of the email change key.

Returns

Boolean

Returns true if the key value is valid and the email has been changed. Returns false in all other cases (for example, if the key is invalid or expired).

Supported Domains

Checkout

Login Required?

Yes

Back toShoppingSession Methods | Back toShopping Objects

Using isRecognized() with isLoggedIn2()

There are four possible cases for using the isLoggedIn2() method and isRecognized() method to correctly determine the logged in status of a user:

  • new (anonymous) user: isRecognized() == false and isLoggedIn2() == false

  • registered and logged in user: isRecognized() == true and isLoggedIn2() == true

  • user who clicked logout: isRecognized() == false and isLoggedIn2() == false

  • user who had logged in, then closed his browser and later returns to the shop: isRecognized() == true and isLoggedIn2() == false

    Note

    This last scenario is the only case where the isRecognized() status differs from the isLoggedIn2() status. In this case the user didn’t click on the logout link and is therefore still recognized but isLoggedIn2() returns false.