Beispiel #1
0
        public virtual IActionResult CurrentCarts(DataSourceRequest command, ShoppingCartTypeModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
            {
                return(AccessDeniedKendoGridJson());
            }

            var customers = _customerService.GetAllCustomers(
                loadOnlyWithShoppingCart: true,
                sct: model.ShoppingCartType,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = customers.Select(x => new ShoppingCartModel
                {
                    CustomerId    = x.Id,
                    CustomerEmail = x.IsRegistered() ? x.Email : _localizationService.GetResource("Admin.Customers.Guest"),
                    TotalItems    = x.ShoppingCartItems.Where(sci => sci.ShoppingCartType == model.ShoppingCartType).ToList().GetTotalProducts()
                }),
                Total = customers.TotalCount
            };

            return(Json(gridModel));
        }
Beispiel #2
0
        public virtual IActionResult GetCartDetails(int customerId, ShoppingCartTypeModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrentCarts))
            {
                return(AccessDeniedKendoGridJson());
            }

            var customer = _customerService.GetCustomerById(customerId);
            var cart     = customer.ShoppingCartItems.Where(x => x.ShoppingCartType == model.ShoppingCartType).ToList();

            var gridModel = new DataSourceResult
            {
                Data = cart.Select(sci =>
                {
                    var store    = _storeService.GetStoreById(sci.StoreId);
                    var sciModel = new ShoppingCartItemModel
                    {
                        Id            = sci.Id,
                        Store         = store != null ? store.Name : "Unknown",
                        ProductId     = sci.ProductId,
                        Quantity      = sci.Quantity,
                        ProductName   = sci.Product.Name,
                        AttributeInfo = _productAttributeFormatter.FormatAttributes(sci.Product, sci.AttributesXml, sci.Customer),
                        UnitPrice     = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Product, _priceCalculationService.GetUnitPrice(sci), out decimal taxRate)),
                        Total         = _priceFormatter.FormatPrice(_taxService.GetProductPrice(sci.Product, _priceCalculationService.GetSubTotal(sci), out taxRate)),
                        UpdatedOn     = _dateTimeHelper.ConvertToUserTime(sci.UpdatedOnUtc, DateTimeKind.Utc)
                    };
                    return(sciModel);
                }),
                Total = cart.Count
            };

            return(Json(gridModel));
        }