You are here

function uc_cart_checkout_form in Ubercart 6.2

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

The checkout form built up from the enabled checkout panes.

See also

uc_cart_checkout_form_validate()

uc_cart_checkout_form_review()

uc_cart_checkout_review()

theme_uc_cart_checkout_form()

6 string references to 'uc_cart_checkout_form'
uc_cart_checkout in uc_cart/uc_cart.pages.inc
Displays the cart checkout page built of checkout panes from enabled modules.
uc_credit_form_alter in payment/uc_credit/uc_credit.module
Implements hook_form_alter().
uc_payment_form_alter in payment/uc_payment/uc_payment.module
Implements hook_form_alter().
uc_paypal_form_alter in payment/uc_paypal/uc_paypal.module
Implements hook_form_alter().
uc_quote_form_alter in shipping/uc_quote/uc_quote.module
Implements hook_form_alter().

... See full list

File

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

Code

function uc_cart_checkout_form() {
  global $user;

  // Cancel an order when a customer clicks the 'Cancel' button.
  if (isset($_POST['op']) && $_POST['op'] == t('Cancel')) {
    if (isset($_SESSION['cart_order']) && 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');
  }
  if (isset($_SESSION['cart_order'])) {
    $order = uc_order_load($_SESSION['cart_order']);
  }
  else {
    $order = new UcOrder();
  }

  // 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 = new UcOrder();
    }
    elseif (uc_order_status_data($order->order_status, 'state') != 'in_checkout' || $user->uid > 0 && $user->uid != $order->uid) {
      $order = new UcOrder();
    }
  }
  else {
    unset($_SESSION['cart_order']);
    $order = new UcOrder();
  }
  $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 ($pane['enabled']) {
      $pane['prev'] = _uc_cart_checkout_prev_pane($panes, $pane['id']);
      $pane['next'] = _uc_cart_checkout_next_pane($panes, $pane['id']);
      if (!isset($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' => isset($return['theme']) ? $return['theme'] : NULL,
        );

        // 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 ((!isset($return['next-button']) || $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' => 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']);
  $contents = uc_cart_get_contents();
  $form['cart_contents'] = array(
    '#type' => 'hidden',
    '#value' => serialize($contents),
  );
  $form['uid'] = array(
    '#type' => 'hidden',
    '#value' => $user->uid,
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#submit' => FALSE,
  );
  $form['continue'] = array(
    '#type' => 'submit',
    '#value' => t('Review order'),
  );
  return $form;
}