You are here

function uc_checkout_pane_coupon in Ubercart Discount Coupons 7.3

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.2 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 1581
Provides discount codes and gift certificates for Ubercart.

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':

      // Revalidate the session coupons against the actual order.
      drupal_add_css('#coupon-messages { clear: both; }', array(
        'type' => 'inline',
        'group' => CSS_DEFAULT,
      ));
      $description = variable_get('uc_coupon_pane_description', t('Enter a coupon code for this order.'));
      $submit = array(
        '#limit_validation_errors' => array(),
        '#ajax' => array(
          'callback' => 'uc_coupon_checkout_update',
        ),
        '#submit' => array(
          'uc_coupon_checkout_submit',
        ),
      );
      $contents = uc_coupon_form(array(), $form_state, 'checkout', $submit);
      $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['panes']['coupon'], $form_state);
        return FALSE;

        // Prevent redirection.
      }
      else {

        // !TODO Coupon will not be submitted 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;
  }
}