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:
Use the Session
class to access details about browser
actions, such as:
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 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.