Posted on 18/12/2024 13:32:59
Hi Adrian
That is not possible - but the feature is pretty simple - you can use the code and make your own custom version simple.
Below the code - it uses CustomerOrderCollection and you probably want to use the orderservice instead.
public static OutputResult RenderExcel(string shopId, string orderContextId)
{
var response = Context.Current.Response;
int uid = UserContext.Current.UserId;
bool isQuote = Converter.ToString(Context.Current.Request["OrderType"]) == "quotes";
bool isLedgerEntry = string.Equals(Context.Current.Request["OrderType"], "LedgerEntries", StringComparison.CurrentCultureIgnoreCase);
if (uid == 0)
return ContentOutputResult.Empty;
var orderType = OrderType.Order;
if (isQuote)
{
orderType = OrderType.Quote;
}
else if (isLedgerEntry)
{
orderType = OrderType.LedgerEntry;
}
var customerOrders = new CustomerOrderCollection();
customerOrders.Load(uid, shopId, orderType, 0, false, orderContextId);
var orders = customerOrders.OrderBy(o => o.Id);
var sb = new System.Text.StringBuilder();
// // Write headers
sb.Append("Date" + @"\t");
sb.Append("Order ID" + @"\t");
sb.Append("Product ID" + @"\t");
sb.Append("Product Number" + @"\t");
sb.Append("Variant ID" + @"\t");
sb.Append("Variant Text" + @"\t");
sb.Append("Product Name" + @"\t");
sb.Append("Quantity" + @"\t");
sb.Append("Unit Price" + @"\t");
sb.Append("Currency" + @"\t");
sb.Append("Currency Rate" + @"\t");
sb.Append(System.Environment.NewLine);
foreach (Order enumOrder in orders)
{
foreach (OrderLine orderLine in enumOrder.OrderLines)
{
sb.Append(enumOrder.Date.ToShortDateString() + @"\t");
sb.Append(enumOrder.Id + @"\t");
sb.Append(orderLine.ProductId + @"\t");
sb.Append(orderLine.ProductNumber + @"\t");
sb.Append(orderLine.ProductVariantId + @"\t");
sb.Append(orderLine.ProductVariantText + @"\t");
sb.Append(orderLine.ProductName + @"\t");
sb.Append(orderLine.Quantity.ToString() + @"\t");
sb.Append(orderLine.Price.Price.ToString() + @"\t");
sb.Append(enumOrder.CurrencyCode + @"\t");
sb.Append(enumOrder.CurrencyRate.ToString() + @"\t");
sb.Append(System.Environment.NewLine);
}
}
var preamble = System.Text.Encoding.UTF32.GetPreamble();
var fileBytes = System.Text.Encoding.UTF32.GetBytes(sb.ToString());
var output = new byte[preamble.Length + fileBytes.Length];
Buffer.BlockCopy(preamble, 0, output, 0, preamble.Length);
Buffer.BlockCopy(fileBytes, 0, output, preamble.Length, fileBytes.Length);
return new StreamOutputResult
{
ContentType = "application/vnd.ms-excel; charset=" + System.Text.Encoding.UTF32.WebName,
Filename = "MyOrders.xls",
ContentStream = new MemoryStream(output)
};
}