Creating Custom Functions for Scriptable Cart

By creating custom functions, you can link events to functions that are only applicable to the shopping cart. Because your script is running against a sales order form, other events related to a sales order transaction also execute along with the events you specify in your script for the shopping cart. This could adversely impact performance.

The main reason for creating custom functions is to filter out events that do not apply to the web store. Sample custom functions are listed below:

function customInit(type)

Use this custom function to call any functions related to login.

          function customInit(type)
{
   //call any functions related to login here.
} 

        

function customOnChange(type, name, linenum)

Use this custom function to link to the FieldChanged event and filter out non-Web store events.

          function customOnChange(type, name, linenum)
{
         if (name == 'promocode')
         {
   // call any functions that are triggered by promocode here
        sample();
  } 

        

function customRecalc(type, action)

Use this custom function to link to the Recalc client event. In Scriptable Cart, the action can only be 'commit' or 'remove.' Note that only events related to items are applicable to Scriptable Cart.

          function customRecalc(type, action)
{
            if (type == 'item')
            {
                        // call any functions related to recalc here
                        sample1(action);
                        sample2(action);
            }
} 

        

function customValidateLine(type)

Use this custom function to link to the ValidateLine event. Note that all validations occur in the item list on the shopping cart page. For best results, filter out any events that are not executed against items.

The return value of each function called from customValidateLine must be tested. If any function returns false, processing must stop and return false.

          function customValidateLine(type)
{
            if (type != 'item')
            {
                        return true;
            }
             if (!sample())
            {
                        return false;
            }
            if (!bar())
            {
                        return false;
            }
            // All validations passed, so return true
            return true; 

        

function customBeforeSubmit()

This custom function will execute before a sales order is saved. Scripts that include the beforeSubmit() gateway function must be attached to a script record of type User Event.

          function customBeforeSubmit()
{
            return sample();
} 

        

function customAfterSubmit()

This custom function will be run after a sales order is saved. Scripts that include the afterSubmit() gateway function must be attached to a script record of type User Event.

          function customAfterSubmit()
{
            return sample();
} 

        
Note:

You can combine the deployment for both the customBeforeSubmit() function and the customAfterSubmit() functions on the same script deployment record when necessary. For more information, see Deploying and Running Scriptable Cart.

Related Topics

Working with Field Changed Client Events
SuiteScript for Scriptable Cart
Sample Scripts for Scriptable Cart
Scriptable Cart FAQ

General Notices