Understanding Server-Side JavaScript

The various Salesforce B2C Commerce development components give you a great deal of flexibility in how you customize your ecommerce application. You will be developing your application locally in Studio, but actually running it on the server. A JavaScript interpreter runs on the application server to process each JavaScript class or method.

Use the B2C Commerce APIs (a combination of JavaScripts and pipelets) to make scripting calls. Standard pipelets uses the APIs internally. To the JavaScript interpreter, the source of the script call is irrelevant.

B2C Commerce development components that can make JavaScript calls include the following:

Component Description Scripting Usage
Pipeline

Models the business process of the storefront application, including the actual business process, page display and data input and validation.

For example, the stores pipeline locates the nearest stores and lists them on the browser.

Use an EVAL pipelet to evaluate an expression.
Pipelet

Small, reusable units or building blocks that define B2C Commerce business logic.

For example, the addProductToBasket pipelet within the cart pipeline creates and returns a ProductLineItem by assigning the specified Product and Quantity to the specified Basket.

Custom: Create a new pipelet within a pipeline that calls a script.ds file to invoke a new business process.

Standard: Access JavaScript for commonly used processes.

Template

Templates define how data and page information is transformed into the HTML that is rendered on a browser.

For example, the cart template defines how the cart page appears, which includes basket contents, shipping types, product variations, availability, promotions and shipping and tax calculations. This template uses <isscript> to run through odd/even row colors.

Access a business process via an <isscript> tag, or wherever B2C Commerce JavaScript APIs are used.

How you use each of these elements depends on your application requirements.

For more information on the APIs, refer to the B2C Commerce Script API documentation.

Cartridge Storage

B2C Commerce JavaScript must be stored in the /cartridge/scripts folder of a cartridge, with the .ds extension. However, it's possible to call a script from a different cartridge using the following syntax:
cartridge:folder\subfolder\scriptfile.ds
Note: When you specify a script in this way, it doesn't search the cartridge path the way it would for a template, pipeline, js or css file.