You are here

function uc_cart_checkout_review_form_submit in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_cart/uc_cart.module \uc_cart_checkout_review_form_submit()
  2. 6.2 uc_cart/uc_cart.pages.inc \uc_cart_checkout_review_form_submit()

Final checks to make sure the order can be completed.

See also

uc_cart_checkout_review_form()

File

uc_cart/uc_cart.pages.inc, line 552
Cart menu items.

Code

function uc_cart_checkout_review_form_submit($form, &$form_state) {

  // Invoke hook_uc_order($op = 'submit') to test to make sure the order can
  // be completed... used for auto payment in uc_credit.module.
  $order = $form_state['uc_order'];
  $error = FALSE;

  // Invoke it on a per-module basis instead of all at once.
  foreach (module_implements('uc_order') as $module) {
    $function = $module . '_uc_order';
    if (function_exists($function)) {

      // $order must be passed by reference.
      $result = $function('submit', $order, NULL);
      $msg_type = 'status';
      if (isset($result[0]['pass']) && $result[0]['pass'] === FALSE) {
        $error = TRUE;
        $msg_type = 'error';
      }
      if (!empty($result[0]['message'])) {
        drupal_set_message($result[0]['message'], $msg_type);
      }

      // Stop invoking the hooks if there was an error.
      if ($error) {
        break;
      }
    }
  }
  if ($error) {
    $form_state['redirect'] = $form_state['storage']['base_path'] . '/checkout/review';
  }
  else {
    unset($_SESSION['uc_checkout'][$order->order_id]['do_review']);
    $_SESSION['uc_checkout'][$order->order_id]['do_complete'] = TRUE;
    $form_state['redirect'] = $form_state['storage']['base_path'] . '/checkout/complete';
  }
}