You are here

function uc_views_bulk_operations_orders_process_orders in Ubercart Views 6.3

Same name and namespace in other branches
  1. 6.2 uc_views_bulk_operations/uc_views_bulk_operations.module \uc_views_bulk_operations_orders_process_orders()

Processes selected orders (moves them to next state in CA)

1 string reference to 'uc_views_bulk_operations_orders_process_orders'
uc_views_bulk_operations_order_operations in uc_views_bulk_operations/uc_views_bulk_operations.module
Implementation of hook_node_operations(). (rather, hook_order_operations, which is based off the other)

File

uc_views_bulk_operations/uc_views_bulk_operations.module, line 66

Code

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) {

        // state matches current one, so grab the next one if it exists.
        if ($states[$key + 1]) {
          $new_status = $states[$key + 1]['id'];
        }
        else {

          // there is no "next state", so we're at the end. return error msg.
          $new_status = NULL;
          drupal_set_message(t('Order #!order_id already at final state. Unable to update.', array(
            '!order_id' => $order_id,
          )), 'error', FALSE);
        }
      }
    }

    // now we need to update each order accordingly.
    if ($new_status) {
      uc_order_update_status($order_id, $new_status);
      drupal_set_message(t('Order #!order_id updated to status: !status', array(
        '!order_id' => $order_id,
        '!status' => $new_status,
      )));
    }
  }
}