Scripting: Maintaining State
A script can't maintain state from one execution to the next. After the execution of a script, all variables are erased from the system.
To maintain state across calls, use other mechanisms such as:
- The Session
- Persistent Business Objects
- Client-side cookies
Using the Session
Use the Session
class to access details about browser
actions, such as:
- The current click stream if it's an HTTP or HTTPS session
- The session's custom attributes (stored for the lifetime of the session and are not cleared when the customer logs out)
- The current customer associated with the storefront session
- If the customer associated with the session is authenticated
- The session's custom privacy attributes (stored for the lifetime of the session and cleared when the customer logs out)
- The unique session identifier
Using Persistent Business Objects
The SiteGenesis application handles most general ecommerce processing situations. However, as you develop your storefront, you might identify a particular processing need that isn't implemented. In that case, you might want to create a custom business object to handle the transaction. For example, you might want to offer customers the ability to add a monogram or personalized name to certain products such as tote bags or camera cases.
Using Client-Side Cookies
Using the Salesforce B2C Commerce APIs, not only can you collect information about the cookies that are bound to a session, you can also track all associated cookies via an array.