I have created a view for commerce orders where format is tabular and they are grouped by email of order owner. So basically each group of record shows how many orders are placed by a given email id.I need to have a extra row in each grouped results which is basically summary of order(showing cumulative order total) so I used views_summarize module and got it done. Now I need to have export views as csv or xls functionality so I put views_data_export module but it seems the row added by views_summarize is not included by csv or xls generated by views_data_export.
I also tried including the row using hook_views_pre_render(), and I am seeing the row is getting added in the views page under preview but when I export the views in csv again the row does not appear.
Here is code
function mymodulename_views_pre_render(&$view) // don't forget to replace my_module with your modules name
{
if($view->name == "paid_partner") {
if($view->current_display = "paid_partner_csv" || $view->current_display = "paid_partner_xls") {
foreach($view->result as $submission) {
$order_total_summary += $submission->field_data_commerce_order_total_commerce_order_total_amount;
$quantity_total_summary += $submission->commerce_line_item_field_data_commerce_line_items_quantity;
$currency = $submission->commerce_order_total_amount_currency_code;
}
$price_display = commerce_currency_format($order_total_summary, $currency);
// insert a 'total' row
$row = new stdClass();
$row->order_id = "Order Summary";
$row->users_commerce_order_mail = "Order Total Summary";
$row->commerce_line_item_field_data_commerce_line_items_quantity = $quantity_total_summary;
$row->field_commerce_order_total[0]['rendered'] = array(
'#markup' => $price_display,
'#access' => TRUE,
);
$view->result[] = $row;
}
}
}
What can I do to include the summary row with each grouped record in exported csv or xls.