1

我正在尝试在 NopCommerce/MVC 应用程序的自定义控制器中创建订单列表,我希望该列表按 creationDate 排序并包含该日期的总订单并将这些值转换为字符串格式。

问题是我希望 ActionResult 在视图中显示网格,就像在 Admin/Orders 中一样。我想要的只是model.StartDate和model.EndDate之间所有已付款订单的列表,其中包含两个参数“CreationDateUtc”和TotalOrders“。我只需要一个包含按creationdate排序的订单数据的列表。

如果我选择 StartDate 2014-03-29 和 EndDate 2014-04-02,我想要的输出将如下所示:

使用参数 CreationDateUtc 和 TotalOrders 列出 OrdersTotalList

CreationDateUtc "2014-03-29" 
TotalOrders "562"

CreationDateUtc "2014-03-30" 
TotalOrders "485"

CreationDateUtc "2014-03-31" 
TotalOrders "733"

CreationDateUtc "2014-04-01" 
TotalOrders "729"

CreationDateUtc "2014-04-02" 
TotalOrders "681

"

我正在尝试通过我的 CustomController 中 OrderController 的 OrderList 实现来访问数据。问题是当这个时间空间内的订单总数为 58 时,此方法总是返回 10 个对象。调试 Total = orders.TotalCount 实际上将 58 个订单显示为一个 int 值)。这里也使用了gridmodel,但我真的不需要gridmodel,我只需要数据库中的数据:

公共列表 OrderList(GridCommand 命令,OrderListModel 模型,OrderModel Omodel){

            DateTime S = new DateTime(2014, 3, 29); //-- Dates for testing
            DateTime E = new DateTime(2014, 4, 02);

            model.StartDate = S;
            model.EndDate = E;

            DateTime? startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime? endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            OrderStatus? orderStatus = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
            PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
            ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;

            //load orders
            var orders = _orderService.SearchOrders(startDateValue, endDateValue, orderStatus,
                paymentStatus, shippingStatus, model.CustomerEmail, model.OrderGuid, command.Page - 1, command.PageSize);
            var gridModel = new GridModel<OrderModel>
            {
                Data = orders.Select(x =>
                {
                    var customerCurrency = _currencyService.GetCurrencyByCode(x.CustomerCurrencyCode);
                    var totalInCustomerCurrency = _currencyService.ConvertCurrency(x.OrderTotal, x.CurrencyRate);

                    return new OrderModel()
                    {
                        Id = x.Id,
                        OrderTotal = _priceFormatter.FormatPrice(totalInCustomerCurrency, true, customerCurrency),
                        OrderStatus = x.OrderStatus.GetLocalizedEnum(_localizationService, _workContext),
                        PaymentStatus = x.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext),
                        ShippingStatus = x.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext),

                        CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc)
                    };
                }),


                Total = orders.TotalCount <-- Returns all orders (58) but as an integer


            };



            var reportSummary = _orderReportService.GetOrderAverageReportLine
             (orderStatus, paymentStatus, shippingStatus, startDateValue, endDateValue, model.CustomerEmail);
            var profit = _orderReportService.ProfitReport
                (orderStatus, paymentStatus, shippingStatus, startDateValue, endDateValue, model.CustomerEmail);
            var aggregator = new OrderModel()
            {
                aggregatorprofit = _priceFormatter.FormatPrice(profit, true, false),
                aggregatortax = _priceFormatter.FormatPrice(reportSummary.SumTax, true, false),
                aggregatortotal = _priceFormatter.FormatPrice(reportSummary.SumOrders, true, false)
                //aggregatordates = 
            };

            List<Order> TotalProductsSold = new List<Order>();

        foreach (var o in orders)
        {

            TotalProductsSold.Add(o);


        }


            return TotalProductsSold.ToList(); //<-- returns 10 orders containing all order info
        }

如果我理解正确以便存档,我必须首先搜索订单以及他们的 PaymentStatus 是否已支付。然后在上面的方法中创建一个列表。foreach 循环可以遍历订单并将订单添加到列表中,尽管我需要指定我只希望该日期的 CreationDate 和 TotalOrders 作为列表中的参数。

我知道这是不对的,但我想类似的事情。问题是我需要一个订单对象列表,而不是一个具有一个值的对象:

List<OrderModel> OrdersTotalList = new List<OrderModel>();

    foreach (var o in orders)
                {

                    OrderModel OM = new OrderModel(OM.OrderTotal, OM.CreatedOn);

                    OrdersTotalList.Add(OM);

                }

    return OrdersTotalList; //--

我完全同意还是这是正确的方法?我希望更熟悉 NopCommerce 的人对此有更多了解。

对不起所有的文字

谢谢

4

1 回答 1

0

解决了。

为了获得完整的订单列表,您可以在 IOrderService/OrderService 中创建一个新的构造函数,它的类型是 List 而不是 IPagedList。用于搜索订单的方法称为“SearchOrders”,类型为 IPagedList。IPagedList 包含属性 PageSize,它只产生 10 个订单。

您可以创建一个与 SearchOrders 具有相同实现的新方法,并将 IPagedList 更改为 List,删除“int pageIndex”和“int pageSize”。

然后使用:

            _orderService.YourNewConstructor(DateTime? startTime, DateTime? endTime,
            OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, string billingEmail,
            string orderGuid)
            {
                 some code...
            }

这将使您可以访问所有订单。

于 2014-04-07T10:44:29.707 回答