View source
<?php
function uc_views_bulk_operations_views_api() {
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'uc_views_bulk_operations') . '/views',
);
}
function uc_views_bulk_operations_views_bulk_operations_object_info() {
return array(
'order' => array(
'type' => 'order',
'base_table' => 'uc_orders',
'load' => 'uc_order_load',
'title' => 'order_id',
),
);
}
function uc_views_bulk_operations_order_operations() {
return array(
'process_orders' => array(
'label' => 'Move Orders to next State',
'callback' => 'uc_views_bulk_operations_orders_process_orders',
'disabled' => TRUE,
),
'print_orders' => array(
'label' => 'Print Orders',
'callback' => 'uc_views_bulk_operations_orders_print_orders',
'disabled' => TRUE,
),
);
}
function uc_views_bulk_operations_orders_process_orders($order_ids) {
$states = uc_order_status_list();
foreach ($order_ids as $order_id) {
$order = uc_order_load($order_id);
foreach ($states as $key => $state) {
if ($state['id'] == $order->order_status) {
if ($states[$key + 1]) {
$new_status = $states[$key + 1]['id'];
}
else {
$new_status = NULL;
drupal_set_message(t('Order #' . $order_id . ' already at final state. Unable to update.'), 'error', FALSE);
}
}
}
if ($new_status) {
uc_order_update_status($order_id, $new_status);
drupal_set_message(t('Order #' . $order_id . ' updated to status: ') . $new_status);
}
}
}
function _uc_order_bulkops_view_invoice($order_id) {
$order = uc_order_load($order_id);
$output = uc_order_load_invoice($order, 'print', variable_get('uc_cust_order_invoice_template', 'customer'));
return $output;
}
function uc_views_bulk_operations_orders_print_orders($orders) {
$args = implode(',', $orders);
foreach ($orders as $order_id) {
$output .= _uc_order_bulkops_view_invoice($order_id);
$output .= '<hr style="page-break-after: always;"/>';
}
$output .= '<div align="right" id="_toolbar_to_hide" style="margin-top: 1em; margin-right: 1em;"><input type="button" value="' . t('Print invoice') . '" onclick="$(\'input\').hide(); window.print();" /> ' . '<input type="button" value="' . t('Back') . '" onclick="history.go(-1);" /></div>';
die(print $output);
}