在NopCommerce中创建订单的自定义列表

时间:2014-04-03 13:05:57

标签: asp.net-mvc list e-commerce nopcommerce orders

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

事情是我希望ActionResult在视图中显示网格,例如在管理员/订单中。我想要的是model.StartDate和model.EndDate之间所有付费订单的列表,它包含两个参数" CreationDateUtc"和TotalOrders"。我只需要一个包含按创建日期排序的订单数据的列表。

如果我选择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来访问数据。问题是这个方法总是返回10个对象,实际上这个时间空间内的订单总数是58.当调试时Total = orders.TotalCount实际上显示58个订单作为一个int值)。此外还使用了gridmodel,但我真的不需要gridmodel,我只需要数据库中的数据:

public List 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是付费的。然后在上面的方法中创建一个List。 foreach循环可以遍历订单并向List添加订单,尽管我需要指定我只希望该日期的CreationDate和TotalOrders作为List中的参数。

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

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的人更了解这一点。

抱歉所有文字

谢谢

1 个答案:

答案 0 :(得分: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...
            }

这将允许您访问所有订单。