WebSphere Commerce Developer

Enabling global persistent sessions (Developer)

WebSphere Commerce can be configured to enable persistent sessions for both registered and guest users. Enabling persistent sessions allows for some session-related information of the user to be stored as permanent cookies. If persistent sessions are enabled, a customer at a WebSphere Commerce store will be recognized on subsequent visits to the store, even after the customer closes the browser.

Note: You can enable persistent sessions globally on your production environment. For more information, see: Enabling global persistent sessions.

Procedure

  1. Enable persistent sessions globally (handles only registered customers by default):
    1. Open the workspace_dir\WC\xml\config\wc-server.xml file for editing.
    2. Locate PersistentSession element within the SessionManagement code:
      <SessionManagement>
          <url-rewriting display="false" enabled="false"/>
          <cookie acceptance="false" age="-1" display="false"
              domain="" enabled="true" path="/" persistence="wcs"/>
          <referrerCookie age="-1"/>
          <AllowMultipleLogonForSameUser enabled="true"/>
          <PersistentSession cookieExpiry="-1"
              delayNewPersistentGuestSession="true" display="false" enable="false"/>
          <PersonalizationId display="false" enable="true"/>
      </SessionManagement>
    3. In the cookieExpiry attribute, enter the number of days that you want the session to last. If the customer logs on to the store within the specified number of days, their session is persisted. A value of -1 indicates that the cookie is removed at the end of a browser session, and a value of 0 is not supported.
    4. Set the enable attribute to "true".
    5. Save and close the file.
  2. Optional: Enable the Migrate Guest Orders Event Listener for guest customers in pesistent sessions.
    This event listener is defined within the GuestUserOrderResetEventListener class and is used to listen for guest user migration events. When an event occurs, the listener class resets the pending orders that belong to the previous guest user, clearing all of the private information that belongs to the order. The class then sets the ownership of the order to the new guest user.
    For example, when persistent sessions are enabled and a guest shopper adds an item to their shopping cart, guest user A is created. If the shopper closes and then opens their web browser again, they can still view the item within the shopping cart. When the shopper adds another item to their cart, or performs an action that is not allowed with persistent sessions, a new guest user B is created. The actions that are allowed by persistent sessions are configured in the corresponding struts configuration file. With guest user B created, the enablement of the event listerner determines the shopping cart contents. If enabled, the guest user A shopping cart is migrated to guest user B and the contents of the cart are mergerd. This migration provides the shopper with a consitent shopping experience without the shopper knowing that a second guest user session is created.
    Note: This event listener class is used only for persistent sessions. If persistent sessions are not enabled, the listener is not used, regardless of whether you enable the listener.
    1. Edit the workspace_dir\WC\xml\config\wc-server.xml file.
    2. Locate the following code snippet:
      <component
          compClassName="com.ibm.commerce.order.event.GuestUserOrderResetEventListener"
          enable="false" name="Migrate Guest Orders Event Listener">
        <property display="false">
            <start enabled="true"/>
        </property>
      </component>
    3. Set the enable attribute to "true".
    4. Save and close the file.
  3. Enable persistent sessions in a single store. Enabling persistent sessions in a single store ensures that your store is configured to handle persistent sessions. For example, your STORE.PERSISTENTSESSION value must correspond to the configuration you want to support, such as remembering registered customers only, or remembering both registered and guest customers. If you want registered customers to use persistent session features, you must also create a check box on the logon and registration page that enables the feature for their account.
    Note: You might need to update store JSP pages to ensure your persistent session option displays correctly.
  4. Restart your WebSphere Commerce test server.