You are here

function __prepare_commerce_reports_products_sales_monthly_bar_data in Commerce Reporting 7

1 call to __prepare_commerce_reports_products_sales_monthly_bar_data()
commerce_reports_handler_field_products_sales_monthly_bar::render in includes/views/handlers/commerce_reports_handler_field_products_sales_monthly_bar.inc
Render the field.

File

./commerce_reports.module, line 76
Defines additional menu item and order reports functionality.

Code

function __prepare_commerce_reports_products_sales_monthly_bar_data($view_result) {
  $data = array();
  foreach ($view_result as $order_details) {
    $order = commerce_order_load($order_details->order_id);
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $currency_code = $wrapper->commerce_order_total->currency_code
      ->value();
    $amount = commerce_currency_amount_to_decimal($wrapper->commerce_order_total->amount
      ->value(), $currency_code);
    $month = date("M Y", $order->created);
    if (!isset($data[$month])) {
      $data[$month] = $amount;
    }
    else {
      $data[$month] += $amount;
    }
  }
  return $data;
}