1

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.

1 Answer 1

3

Views Data Export does not render your results in a traditional way, so render hooks are not executed. But you should be able to alter results using hook_views_post_execute:

This hook is called right after the execute process. The query has been executed, but the pre_render() phase has not yet happened for handlers.

Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Emphasis mine - that's what you should to to alter content not only for display purposes, but in generic, usage-independent way.

1
  • @arpitr glad it helped :)
    – Mołot
    Commented Jan 9, 2014 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.