Custom Order Report - Get Product Type for each Order

Posted by Community Admin on 05-Aug-2018 05:57

Custom Order Report - Get Product Type for each Order

All Replies

Posted by Community Admin on 31-Jul-2013 00:00

I am trying to get the Product Type of each Product within the context of a list of all Orders. I am currently binding all Orders to a RadGrid for reporting purposes. Below is a snippet which hopefully shows what I am trying to acheive:

-----------------------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
       

            //Store Orders in "orderList" then bind it to RadGrid.
            var orderList = new List<OrderReportView>();

            OrdersManager ordersManager = OrdersManager.GetManager();
            IQueryable<Order> orders = ordersManager.GetOrders();

            foreach (Order order in orders)
           

                var theOrder = new OrderReportView();

                theOrder.OrderNumber = order.OrderNumber;
                theOrder.OrderDate = order.OrderDate;
                theOrder.OrderStatus = order.OrderStatus;
                theOrder.Total = order.Total;

                //Assume only 1 Product per Order.
                theOrder.Title = order.Details[0].Title;
                //NOW SOMETHING LIKE THIS BELOW??
                theOrder.ProductType = order.Details[0].ProductTypeName; //eg. "Book"

                orderList.Add(theOrder);

           

            RadGrid1.DataSource = orderList;
            RadGrid1.DataBind();

       
-----------------------------------------------------------------------------------------

Any help would be appreciated.
Thanks,
Gavin.

Posted by Community Admin on 01-Aug-2013 00:00

Hello Gavin,

 You will have to match the product clrtype to the product type clrtype. I do this in my Product model I use when I want to cut our certain data from being returned (for example in the case of custom web api or auto generated reports).

namespace SitefinityWebApp.Data.Models
    public class ProductModel
    
 
        public Guid Id get; set;
        public string ProductType get; set;
        public string Title get; set;
        public ProductModel()
 
        public ProductModel(Product product)
        
            var em = EcommerceManager.GetManager();
            this.Id = product.Id;
            this.Title = product.Title;
            this.ProductType = em.GetProductTypes().Where(pt => pt.ClrType == product.ClrType).FirstOrDefault().Title;
        
    

I hope this helps.

Regards,
Patrick Dunn
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed