}
public static WebPosSession getWebPosSession(HttpServletRequest request, String posTerminalId) {
HttpSession session = request.getSession(true);
GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
WebPosSession webPosSession = (WebPosSession) session.getAttribute("webPosSession");
ShoppingCart cart = (ShoppingCart) session.getAttribute("shoppingCart");
Delegator delegator = (Delegator) request.getAttribute("delegator");
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
if (UtilValidate.isEmpty(webPosSession)) {
String productStoreId = ProductStoreWorker.getProductStoreId(request);
GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator);
String facilityId = null;
String currencyUomId = request.getParameter("currencyUomId");
if (UtilValidate.isNotEmpty(productStore)) {
facilityId = productStore.getString("inventoryFacilityId");
if (UtilValidate.isEmpty(currencyUomId)) {
currencyUomId = productStore.getString("defaultCurrencyUomId");
}
}
if (UtilValidate.isNotEmpty(userLogin)) {
session.setAttribute("userLogin", userLogin);
}
if (UtilValidate.isEmpty(cart)) {
cart = new ShoppingCart(delegator, productStoreId, request.getLocale(), currencyUomId);
session.setAttribute("shoppingCart", cart);
}
if (UtilValidate.isNotEmpty(posTerminalId)) {
webPosSession = new WebPosSession(posTerminalId, null, userLogin, request.getLocale(), productStoreId, facilityId, currencyUomId, delegator, dispatcher, cart);
session.setAttribute("webPosSession", webPosSession);
} else {
Debug.logError("PosTerminalId is empty cannot create a webPosSession", module);
}
}