You are here

function uc_checkout_pane_billing in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_billing()
  2. 7.3 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_billing()

Get the billing information.

1 string reference to 'uc_checkout_pane_billing'
uc_cart_checkout_pane in uc_cart/uc_cart.module
Implementation of hook_checkout_pane().

File

uc_cart/uc_cart_checkout_pane.inc, line 303
This file contains the callbacks for the default checkout panes supplied with Ubercart and their corresponding helper functions.

Code

function uc_checkout_pane_billing($op, &$arg1, $arg2) {
  global $user;
  switch ($op) {
    case 'view':
      $description = t('Enter your billing address and information here.');
      if ((uc_cart_is_shippable() || !variable_get('uc_cart_delivery_not_shippable', TRUE)) && _checkout_pane_data('delivery', 'weight') < _checkout_pane_data('billing', 'weight') && _checkout_pane_data('delivery', 'enabled')) {
        $contents['copy_address'] = array(
          '#type' => 'checkbox',
          '#title' => t('My billing information is the same as my delivery information.'),
          '#attributes' => array(
            'onclick' => "uc_cart_copy_address(this.checked, 'delivery', 'billing');",
          ),
        );
      }
      if ($user->uid) {
        $addresses = uc_select_address($user->uid, 'billing', 'apply_address(\'billing\', this.value);', t('Saved addresses'), TRUE);
        if (!empty($addresses)) {
          $contents['billing_address_select'] = $addresses;
        }
      }
      if (uc_address_field_enabled('first_name')) {
        $contents['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->billing_first_name, uc_address_field_required('first_name'));
      }
      if (uc_address_field_enabled('last_name')) {
        $contents['billing_last_name'] = uc_textfield(uc_get_field_name('last_name'), $arg1->billing_last_name, uc_address_field_required('last_name'));
      }
      if (uc_address_field_enabled('company')) {
        $contents['billing_company'] = uc_textfield(uc_get_field_name('company'), $arg1->billing_company, uc_address_field_required('company'), NULL, 64);
      }
      if (uc_address_field_enabled('street1')) {
        $contents['billing_street1'] = uc_textfield(uc_get_field_name('street1'), $arg1->billing_street1, uc_address_field_required('street1'), NULL, 64);
      }
      if (uc_address_field_enabled('street2')) {
        $contents['billing_street2'] = uc_textfield(uc_get_field_name('street2'), $arg1->billing_street2, uc_address_field_required('street2'), NULL, 64);
      }
      if (uc_address_field_enabled('city')) {
        $contents['billing_city'] = uc_textfield(uc_get_field_name('city'), $arg1->billing_city, uc_address_field_required('city'));
      }
      if (uc_address_field_enabled('country')) {
        $contents['billing_country'] = uc_country_select(uc_get_field_name('country'), $arg1->billing_country, NULL, 'name', uc_address_field_required('country'));
      }
      if (uc_address_field_enabled('zone')) {
        if (isset($_POST['panes']['billing']['billing_country'])) {
          $country_id = intval($_POST['panes']['billing']['billing_country']);
        }
        else {
          $country_id = $arg1->billing_country;
        }
        $contents['billing_zone'] = uc_zone_select(uc_get_field_name('zone'), $arg1->billing_zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
        if (isset($_POST['panes']) && count($contents['billing_zone']['#options']) == 1) {
          $contents['billing_zone']['#required'] = FALSE;
        }
      }
      if (uc_address_field_enabled('postal_code')) {
        $contents['billing_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $arg1->billing_postal_code, uc_address_field_required('postal_code'), NULL, 10, 10);
      }
      if (uc_address_field_enabled('phone')) {
        $contents['billing_phone'] = uc_textfield(uc_get_field_name('phone'), $arg1->billing_phone, uc_address_field_required('phone'), NULL, 32, 16);
      }
      return array(
        'description' => $description,
        'contents' => $contents,
        'theme' => 'address_pane',
      );
    case 'process':
      $arg1->billing_first_name = $arg2['billing_first_name'];
      $arg1->billing_last_name = $arg2['billing_last_name'];
      $arg1->billing_company = $arg2['billing_company'];
      $arg1->billing_street1 = $arg2['billing_street1'];
      $arg1->billing_street2 = $arg2['billing_street2'];
      $arg1->billing_city = $arg2['billing_city'];
      $arg1->billing_zone = $arg2['billing_zone'];
      $arg1->billing_postal_code = $arg2['billing_postal_code'];
      $arg1->billing_country = $arg2['billing_country'];
      $arg1->billing_phone = $arg2['billing_phone'];
      return TRUE;
    case 'review':
      $review[] = array(
        'title' => t('Address'),
        'data' => uc_order_address($arg1, 'billing', FALSE),
      );
      if (uc_address_field_enabled('phone') && !empty($arg1->billing_phone)) {
        $review[] = array(
          'title' => t('Phone'),
          'data' => check_plain($arg1->billing_phone),
        );
      }
      return $review;
  }
}