Custom Order Report - Get Product Type for each Order
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.
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;