You are here

function uc_cart_checkout in Ubercart 5

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

Display the cart checkout page built of checkout panes from enabled modules.

1 string reference to 'uc_cart_checkout'
uc_cart_menu in uc_cart/uc_cart.module
Implementation of hook_menu().

File

uc_cart/uc_cart.module, line 1327

Code

function uc_cart_checkout() {
  global $user;
  $items = uc_cart_get_contents();
  if (count($items) == 0 || !variable_get('uc_checkout_enabled', TRUE)) {
    drupal_goto('cart');
  }
  if (($min = variable_get('uc_minimum_subtotal', 0)) > 0) {
    $subtotal = 0;
    $items = uc_cart_get_contents();
    if (is_array($items) && count($items) > 0) {
      foreach ($items as $item) {
        $data = module_invoke($item->module, 'cart_display', $item);
        if (!empty($data)) {
          $subtotal += $data['#total'];
        }
      }
    }
    if ($subtotal < $min) {
      drupal_set_message(variable_get('uc_minimum_subtotal_text', t('The minimum order subtotal for checkout is !min.', array(
        '!min' => uc_currency_format($min),
      ))), 'error');
      drupal_goto('cart');
    }
  }

  // Send anonymous users to login page when anonymous checkout is disabled.
  if (!$user->uid && !variable_get('uc_checkout_anonymous', TRUE)) {
    drupal_set_message(t('You must login before you can proceed to checkout.'));
    drupal_set_message(t('If you do not have an account, you can <a href="!url">click here</a> to create one.', array(
      '!url' => url('user/register', NULL, NULL, TRUE),
    )));
    $_SESSION['checkout-redirect'] = TRUE;
    drupal_goto('user');
  }
  else {
    unset($_SESSION['checkout-redirect']);
  }
  $list = _line_item_list();
  foreach ($list as $line_item) {
    if (function_exists($line_item['callback'])) {
      $line_item['callback']('cart-preview', $items);
    }
  }
  uc_add_js(drupal_get_path('module', 'uc_cart') . '/uc_cart.js');
  $output = drupal_get_form('uc_cart_checkout_form');
  return $output;
}