Tracking the number of items in the shopping cart

Professional Edition onlyBusiness Edition only Customer Care also allows CSRs to track how many items a customer has in their shopping cart at any time. The following code in the obtains the number of items in the shopping car. You can see this code in the CustomerCareInformationSetup.jsp file, if you publish the FashionFlow sample:

<%
JSPHelper jhelper = new JSPHelper(request);
String storeId = jhelper.getParameter("storeId");
long shoppingCartItems = 0; 
%>
<
jsp:useBean id="userRDB" class="com.ibm.commerce.user.beans.UserRegistrationDataBean" scope="page">
<% DataBeanManager.activate(userRDB, request); %></jsp:useBean>

<%
....
 // need to check order items
 OrderListDataBean orderListBean = new OrderListDataBean();
 orderListBean.setStoreId(new Integer(storeId));
 orderListBean.setOrderStatus("P");
 orderListBean.setUserId(cmdcontext.getUserId());
 DataBeanManager.activate(orderListBean, request); 
 Vector pendingOrders = orderListBean.getOrders();
 for (int k=0; k< pendingOrders.size(); k++) {
  OrderAccessBean next_order = (OrderAccessBean) pendingOrders.elementAt(k);
  OrderDataBean orderBean = new OrderDataBean();
  orderBean.setOrderId(next_order.getOrderId());
  DataBeanManager.activate(orderBean, request);  
  //Get items in the order
  OrderItemDataBean [] orderItems = orderBean.getOrderItemDataBeans();
  for (int i = 0; ((orderItems != null) && (i < orderItems.length)); i++) 
  {
   OrderItemDataBean orderItem = orderItems[i];
   shoppingCartItems += orderItem.getQuantityInEJBType().longValue();
   }
  }
....
%>

The following JavaScript function will update the cart information to Sametime applet:

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

Note: A CSR can view the contents of the shopping cart using the View Shopping Cart button. For more information, see the WebSphere Commerce online help.

The starter stores determine the number of items in the shopping cart by adding the following code to the above pages:

The following code is used in the empty shopping cart page and the order confirmation page to reset the number of items in the cart to zero:

<script language="javascript">
 if (typeof parent.setShoppingCartItems == 'function')
  parent.setShoppingCartItems(0);
</script>


Feedback