All requires we have seen in previous chapters of SFRA course that starts with dw/ means that are part of the Salesforce Commerce Cloud API. we don’t have access to the source code. In case you need details, functions, attributes about any of them, refer to the official documentation.
The use will them to access data about the system, such as: products, catalogs, prices, etc. You can access the API from both controllers and ISML templates for expressions or inside <isscript> tags.
The Digital Script API is organized in packages, just like Java. Unlike Java, inheritance is not possible from these classes or packages when you create a script. You can only use the properties and methods of these classes in your scripts.
In this API, the TopLevel package is the default package. It is similar to java.lang in Java. It does not need to be imported into scripts. It provides standard ECMAScript classes and extensions, such as: Error, Date, Function, String, Math, Number, XML.
The TopLevel.global class contains many of the common constants and properties used in scripts. Some properties are: customer, request and session.
In these packages there are many classes that end with Mgr: These classes, for example, dw.catalog.ProductMgr, retrieves instances of business objects related to the package they belong to.
For example, use ProductMgr.getProduct(String id) to get a product using a unique identifier. The method returns a Product instance which you can use to find information about the product. This pattern is repeated for all Managers.
The table below shows the description of some of these packages. You don’t need to remember everything, just use it as a reference for future needs:
|eCommerce API Packages||Description|
For campaign and promotions.
Classes: PromotionMgr, Campaign, Promotion, SourceCodeGroup, etc.
For catalog, product, and price book.
Classes: CatalogMgr, Category, Product, Recommendation, PriceBook, etc.
For non-product content management.
Classes: ContentMgr, Content, Folder, Library, etc.
For customer profile and account.
Classes: CustomerMgr, Customer, Profile, ProductList, OrderHistory, etc.
For orders, including: basket, coupons, line items, payment, shipment
Classes: Basket, Order, ProductLineItem, ShippingMgr, TaxMgr, etc.
|Generic API Packages||Description|
Encryption services using JCA; DES, Triple-DES, AES, RSA, etc.
Classes: Cipher, MessageDigest
Input and output.
Classes: File, FileReader, CSVStreamReader, XMLStreamReader, etc.
System base classes and custom objects.
Classes: PersistentObject, ExtensibleObject, CustomObjectMgr, etc.
Web services related APIs.
Classes: WebReference, Stub
Classes: Site, Request, Session, Logger
Similar to the java.util API: collections, maps and calendar classes.
Immutable value objects.
Classes: Money, Quantity
Classes: URLUtils, Forms, Cookie, HttpParameterMap, etc.
You can also embed SFCC Script API calls into ISML by using the <isset> tag as you can see below:
Inside of the <isscript> tag, you can fully qualify every class you want to use or you can import any packages at the top of the script:
var CatalogMgr = require('dw/catalog/CatalogMgr'); var siteCatalog = CatalogMgr.getSiteCatalog(); ...
Create a Controller that requires needed customer Digital Script API and send to a new template.isml if current customer is authenticated or not.