예제 #1
0
        /// <summary>
        /// 删除购物车中套装
        /// </summary>
        public ActionResult DelSuit()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pmId = WebHelper.GetQueryInt("pmId");                                          //套装id
            int    pos  = WebHelper.GetQueryInt("pos");                                           //位置
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);

            Carts.DeleteCartSuit(ref orderProductList, pmId);

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List <OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List <CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartItemList  = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            if (pos == 0)
            {
                return(View("ajaxindex", model));
            }
            else
            {
                return(View("snap", model));
            }
        }
예제 #2
0
        /// <summary>
        /// 修改购物车中套装数量
        /// </summary>
        public ActionResult ChangeSuitCount()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pmId     = WebHelper.GetQueryInt("pmId");                                      //套装id
            int    buyCount = WebHelper.GetQueryInt("buyCount");                                  //购买数量
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //套装商品列表
            List <OrderProductInfo> suitOrderProductList = Carts.GetSuitOrderProductList(pmId, orderProductList, true);

            if (suitOrderProductList.Count > 0) //当套装已经存在
            {
                if (buyCount < 1)               //当购买数量小于1时,删除此套装
                {
                    Carts.DeleteCartSuit(ref orderProductList, pmId);
                }
                else
                {
                    OrderProductInfo orderProductInfo = suitOrderProductList.Find(x => x.Type == 3);
                    int oldBuyCount = orderProductInfo.RealCount / orderProductInfo.ExtCode2;
                    if (buyCount != oldBuyCount)
                    {
                        Carts.AddExistSuitToCart(ref orderProductList, suitOrderProductList, buyCount);
                    }
                }
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List <OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List <CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartItemList  = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return(View("ajaxindex", model));
        }