You are here

function uc_checkout_pane_coupon in Ubercart Discount Coupons 7.2

Same name and namespace in other branches
  1. 5 uc_coupon.module \uc_checkout_pane_coupon()
  2. 6 uc_coupon.module \uc_checkout_pane_coupon()
  3. 7.3 uc_coupon.module \uc_checkout_pane_coupon()

Checkout Pane callback function.

Used to display a form in the checkout process so that customers can enter discount coupons.

1 string reference to 'uc_checkout_pane_coupon'
uc_coupon_uc_checkout_pane in ./uc_coupon.module
Implements hook_uc_checkout_pane().

File

./uc_coupon.module, line 1450

Code

function uc_checkout_pane_coupon($op, &$order, $form = NULL, &$form_state = NULL) {
  switch ($op) {
    case 'prepare':

      // Remove fake cart items from the order.
      foreach ($order->products as $key => $product) {
        if (isset($product->module) && $product->module == 'uc_coupon') {
          unset($order->products[$key]);
        }
      }
      break;
    case 'view':
      drupal_add_css('#coupon-messages { clear: both; }', array(
        'type' => 'inline',
        'group' => CSS_DEFAULT,
      ));
      $ajax = array(
        'callback' => 'uc_coupon_checkout_update',
      );
      $description = variable_get('uc_coupon_pane_description', t('Enter a coupon code for this order.'));
      $contents = uc_coupon_form(array(), $form_state, 'checkout', $ajax);
      $contents['message'] = array(
        '#markup' => '<div id="coupon-messages"></div>',
        '#weight' => 2,
      );
      return array(
        'description' => $description,
        'contents' => $contents,
        'theme' => 'uc_coupon_form',
      );
    case 'process':
      $trigger = $form_state['triggering_element']['#name'];
      if (substr($trigger, 0, 9) == 'uc-coupon') {
        $form_state['rebuild'] = TRUE;
        uc_coupon_form_submit($form, $form_state);
        uc_coupon_session_validate($order->products);
        return FALSE;

        // Prevent redirection.
      }
      else {

        // !TODO Coupon will not be validated if "Apply to order" is not clicked.  Is this what we want?
        return TRUE;
      }
    case 'settings':
      $form['uc_coupon_collapse_pane'] = array(
        '#type' => 'checkbox',
        '#title' => t('Collapse checkout pane by default.'),
        '#default_value' => variable_get('uc_coupon_collapse_pane', FALSE),
      );
      $form['uc_coupon_pane_description'] = array(
        '#type' => 'textarea',
        '#title' => t('Checkout pane message'),
        '#default_value' => variable_get('uc_coupon_pane_description', t('Enter a coupon code for this order.')),
      );
      return $form;
  }
}