new Search()

Description

The Search component enables you to retrieve the URL of the item search API of the SuiteCommerce website. See the Item Search API topic in the Help Center for more information about this API.

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

See the Working with the Search Component topic in the Help Center for an in-depth example of how you might use the Search component. It explains how to use the getUrl() method to set the url attribute of models and then show the related items on a web store page.

Details

SuiteCommerce 21.1

Methods


getUrl( [ search_filters ] ) → {String}

Description

Retrieves the URL of the item search API of the SuiteCommerce website. Note that this method only retrieves the item search API URL; it does not execute the search.

You can append parameters to the returned URL by passing in an object of property/value pairs to the method. The property name can be any parameter accepted by the item search API. For example, to specify a list of fields, use the property name 'fields' with the field names as a comma separated list of fields: {fields: "dimensions,finish"}. For comprehensive information about item search parameters, see the Item Search API Input Parameters topic in the Help Center.

You can also append a special property called apiMasterOptions, which lets you use search API fieldsets as defined on the SuiteCommerce configuration page in the NetSuite account. The value of apiMasterOptions is the ID of a search API fieldset. When getUrl is called, it gets the values of the Fieldset and Includes columns for the specified ID and appends them to the URL in the format fieldset=[Fieldset]&include=[Includes]. See Search Results Subtab in the Help Center for more information.

If you include both apiMasterOptions and the property name 'fieldset' as parameters, the apiMasterOptions parameters takes preference and sets the value of 'fieldset' in the returned URL.

The following example shows how to get the item search URL with search parameters for a keyword (q), additional fields (fieldset), and a facet field name (dimensions). The returned URL includes the specified parameters and might look like the following:

/api/items?language=en&country=US&currency=USD&pricelevel=5&use_pcv=F&q=frames&fieldset=relateditems&dimensions=52x30

         var search = container.getComponent("Search");
			var searchParams = {
			 q: "frames", 
			 fieldset: "relateditems", 
			 dimensions: "52x30"
			};
			
			var searchUrl = search.getUrl(searchParams);
			

 

The following example shows how to get the item search URL with search parameters for a keyword (q), additional fields (fieldset), and a facet field name (dimensions). We have also included the apiMasterOptions parameter, which will take preference over the fieldset parameter. The returned URL might look like the following:

/api/items?language=en&country=US&currency=USD&pricelevel=5&use_pcv=F&q=frames&dimensions=52x30&fieldset=details&includes=facets

         var search = container.getComponent("Search");
			var searchParams = {
			 q: "frames", 
			 fieldset: "relateditems", 
			 dimensions: "52x30", 
			 apiMasterOptions: "itemDetails"
			};
			
			var searchUrl = search.getUrl(searchParams);
			

 

Some parameters, which correspond to data from the user session such as the language and country, may be automatically appended to the URL. language, country, currency, pricelevel, and use_pcv from the two sample URLs above are examples of user session data.

Parameters
Name Type Attributes Description
search_filters Object <optional>

One or more filters to append to the item search URL.

Name Type Attributes Description
* Boolean | Number | String <optional>

The name of any valid search API input parameter.

apiMasterOptions String <optional>

The ID of a search API fieldset.

Returns

Returns the item search API URL of the SuiteCommerce website. The domain name of the website is not included in the returned URL.

Details

SuiteCommerce 21.1