Create a Custom Module

NOTE — this page has not been updated since Denali; its information may be incomplete, unreliable, or otherwise out of date

Applies to

SuiteCommerce Advanced

SuiteCommerce Advanced (SCA) is designed so that you can extend it by creating new modules to add functionality specific to your web store. When creating a new module, be aware of the following requirements:

The top level directory of your module should have a directory of the format: module_name@x.y.z where module_name is the name of the module and x.y.z is the version number. See Organize Source Code for Custom Modules

The directory containing your custom module must be in the Modules directory. Modules shipped with SCA are stored in two sub-directories, suitecommerce and third_parties. NetSuite recommends creating a third sub-directory to store all custom module code. Examples in this document name this directory extension, as in Modules/extension/. However, you can name this directory any intuitive name as required.

Your new modules directory must have an ns.package.json file to define all of the module dependencies required by the developer tools. For more information, see Core SuiteCommerce Advanced Developer Tools for more information.

The module name must be unique. You cannot have duplicate module names, even when they reside in different folders.

You must update the distro.json file to ensure that your custom module is loaded into the application.

To add a custom module:

Create a custom module within your custom directory with the format of ModuleName@version.

For example, Modules/extensions/MyCustomModule@1.0.0.

Important

You cannot use existing module names, even when those modules reside in different folders.

Create the subdirectories within the module.

The exact subdirectory structure depends on the requirements of your module and your implementation of SCA. NetSuite recommends that you use the same directory structure as existing application modules. Typically, you will need JavaScript, Sass, SuiteScript, and Templates subdirectories.

Create the necessary files for your module.

This is where all of your modules logic is contained. At a minimum, you will need something like the following:

Note

This procedure does not include examples of backend models or services files which are often necessary for backend integration with NetSuite.

An entry point JavaScript file – this file acts as an entry point to the module and must return an object containing the mountToApp property that receives the application as a parameter.

A template file – this file contains the markup used in combination with the views. Note that the SCA implementation leverages the Handlebars templating engine.

<h2>This is my template file for my new module. It takes variables, {{myNewModuleContextVar}}, passed from the View.</h2>

Important

Template file names must be unique. You cannot have duplicate template file names even when they belong to different modules.

If your custom module contains any configurable properties, you must include a Configuration subdirectory and place your Configuration Modifications here. See Modify JSON Configuration Files for details.

Note

This step only applies to Vinson implementations of SCA and later.

Create a new ns.package.json file within the Modules directory.

This file must contain entries for all of the directories required by the module. Use the following example as a template:

After creating your new module, you can test it by viewing your changes in the application. If you are running a local server, you can view your changes by reloading your website. See SCA on a Local Server for more information.

If you are viewing your site in NetSuite, you can deploy your changes using the developer tools. See Deploy to NetSuite for more information.