電子商取引プロジェクトのショッピングカート理解(重*点)

5445 ワード

1、ショッピングカート業務ロジックの核心方法(*重*点*)
private CartVo getCartVoLimit(Integer userId){
        CartVo cartVo=new CartVo();
        List cartList=cartMapper.selectCartByUserId(userId);
        List cartProductVoList= Lists.newArrayList();
        BigDecimal cartTotalPrice=new BigDecimal("0");

        if(CollectionUtils.isNotEmpty(cartList)){
            for(Cart cartItem:cartList){
                //    
                CartProductVo cartProductVo=new CartProductVo();
                cartProductVo.setId(cartItem.getId());
                cartProductVo.setUserId(userId);
                cartProductVo.setProductId(cartItem.getProductId());

                Product product=productMapper.selectByPrimaryKey(cartItem.getProductId());
                if(product!=null){
                    cartProductVo.setProductMainImage(product.getMainImage());
                    cartProductVo.setProductName(product.getName());
                    cartProductVo.setProductSubtitle(product.getSubtitle());
                    cartProductVo.setProductStatus(product.getStatus());
                    cartProductVo.setProductPricec(product.getPrice());
                    cartProductVo.setProductStock(product.getStock());
                    //    
                    int buyLimitCount=0;
                    if(product.getStock()>=cartItem.getQuantity()){
                        //       
                        buyLimitCount=cartItem.getQuantity();
                        cartProductVo.setLimitQuantity(Const.Cart.LIMIT_NUM_SUCCESS);
                    }else{
                        buyLimitCount=product.getStock();
                        cartProductVo.setLimitQuantity(Const.Cart.LIMIT_NUM_FAIL);
                        //          
                        Cart cartForQuantity=new Cart();
                        cartForQuantity.setId(cartItem.getId());
                        cartForQuantity.setQuantity(buyLimitCount);
                        cartMapper.updateByPrimaryKeySelective(cartForQuantity);
                    }
                    cartProductVo.setQuantity(buyLimitCount);
                    //    ,       
                    cartProductVo.setProductTotalPrice(BigDecimalUtil.mul(product.getPrice().doubleValue(),cartProductVo.getQuantity()));
                    cartProductVo.setProductChecked(cartItem.getChecked());//    
                }
                //        
                if(cartItem.getChecked()==Const.Cart.CHECKED){
                    //      ,           
                    cartTotalPrice=BigDecimalUtil.add(cartTotalPrice.doubleValue(),cartProductVo.getProductTotalPrice().doubleValue());
                }
                cartProductVoList.add(cartProductVo);
            }

        }
        cartVo.setCartTotalPrice(cartTotalPrice);
        cartVo.setCartProductVoList(cartProductVoList);
        cartVo.setAllChecked(this.getAllCheckedStatus(userId));//      
        cartVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix"));
        return  cartVo;

    }

 
 
2、ショッピングカート増加商品(要求パラメータ:HttpSession session,Integer count,Integer productId)
a、セッションから現在のログインユーザーを取得する
b、数量と製品idが空かどうかを判断する
c、例えば数量と製品idが空ではなく、ユーザーidと製品idを通じてショッピングカートを検索する
d、検索したカートの対象がnullであれば、新たに1つの製品をこのカートに記録する
e、照会したカートの対象がある場合、当該製品が既に存在することを示す場合、数量加算を行う
f、ショッピングカートを実行する核心方法
3、ショッピングカートの商品リストを検索する(要求パラメータ:HttpSession session)
a、セッションから現在のログインユーザーを取得する
b、カートの核心方法を実行し、cartVo対象を得る
4、ショッピングカート商品の更新(要求パラメータ:HttpSession session,Integer count,Integer productId)
a、セッションから現在のログインユーザーを取得する
b、数量と製品idが空かどうかを判断する
c、例えば数量と製品idが空ではなく、ユーザーidと製品idを通じてショッピングカートを検索する
d、例えばcartが空でない場合、数量を増加する
e、カートのデータベースを更新する
f、カートのコアメソッドを実行し、cartVoオブジェクトを得る
5、ショッピングカート商品削除(HttpSession session,String productIds)
a.セッションから現在のログインユーザを取得する
b、productIdsをカンマ(,)で区切る
List productList= Splitter.on(",").splitToList(productIds);

c、分割された集合が空であるか否かを判断する
CollectionUtils.isEmpty(productList)

d、ユーザidと商品idの集合による削除(sqlによる集合の削除の書き方)

   delete from mmall_cart
    where user_id =#{userId}
    
      and product_id in
      
        #{item}
      
    
  

e、カートのコアメソッドを実行し、cartVoオブジェクトを得る
----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
6、ショッピングカートの選択(全選択と全選択、単独選択と単独選択)
a、セッションから現在のログインユーザーを取得する
b、ユーザーidと商品idと全部チェックする(商品をチェックし、データベースのチェックオプションをチェックする)

    update mmall_cart
    set checked=#{checked}
    update_time=now()
    where user_id=#{userId}
    
      and product_id=#{productId}
    
  

7、ショッピングカートの商品数を調べる
a、セッションから現在のログインユーザーを取得する
b、ユーザーIDでカートの商品数を検索する(nullであれば0)