Demandware Script (DS)
Overview
The server-side language used for coding in the Demandware Platform is Demandware Script (DWScript).DS is based on JavaScript, which is standardized as ECMAScript.
Use: access data about the system, such as products, catalogs, prices.
Write in: pipelines inside Decision nodes, and in ISML templates for
expressions or inside <isscript> tags. But by far the most extensive use of DS is inside Script pipelets.
API Packages
The Demandware Script API is organized in packages just like Java.
However, you cannot inherit from these classes or packages when you create a script, which is indeed different from Java. You can only use the properties and methods of these classes in your scripts.
TopLevel package
This is the default package in Demandware Script. It does not need to be imported in scripts. It provides standard ECMAScript classes and extensions, such as: Error, Date, Function, String, Math, Number, XML.
Of interest here is the TopLevel.global class, which contains many of the common variables and constants used in pipelines and scripts, such as:
Constants: PIPELET_NEXT and PIPELET_ERROR
These are used to indicate (表明) the result of a script pipelet and determine which exit the pipeline takes after pipeline execution
Properties: customer, request and session
These are commonly used in scripts to get access to the current customer and the current session
IMPORTANT NOTE
In the following packages you will find many classes that end with the word Mgr, for example: dw.catalog.ProductMgr. The role of these classes is to retrieve instances of business objects related to the package they belong to: you 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.
Using Demandware Script in ISML
Demandware Script can be embedded into ISML by using the <isscript> tag. The example code below shows how to get the root category of a current site’s navigation catalog as well as getting the category named 'sale' using Demandware script.
Inside of the <isscript> tag you can fully qualify every class you want to use or you can choose to import any packages at the top of the script:
<isscript>
importPackage(dw.catalog);
var siteCatalog = CatalogMgr.getSiteCatalog();
</isscript>
Script Pipelets
Demandware Script files have an extension of .ds and are stored in the
/cartridge/scripts directory.
Script files like Pipelets, can have input and output parameters for data manipulation.
When you create a new script file, the file will be preconfigured (预配置) for scripting.
Input & Output Parameters
Input and output parameters are configured within the script text. The script text below is an example of an input parameter that is called ‘ProductID’ which takes in a string value while the output parameter is called ‘Product’ and returns a product object
When you first create a script file, the input and output parameters are commented out with a *- so you will need to delete the minus sign for the Demandware application to read the parameters
For input/output data types, you can use TopLevel package classes such as String, Number, Object, etc. You can also specify any other data type as long as you fully qualify it: dw.catalog.Product. In the following snippet the TopLevel.Object data type allows you to avoid having to qualify the object you are returning:
@output Subscription : Object
@output Product : dw.catalog.Product Must fully qualify this output type
Importing
When working with script files, if you access Demandware Script packages or classes other than TopLevel, you will need to import them in the script using the following syntax:
importPackage ( dw.system );
You can import a single class, if you wish:
importClass( dw.system.Logger );
You can import a custom script from the same cartridge as the current script you are writing:
importScript( "common/libJson.ds" );
If you are accessing a script in another cartridge, make sure you specify the cartridge prior to the script name as the system will not look for further scripts with the same name in the cartridge path:
importScript( "<cartridge name>:[folder/]utilities.ds" );
Of course, you can always fully qualify the access to a specific class and avoid importing that package/class.
Using the Script Editor
You can turn on line numbers on the script by right-clicking the gray column on the left side of the editor and selecting the Show Line Numbers checkbox
The editor offers auto-complete capabilities and syntax checking: use these tools to minimize coding errors. Studio will automatically generate code hints when you click Ctrl+Spacebar:
Scripts and Cartridge Path Relationship
Although script pipelets can reference scripts in the same cartridge or from dependent cartridges, scripts are NOT searched using the cartridge path, unlike pipelines. A script is expected to(希望) be in the cartridge of the current executing pipeline unless the cartridge is explicitly stated in the ScriptFile configuration property. In the figure below, the solutions cartridge, product directory (under scripts), GetProduct.ds script will be used:
虽然script pipeliets可以引用scripts在相同的cartridge, 或依赖的cartridge, scripts不是使用cartridge来搜索的,不像pipleline. 一个script希望在一个cartridge在当前执行pipeline中。除非cartridge 明确地指明在ScriptFile配置属性中,像下面这样,solutions cartridge, product 目录(在scripts下),GetProduct.ds 脚本将被使用
Of course, this means that you will need to add the solutions cartridge to the cartridge path so the script is found. In which order the solutions cartridge appears in the path is not relevant from the point of view of script access. However, the order of cartridges is relevant for executing pipelines and templates, in which case the first matching file found is used.
当然,这意味着你将需要添加solutions cartridge到cartridge path,这样script 才会被找到。Solution出现在path的什么位置与访问脚本无关,然而,cartridges的顺序对执行pipeline和templates有关,在这种情况下,第一个被找到的文件会被使用。
The ScriptLog Output
Every script pipelet used in a pipeline comes with a default Dictionary Output property called the ScriptLog, of type String:
You can write to the ScriptLog output within your script by using the
TopLevel.global.trace(msg : String , params : Object ...)
method which uses Java MessageFormat. While this capability(功能) exists in the platform as a way to write debug or error messages to the pipeline, its use is not recommended at this time. We suggest you use the dw.system.Logger API to write to log files instead.
Script Debugging
Studio gives you the ability to debug scripts as well as pipelines. In order to use a script debugger you must first create a script debug configuration. The process for creating a script debug configuration is identical (相同) to the pipeline debug configuration setup:
In order to use the debug configuration you will need to add breakpoints in your script files.
When debugging, it is possible to run the script debugger along with the pipeline debugger.
Resource API and Resource Bundles (翻译功能)
In storefront code you want to avoid hard-coding text strings that become visible to the user. Titles, labels, messages, button and field names should all be externalized by using resource bundles (又名properties files.). Also, if you do not want to duplicate ISML templates in order to create locale-specific templates, you can use resource bundles to keep your template generic and reusable.
A resource bundle is a file with a .properties extension that contains the hard coded strings to be used in ISML templates. In SiteGenesis bundles are loosely named by the functional area where the strings are used, but you can use any file name and organization you want.
IMPORTANT NOTE
Property files can be suffixed by “Bundlename_<<locale_id>>.properties” where “<<locale_id>>” stands for a specific locale term other than the default locale.
For example, “de” or “en”
(or locale plus country like “de_DE” or “en_GB”).
The resource bundles contain key=value pairs where the key might be compound 复合型key : (key.subkey) and the value is a hard-coded string that uses Java MessageFormat syntax to implement parameter replacement. Bundles are stored in each cartridge within the /templates/resources directory
Strings from the bundles are accessible to all ISML templates via the
dw.web.Resource.msg(key : String , bundleName : String , DefaultMessage : String ) method:
<h1> ${Resource.msg(‘account.header’, ‘account’, null)} </h1>
Notice that the second parameter points to the account.properties file, which may be overridden by another cartridge in the cartridge path. The null in the third parameter means that the key itself will be used whenever that key is not found on any resource bundle. Instead of the null you can also show a string to display on the storefront in case the key could not be found.
Another useful method is the
dw.web.Resource.msgf(key : String , bundleName : String , defaultMessage : String , args : Object...). Using this method you can specify a key with placeholders which can be dynamically replaced by the parameters specified in the args argument of the method. For example, this usage of the method:
${Resource.msgf('singleshipping.wishlist', 'checkout', null,owners.get(addressKey).profile.firstName )}
Will be paired with the following Java MessageFormat definition in the resource bundle to allow the first name of the wishlist’s owner to show up as Stefan’s Wishlist:
singleshipping.wishlist={0}\'\'s Wishlist
相关推荐
它是通过编排不同的 WebDriver 构建的,可以在 Firefox 或XLT 框架中与XLT Script Developer一起运行。 由于测试套件有时会变得复杂且难以维护,因此我们意识到是时候使用一组定义明确的测试来构建结构清晰的测试...
基于arm64版本的docker-compose文件
台区终端电科院送检文档
埃夫特机器人Ethernet IP 通讯配置步骤
rv320e机器人重型关节行星摆线减速传动装置研发
气缸驱动爬杆机器人的设计().zip
56tgyhujikolp[
内容概要:本文档提供了基于OpenCV的数字身份验证系统的Python代码示例,涵盖人脸检测、训练和识别三个主要功能模块。首先,通过调用OpenCV的CascadeClassifier加载预训练模型,实现人脸检测并采集多张人脸图像用于后续训练。接着,利用LBPH(局部二值模式直方图)算法对面部特征进行训练,生成训练数据集。最后,在实际应用中,系统能够实时捕获视频流,对比已有的人脸数据库完成身份验证。此外,还介绍了必要的环境配置如依赖库安装、文件路径设置以及摄像头兼容性的处理。 适合人群:对计算机视觉感兴趣的研发人员,尤其是希望深入了解OpenCV库及其在人脸识别领域的应用者。 使用场景及目标:适用于构建安全认证系统的企业或机构,旨在提高出入管理的安全性和效率。具体应用场景包括但不限于门禁控制系统、考勤打卡机等。 其他说明:文中提供的代码片段仅为基本框架,可根据实际需求调整参数优化性能。同时提醒开发者注意隐私保护法规,合法合规地收集和使用个人生物识别信息。
内容概要:本文档详细介绍了Java并发编程的核心知识点,涵盖基础知识、并发理论、线程池、并发容器、并发队列及并发工具类等方面。主要内容包括但不限于:多线程应用场景及其优劣、线程与进程的区别、线程同步方法、线程池的工作原理及配置、常见并发容器的特点及使用场景、并发队列的分类及常用队列介绍、以及常用的并发工具类。文档旨在帮助开发者深入理解和掌握Java并发编程的关键技术和最佳实践。 适合人群:具备一定Java编程经验的研发人员,尤其是希望深入了解并发编程机制、提高多线程应用性能的中级及以上水平的Java开发者。 使用场景及目标:①帮助开发者理解并发编程的基本概念和技术细节;②指导开发者在实际项目中合理运用多线程和并发工具,提升应用程序的性能和可靠性;③为准备Java技术面试的候选人提供全面的知识参考。 其他说明:文档内容详尽,适合用作深度学习资料或面试复习指南。建议读者结合实际编码练习,逐步掌握并发编程技巧。文中提到的多种并发工具类和容器,均附有具体的应用场景和注意事项,有助于读者更好地应用于实际工作中。
这个数据集包含了日常步数统计、睡眠时长、活跃分钟数以及消耗的卡路里,是个人健康与健身追踪的一部分。 该数据集非常适合用于以下实践: 数据清洗:现实世界中的数据往往包含缺失值、异常值或不一致之处。例如,某些天的步数可能缺失,或者存在不切实际的数值(如10,000小时的睡眠或负数的卡路里消耗)。通过处理这些问题,可以学习如何清理和准备数据进行分析。 探索性分析(发现日常习惯中的模式):可以通过分析找出日常生活中的模式和趋势,比如一周中哪一天人们通常走得最多,或是睡眠时间与活跃程度之间的关系等。 构建可视化图表(步数趋势、睡眠与活动对比图):将数据转换成易于理解的图形形式,有助于更直观地看出数据的趋势和关联。例如,绘制步数随时间变化的趋势图,或是比较睡眠时间和活动量之间的关系图。 数据叙事(将个人风格的追踪转化为可操作的见解):通过讲述故事的方式,把从数据中得到的洞察变成具体的行动建议。例如,根据某人特定时间段内的活动水平和睡眠质量,提供改善健康状况的具体建议。
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
nginx
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
模拟知识付费小程序,可流量主运营模式
什么是普通上传 调用接口一次性完成一个文件的上传。 普通上传2个缺点 文件无法续传,比如上传了一个比较大的文件,中间突然断掉了,需要重来 大文件上传太慢 解决方案 分片上传
英二2010-2021阅读理解 Part A 题干单词(补).pdf
2023-04-06-项目笔记-第四百五十五阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.453局变量的作用域_453- 2025-04-01
微信小程序项目课程设计,包含LW+ppt