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:
- First an int variable is defined
long liveHelpShoppingCartItems = 0;
- Next, the following line of code is used to add the quantity to liveHelpShoppingCartItems whenever there is an orderitem addition to the cart:
liveHelpShoppingCartItems+= orderItem.getQuantityInEJBType().longValue();
- Then, the following code is added at the end of the page to set the customer name to the guest shopper ID, and to obtain the number of items in the customer's shopping cart.
<script language="javascript"> if (typeof parent.setShoppingCartItems == 'function') parent.setShoppingCartItems(<%=liveHelpShoppingCartItems%>); </script>
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>