You are here

function uc_recurring_order_pane_checkout in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 modules/uc_recurring_order/uc_recurring_order.module \uc_recurring_order_pane_checkout()

Checkout Pane callback function.

Used to display a form in the checkout process so that customers can select recurring/repeat option.

1 string reference to 'uc_recurring_order_pane_checkout'
uc_recurring_order_uc_checkout_pane in modules/uc_recurring_order/uc_recurring_order.module
Implements hook_uc_checkout_pane().

File

modules/uc_recurring_order/uc_recurring_order.module, line 183
Provides a way to duplicate entire orders.

Code

function uc_recurring_order_pane_checkout($op, &$order, $form = NULL, &$form_state = NULL) {
  switch ($op) {
    case 'view':
      $intervals = uc_recurring_order_get_intervals();
      if (empty($intervals)) {
        return;
      }

      // Use recurring order info from cart pane if available.
      if (isset($_SESSION['recurring_option'])) {
        $recurring = $_SESSION['recurring_option'];
        unset($_SESSION['recurring_option']);
      }
      else {
        $recurring = isset($order->data['recurring_option']) ? $order->data['recurring_option'] : '';
      }
      $description = t('Select to have this order automatically repeat.');
      $contents['recurring_option'] = array(
        '#type' => 'select',
        '#title' => t('Recurring Order'),
        '#default_value' => $recurring,
        '#options' => $intervals,
      );
      return array(
        'description' => $description,
        'contents' => $contents,
      );
    case 'process':

      // Can't renew orders that include product with recurring payments.
      if (module_exists('uc_recurring_product')) {
        if ($products = uc_recurring_product_get_recurring_products_in_order($order)) {
          unset($_SESSION['recurring_option']);
          drupal_set_message(t('Unable to create recurring order when it contains recurring products'), 'warning');
          return FALSE;
        }
      }
      $recurring = $form_state['values']['panes']['recurring']['recurring_option'];
      $next_renewal = strtotime('+' . $recurring, REQUEST_TIME);
      if ($next_renewal > REQUEST_TIME) {
        $order->data['recurring_option'] = $recurring;
      }
      else {
        unset($_SESSION['recurring_option']);
      }
      return TRUE;
    case 'review':
      $review = NULL;
      if (!empty($order->data['recurring_option'])) {
        $next_renewal = strtotime('+' . $order->data['recurring_option']);
        $review[] = array(
          'title' => t('Recurring Order'),
          'data' => t('Your next order after this will occur on @next.', array(
            '@recurring' => $order->data['recurring_option'],
            '@next' => format_date($next_renewal, 'short'),
          )),
        );
      }
      return $review;
  }
}