private void addToCarOrder(Good g) { CarOrder o = CarOrder.getCarOrder(context); String shopId = Constants.seller.getShopId(); try { if (!shopId.equals(o.getShopId())) { o = new CarOrder(); } } catch (Exception e) { e.printStackTrace(); } o.setBuyerName(Constants.seller.getShopName()); o.setShopId(shopId); o.setBuyerName(Constants.user.getUserName()); o.setShopKeeperName(Constants.seller.getShopName()); o.setUserId(Constants.user.getUserId()); Integer shopType = Constants.seller.getShopType(); if (shopType != null) { o.setSeaRecordId( shopType.intValue() == Seller.TYPE_FARMER ? null : ((Fisherman) Constants.seller).getSeaRecordId()); } List<Good> goods = o.getOrdersDetail(); if (goods == null) { goods = new ArrayList<Good>(); } g.setNumber(1); goods.add(g); o.setOrdersDetail(goods); CarOrder.saveCarOrder(o, context); }