Frontend Models
Frontend models contain the data that SuiteCommerce Advanced (SCA) uses. Frontend models are part of the Backbone.js framework that defines the data component within the MVC paradigm. Each frontend model is an extension of Backbone.Model which is defined in BackboneExtras. Backbone.Model defines inheritable methods that are available to all models defined in SCA. If necessary, a model can override these core methods. For example, many modules override the initialize
method to set values of properties that are specific to that model.
If you are customizing SCA 2020.1 and later, do not use Backbone.Model as described in the following sections and examples. For release 2020.1 and later, you should use SCModel as described in the extensibility API reference. SCModel is the SuiteCommerce implementation of Backbone.Model and it inherits all methods and properties of Backbone.Model
Most feature modules define models that hold the data they require. Models in SCA are defined in the following ways:
-
Models that are specific to features are defined by returning an object containing the model. These models are defined using the following syntax:
return Backbone.Model.extend
-
Models that are used by the wider application context. These models are created and their data populated when they are initialized. These models are defined in the following manner:
ProfileModel = Backbone.Model.extend
By defining a model this way, it can be accessed from models and views that are defined outside of the current module. In this example, the ProfileModel can be accessed by other modules that need to access information stored in the user’s profile. Most models that are created this way are defined as singletons. Therefore there can only be one instance defined per user session.
When a router or view initializes a model, it may pass properties that the model requires. These can be properties that the frontend model uses internally or properties that are passed to the backend model.
In general, frontend models contain code that performs the following tasks:
-
Sets initial values of properties
-
Defines model-specific methods
-
Overrides default methods
-
Performs frontend validation of user-submitted data
All frontend modules define the following properties:
-
urlRoot
: specifies the backend service that is used to handle HTTP requests. This property is a string containing a partial URL. -
validation
: specifies an object that defines the properties that are validated when a user submits form data.