function checkStore(){ var flag=1; $.ajax({ url:"widget?type=shop_cart&ajax=yes&action=checkStore", dataType:"json", async: false, success:function(json){ userLoad = false; json = eval(json.products); for(var i=0; i<json.length; i++) { if(!isNaN(json[i])){ }else{ flag=0; } $("#p"+json[i]).removeClass(); $("#"+json[i]).addClass("selected"); } } }); if(flag==0){ return false; } else{ return true; } }
/** * 检查产品库存情况,别返回到页面 */ private void checkStore(){ String sessionid = request.getSession().getId(); List itemList = this.cartManager.listGoods(sessionid); JSONObject object=new JSONObject(); List products=new ArrayList(); for (int i = 0; i < itemList.size(); i++) { CartItem c = (CartItem) itemList.get(i); Product product = productManager.get(c.getProduct_id()); if(product.getSpec_num() * c.getNum() > product.getProductStore()){ products.add("p"+product.getProduct_id()); }else{ products.add(product.getProduct_id()); } } object.put("products", products); this.showJson(object.toString()); }