コード例 #1
0
        public Cart GetCart()
        {
            //get cart items
            var cartEntity = _cartRepository.GetCart(this.shoppingCartId);
            var cartItems  = cartEntity.Select(p => new CartItem()
            {
                Id          = p.RecordId,
                CartId      = p.CartId,
                ProductId   = p.ProductId,
                Quantity    = p.Count,
                DateCreated = p.DateCreated,
                ProductName = p.ProductName,
                SizeName    = p.SizeName,
                ColorName   = p.ColorName,
                Price       = p.Price,
                Sku         = p.Sku
            }).ToList();
            var taxRate = Convert.ToDecimal(_configuration["TaxRate"]);

            //build cart
            return(new Cart()
            {
                CartItems = cartItems,
                CartTotal = cartItems.Sum(c => c.Price * c.Quantity),
                ShipChart = _shippingRepository.GetShipCosts(),
                Tax = cartItems.Sum(c => c.Price * c.Quantity * taxRate)
            });
        }