Add List of Products to Orders in Order History

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 лет назад
Hi again!

We want to add a list of products to the orders on the Order History page. Can anyone give me some insight as to the proper way to do this? This way, users can see what products were ordered without having to click into the order details page.
7 лет назад
DerekFoulk wrote:
Hi again!

We want to add a list of products to the orders on the Order History page. Can anyone give me some insight as to the proper way to do this? This way, users can see what products were ordered without having to click into the order details page.


Hi Derek,

this is not possible out-of-the-box since this information doesn't exist in the context of the OrderList page. You have to do some code modifications, so if you are familiar with MVC and C#, I could give you some pointers, otherwise I would suggest finding a developer to do it for you.

Kind regards,
Aleks
7 лет назад
I am still learning C# (and MVC). To be honest, I was kind of looking forward to developing this myself. I think that I could learn a lot from building this upgrade. Any tips you wouldn't mind sharing would be greatly appreciated!
7 лет назад
Nop-Templates.com wrote:
Hi again!

We want to add a list of products to the orders on the Order History page. Can anyone give me some insight as to the proper way to do this? This way, users can see what products were ordered without having to click into the order details page.

Hi Derek,

this is not possible out-of-the-box since this information doesn't exist in the context of the OrderList page. You have to do some code modifications, so if you are familiar with MVC and C#, I could give you some pointers, otherwise I would suggest finding a developer to do it for you.

Kind regards,
Aleks


I could really use some pointers here. I have been looking at the Order Details view, model and controller. I have copied some lines from OrderDetailsModel.cs into CustomerOrderListModel.cs (code shown below):

using System;
using System.Collections.Generic;
using Nop.Core.Domain.Orders;
using Nop.Web.Framework.Mvc;

// From OrderDetailsModel.cs (Not sure if this is needed quite yet)
using Nop.Web.Models.Common;

namespace Nop.Web.Models.Order
{
    public partial class CustomerOrderListModel : BaseNopModel
    {
        public CustomerOrderListModel()
        {
            Orders = new List<OrderDetailsModel>();
            RecurringOrders = new List<RecurringOrderModel>();
            CancelRecurringPaymentErrors = new List<string>();

            // Custom
            Items = new List<OrderItemModel>();
        }

        public IList<OrderDetailsModel> Orders { get; set; }
        public IList<RecurringOrderModel> RecurringOrders { get; set; }
        public IList<string> CancelRecurringPaymentErrors { get; set; }


        #region Nested classes

        public partial class OrderDetailsModel : BaseNopEntityModel
        {
            public string OrderTotal { get; set; }
            public bool IsReturnRequestAllowed { get; set; }
            public OrderStatus OrderStatusEnum { get; set; }
            public string OrderStatus { get; set; }
            public string PaymentStatus { get; set; }
            public string ShippingStatus { get; set; }
            public DateTime CreatedOn { get; set; }
        }

        public partial class RecurringOrderModel : BaseNopEntityModel
        {
            public string StartDate { get; set; }
            public string CycleInfo { get; set; }
            public string NextPayment { get; set; }
            public int TotalCycles { get; set; }
            public int CyclesRemaining { get; set; }
            public int InitialOrderId { get; set; }
            public bool CanCancel { get; set; }
        }

        #endregion


        #region My classes

        public bool PrintMode { get; set; }
        public bool PricesIncludeTax { get; set; }
        public bool DisplayTaxShippingInfo { get; set; }
        public bool ShowSku { get; set; }
        public IList<OrderItemModel> Items { get; set; }

        public partial class OrderItemModel : BaseNopEntityModel
        {
            public Guid OrderItemGuid { get; set; }
            public string Sku { get; set; }
            public int ProductId { get; set; }
            public string ProductName { get; set; }
            public string ProductSeName { get; set; }
            public string UnitPrice { get; set; }
            public string SubTotal { get; set; }
            public int Quantity { get; set; }
            public string AttributeInfo { get; set; }
            public string RentalInfo { get; set; }

            //downloadable product properties
            public int DownloadId { get; set; }
            public int LicenseId { get; set; }
        }

        #endregion
    }
}


I also found this in OrderController.cs, but I am unsure how to change it for the 'CustomerOrders()' method...

//My account / Order details page
[NopHttpsRequirement(SslRequirement.Yes)]
public ActionResult Details(int orderId)
{
    var order = _orderService.GetOrderById(orderId);
    if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
        return new HttpUnauthorizedResult();

    var model = PrepareOrderDetailsModel(order);

    return View(model);
}

I am guessing that this needs to be changed to handle multiple 'Order IDs', instead of just one (passed as an argument here)...

And in the view (CustomerOrders.cshtml), I simply copied the 'Model.Items' loop. I put it inside the 'Model.Orders' loop:

@foreach (var order in Model.Orders)
{
    @foreach (var item in Model.Items)
    {
        @item.Sku
        ...
    }
}
7 лет назад
GOOD!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.