Obtaining the customer's name or ID

Professional Edition onlyBusiness Edition only Once the customer care applet is launched and the CSR is logged on, the CSR is able to identify who is using the applet by name or by shopper ID. The fashion flow sample store includes specialized code that work with the customer care applet to determine the customer's name or shopper ID. This code determines whether the customer is a guest customer, a guest customer with items in a shopping cart or a registered customer, then assigns a name or ID to the customer, and passes this name back to the customer care applet. These names then display to the CSR. For example, if the customer is a guest customer, who hasn't placed anything in the shopping cart, the customer is assigned a generated ID, with shopper ID -1002. If the customer is a guest with items in the shopping cart, the shopper ID will display, and if the customer is registered, their first name and last names display.

The store obtains the customer's name or ID by including the CustomerCareInformationSetup.jsp in the store pages header file. The following code in the CustomerCareInformationSetup.jsp file, available if you publish the FashionFlow sample, obtains the customer's name and ID:

<jsp:useBean id="userRDB" class="com.ibm.commerce.user.beans.UserRegistrationDataBean" scope="page">
<% DataBeanManager.activate(userRDB, request); %>
</jsp:useBean>
<%
String customer_name="";
customer_name=userRDB.getUserId();
if (userRDB.findUser()){
   if (userRDB.getLastName() !=null && userRDB.getLastName().length() > 0){
         if (locale.toString().equals("ja_JP")||locale.toString().equals("ko_KR")||locale.toString().equals("zh_CN")||locale.toString().equals("zh_TW"))
            {customer_name = userRDB.getLastName() + " " + userRDB.getFirstName();}
         else
            {customer_name = userRDB.getFirstName() + " " + userRDB.getLastName();}
      }
}
if (customer_name.equals("-1002")) {
 customer_name="";
 }
else {
 // need to check order items
 ....
}
customer_name=customer_name.trim();
%>

Note: Each time a customer browses a new page in the store, the customer's name or ID is refreshed.

The following code in the CustomerCareInformationSetup.jsp file updates the customer's name and ID:

<script language="javascript">
 ....
function changeSTAttributes()
{ 
 if (typeof top.setCustomerName == 'function') {
    top.setCustomerName(<%=userRDB.getUserId()%>, '<%=customer_name%>');
    top.setShoppingCartItems(<%=shoppingCartItems%>);
    top.changeSTAttributes();
    }
}
</script>

In the starter store's Logout page, more custom code is included, which sets the customer name to a generated ID and resets the number of items in the shopping cart to zero. The Logout page is UserLogoffRouter.jsp. The custom code is as follows:

<HTML>
<HEAD>
<SCRIPT language="javascript">
 if (typeof parent.setCustomerName == 'function')
     parent.setCustomerName (parent.WCSGUESTID, '')
   if (typeof parent.setShoppingCartItems == 'function')
     parent.setShoppingCartItems(0);
</SCRIPT>
</HEAD>
</HTML>

Feedback