You are here

function uc_cart_checkout_form in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.pages.inc \uc_cart_checkout_form()
  2. 7.3 uc_cart/uc_cart.pages.inc \uc_cart_checkout_form()
8 string references to 'uc_cart_checkout_form'
uc_cart_checkout in uc_cart/uc_cart.module
Display the cart checkout page built of checkout panes from enabled modules.
uc_credit_form_alter in payment/uc_credit/uc_credit.module
Implementation of hook_form_alter().
uc_payment_form_alter in payment/uc_payment/uc_payment.module
Implementation of hook_form_alter().
uc_paypal_form_alter in payment/uc_paypal/uc_paypal.module
Implementation of hook_form_alter(). Notice how we alter the checkout review form to post the order to PayPal.
uc_quote_cache_quotes in shipping/uc_quote/uc_quote.module

... See full list

File

uc_cart/uc_cart.module, line 1376

Code

function uc_cart_checkout_form() {
  global $user;

  // Cancel an order when a customer clicks the 'Cancel' button.
  if ($_POST['op'] == t('Cancel')) {
    if (intval($_SESSION['cart_order']) > 0) {
      uc_order_comment_save($_SESSION['cart_order'], 0, t('Customer cancelled this order from the checkout form.'));
      unset($_SESSION['cart_order']);
    }
    drupal_goto('cart');
  }
  $order = uc_order_load($_SESSION['cart_order']);

  // Check the referer URI to clear order details and prevent identity theft.
  if (uc_referer_check(array(
    'cart/checkout',
    'cart/checkout/review',
  ))) {
    if ($order == FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
      unset($_SESSION['cart_order']);
      $order = NULL;
    }
    if (uc_order_status_data($order->order_status, 'state') != 'in_checkout' || $user->uid > 0 && $user->uid != $order->uid) {
      $order = NULL;
    }
  }
  else {
    unset($_SESSION['cart_order']);
    $order = NULL;
  }
  $form['panes'] = array(
    '#tree' => TRUE,
  );
  $panes = _checkout_pane_list();

  // If the cart isn't shippable, remove panes with shippable == TRUE.
  if (!uc_cart_is_shippable() && variable_get('uc_cart_delivery_not_shippable', TRUE)) {
    $panes = uc_cart_filter_checkout_panes($panes, array(
      'shippable' => TRUE,
    ));
  }
  foreach ($panes as $pane) {
    if (variable_get('uc_pane_' . $pane['id'] . '_enabled', TRUE)) {
      $pane['prev'] = _uc_cart_checkout_prev_pane($panes, $pane['id']);
      $pane['next'] = _uc_cart_checkout_next_pane($panes, $pane['id']);
      if (is_null($pane['collapsed'])) {
        $collapsed = $pane['prev'] === FALSE || empty($displayed[$pane['prev']]) ? FALSE : TRUE;
      }
      if (isset($_SESSION['expanded_panes'])) {
        if (is_array($_SESSION['expanded_panes']) && in_array($pane['id'], $_SESSION['expanded_panes'])) {
          $collapsed = FALSE;
        }
      }
      $return = $pane['callback']('view', $order, NULL);

      // Add the pane if any display data is returned from the callback.
      if (is_array($return) && (!empty($return['description']) || !empty($return['contents']))) {

        // Create the fieldset for the pane.
        $form['panes'][$pane['id']] = array(
          '#type' => 'fieldset',
          '#title' => $pane['title'],
          '#description' => !empty($return['description']) ? $return['description'] : NULL,
          '#collapsible' => $pane['collapsible'],
          '#collapsed' => variable_get('uc_use_next_buttons', FALSE) ? $collapsed : FALSE,
          '#attributes' => array(
            'id' => $pane['id'] . '-pane',
          ),
          '#theme' => $return['theme'],
        );

        // Add the contents of the fieldset if any were returned.
        if (!empty($return['contents'])) {
          $form['panes'][$pane['id']] = array_merge($form['panes'][$pane['id']], $return['contents']);
        }

        // Add the 'Next' button if necessary.
        if ($return['next-button'] !== FALSE && $pane['next'] !== FALSE && variable_get('uc_use_next_buttons', FALSE) != FALSE) {
          $opt = variable_get('uc_collapse_current_pane', FALSE) ? $pane['id'] : 'false';
          $form['panes'][$pane['id']]['next'] = array(
            '#type' => 'button',
            '#value' => variable_get('uc_checkout_next_button', t('Next')),
            '#weight' => variable_get("uc_pane_{$pane_id}_field_button_weight", 20),
            '#attributes' => array(
              'onclick' => "return uc_cart_next_button_click(this, '" . $pane['next'] . "', '" . $opt . "');",
            ),
            '#prefix' => '<div class="next-button show-onload">',
            '#suffix' => '</div>',
          );
        }

        // Log that this pane was actually displayed.
        $displayed[$pane['id']] = TRUE;
      }
    }
  }
  unset($_SESSION['expanded_panes']);
  $form['cart_contents'] = array(
    '#type' => 'hidden',
    '#value' => serialize(uc_cart_get_contents()),
  );
  if (variable_get('uc_cart_show_cancel', TRUE)) {
    $form['cancel'] = array(
      '#type' => 'submit',
      '#submit' => FALSE,
      '#value' => t('Cancel'),
    );
  }
  $form['continue'] = array(
    '#type' => 'submit',
    '#value' => variable_get('uc_checkout_review_button', t('Review order')),
  );
  return $form;
}