You are here

function uc_cart_checkout_form_validate in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.pages.inc \uc_cart_checkout_form_validate()
  2. 7.3 uc_cart/uc_cart.pages.inc \uc_cart_checkout_form_validate()

File

uc_cart/uc_cart.module, line 1506

Code

function uc_cart_checkout_form_validate($form_id, $form_values) {
  global $user;
  if (empty($_SESSION['cart_order'])) {
    $order = uc_order_new($user->uid);
    $_SESSION['cart_order'] = $order->order_id;
  }
  else {
    $order = new stdClass();
    $order->uid = $user->uid;
    $order->order_id = $_SESSION['cart_order'];
    $order->order_status = uc_order_state_default('in_checkout');
  }
  $order->products = unserialize($form_values['cart_contents']);
  $order->order_total = uc_order_get_total($order, TRUE);

  // Validate/process the cart panes.  A FALSE value results in failed checkout.
  $_SESSION['checkout_valid'] = TRUE;
  foreach (element_children($form_values['panes']) as $pane_id) {
    $func = _checkout_pane_data($pane_id, 'callback');
    $isvalid = $func('process', $order, $form_values['panes'][$pane_id]);
    if ($isvalid === FALSE) {
      $_SESSION['expanded_panes'][] = $pane_id;
      $_SESSION['checkout_valid'] = FALSE;
    }
  }
  $order->line_items = uc_order_load_line_items($order->order_id, TRUE);
  uc_order_save($order);
}