关于ofbiz的order模块测试问题

在ofbiz初学者指南中,有介绍使用其order功能(ecommerce),当以游客身份创建订单时,会出现问题。

原因是在
org.ofbiz.webapp.stats.ServerHitBin类得
protected static void countHit(String baseId, int type,
HttpServletRequest request, long startTime, long runningTime,
GenericValue userLogin, boolean isOriginal) {
}
方法中
String delegatorName = (String) request.getSession().getAttribute(
"delegatorName");
这一步会出现得到的delegatorName是null。

发现更深的原因是在org.ofbiz.order.shoppingcart.ShoppingCartEvents类得清理购物车时有这样的一段操作:
public static String clearCart(HttpServletRequest request, HttpServletResponse response) {
        ShoppingCart cart = getCartObject(request);
        cart.clear();

        // if this was an anonymous checkout process, go ahead and clear the session and such now that the order is placed; we don't want this to mess up additional orders and such
        HttpSession session = request.getSession();
        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");
        if (userLogin != null && "anonymous".equals(userLogin.get("userLoginId"))) {
            // here we want to do a full logout, but not using the normal logout stuff because it saves things in the UserLogin record that we don't want changed for the anonymous user
//问题在这里,当它发现是游客身份的时候,会将session清理掉,那么从session取出的delegatorName当然就是null了。
            session.invalidate();
            session = request.getSession(true);

            // to allow the display of the order confirmation page put the userLogin in the request, but leave it out of the session
            request.setAttribute("temporaryAnonymousUserLogin", userLogin);

            Debug.logInfo("Doing clearCart for anonymous user, so logging out but put anonymous userLogin in temporaryAnonymousUserLogin request attribute", module);
        }

        return "success";
    }

你可能感兴趣的:(ofbiz)