Script Access Examples

Use examples to understand how to incorporate script into your storefront.

Consider the following examples, taken from the SiteGenesis application:

Pipeline

The following is an example of using the EVAL pipelet in a pipeline to evaluate an expression, which in this case is confirms the order status.

Pipeline: COPlaceOrder-PlaceOrder

Pipelet: EVAL: Confirm order

Expression: Order.setConfirmationStatus(Order.CONFIRMATION_STATUS_CONFIRMED)

Pipelet: Custom

The continueshopping.ds script file is called by a Script pipelet in the Cart-ContinueShipping pipeline to find the last catalog click and return it as the target for the continue shopping button redirect.

/**
* The script finds the last catalog click and returns it
* as the target for a redirect.
*
* @output Location : String
*/
 importPackage( dw.system );
 importPackage( dw.web );
 importPackage( dw.util );
 function execute( pdict : PipelineDictionary ) : Number
{
 // find the last catalog related click
 var list : List = session.clickStream.clicks;
 for( var i = list.size()-1; i >= 0; i-- )
{
 var click : ClickStreamEntry = list[i];
 switch( click.pipelineName )
{
 case "Product-Show":
 // product detail page click
 pdict.Location = click.url.replace(/source=/g, "src=").replace(/format=/g, "frmt=");
 // hack to change product URL if it was viewed from search
 return PIPELET_NEXT;
 case "Search-Show":
 // catalog related click
 pdict.Location = click.url.replace(/source=/g, "src=").replace(/format=/g, "frmt=");
 // avoid showing product grid only
 return PIPELET_NEXT;
}
}
 // nothing found, go to the home page
 pdict.Location = URLUtils.httpHome().toString();
 return PIPELET_NEXT;
} 

In the example, the script imports and uses API calls from dw.system, dw.web, and dw.util. The JavaScript class URLUtils.url is located in the dw.util package.

Pipelet: Standard

The JavaScript used in a standard pipelet isn't public. For example, the GetProduct pipelet returns the product that is identified by a supplied product ID. The actual internal JavaScript code is unavailable to the developer.

Template

The following portion of the ordertotals.isml template uses <isscript> to calculate order-level discounts as part of the order total.

<iscomment>calculate order level discounts</iscomment>
<isscript>
	var merchTotalExclOrderDiscounts : dw.value.Money = LineItemCtnr.getAdjustedMerchandizeTotalPrice(false);
	var merchTotalInclOrderDiscounts : dw.value.Money = LineItemCtnr.getAdjustedMerchandizeTotalPrice(true);
	var orderDiscount : dw.value.Money = merchTotalExclOrderDiscounts.subtract( merchTotalInclOrderDiscounts );
 </isscript>

The example uses the getAdjustedMerchandizeTotalPrice method.