Definition

address_checkout_form($txn)
ecommerce-5--3/address/address.module, line 243

Description

The form to set the shipping and billing address in the checkout procedure.

Code

<?php
function address_checkout_form($txn) {
  global $user;

  /* Configure the how to render addresss info */
  if ($txn->uid > 0) {

    /* Grab the user's addressbook */
    $address = address_get_addresses($txn->uid);
    if (empty($address)) {
      drupal_set_message(t('There are no addresses in your addressbook.  Please add a shipping/delivery address now.'));
      drupal_goto('user/'. $txn->uid. '/address/add', drupal_get_destination());
    }    
    // theme the options list 
    $options = theme_address_list($address);
    $address_format = variable_get('ec_address_display_format', 0);

    $form_type = (variable_get('ec_address_display_format', 0) == 0 ) ? 'select' : 'radios';
    
    if ($txn->shippable) {
      $form['shipping_address'] = array(
        '#type' => $form_type,
        '#title' => t('Shipping to'),
        '#default_value' => $txn->shipping_address,
        '#options' => $options,
        '#description' => t('Please choose where you would like the items to be delivered. You can also <a href="!add_address">add a new address</a>.', array('!add_address' => url("user/$txn->uid/address/add", drupal_get_destination()))),
      );
    }

    $form['billing_address'] = array(
      '#type' => $form_type,
      '#title' => t('Billing to'),
      '#default_value' => $txn->billing_address,
      '#options' => $options,
      '#description' => t('Please choose where you would like the invoice to be sent. You can also <a href="!add_address">add a new address</a>.', array('!add_address' => url("user/$txn->uid/address/add", drupal_get_destination()))),
    );
  }
  else {
    /* Don't use the addressbook if the user can buy anonymously */
    $form['address']['billing']['#type'] = 'fieldset';
    $form['address']['billing']['#title'] = t('Billing address');
    $form['address']['billing'] = store_address_form($txn->address['billing']);
    $form['address']['billing']['firstname']['#required'] = TRUE;
    $form['address']['billing']['lastname']['#required'] = TRUE;
    if ($txn->shippable) {
      $form['address']['shipping'] = store_address_form($txn->address['shipping']);
      $form['address']['shipping']['#type'] = 'fieldset';
      $form['address']['shipping']['#title'] = t('Shipping address');
    }
  }

  $form['address']['#tree'] = TRUE;
  return $form;
}
?>