Skip navigation
Help

uc_cart_view_form

6 uc_cart.module uc_cart_view_form($form_state, $items = NULL)
7 uc_cart.module uc_cart_view_form($form, &$form_state, $items = NULL)

Displays the contents of the customer's cart.

Handles simple or complex objects. Some cart items may have a list of products that they represent. These are displayed but are not able to be changed by the customer.

See also

uc_cart_view_form_submit()

uc_cart_view_form_continue_shopping()

uc_cart_view_form_checkout()

theme_uc_cart_view_form()

uc_cart_view_table()

Related topics

3 string references to 'uc_cart_view_form'

File

ubercart/uc_cart/uc_cart.module, line 602
Handles all things concerning Ubercart's shopping cart.

Code

function uc_cart_view_form($form, &$form_state, $items = NULL) {
  $form['#attached']['css'][] = drupal_get_path('module', 'uc_cart') . '/uc_cart.css';

  $form['items'] = array(
    '#type' => 'tapir_table', 
    '#tree' => TRUE,
  );

  $i = 0;
  $display_items = entity_view('uc_cart_item', $items, 'cart');
  foreach (element_children($display_items['uc_cart_item']) as $key) {
    $display_item = $display_items['uc_cart_item'][$key];
    if (count(element_children($display_item))) {
      $form['items'][$i] = $display_item;
      $form['items'][$i]['image'] = uc_product_get_picture($display_item['nid']['#value'], 'uc_cart');

      $description = $display_item['title']['#markup'] . $display_item['description']['#markup'];
      $form['items'][$i]['desc']['#markup'] = $description;

      if (isset($form['items'][$i]['remove'])) {
        // Backward compatibility with old checkbox method.
        if ($form['items'][$i]['remove']['#type'] == 'checkbox') {
          $form['items'][$i]['remove'] = array(
            '#type' => 'submit',
            '#value' => t('Remove'),
          );
        }

        $form['items'][$i]['remove']['#name'] = 'remove-' . $i;
      }

      $form['items'][$i]['title']['#type'] = 'value';
      $form['items'][$i]['description']['#type'] = 'value';

      if (empty($display_item['qty'])) {
        $form['items'][$i]['qty'] = array(
          '#type' => 'hidden', 
          '#value' => 0,
        );
      }

      $form['items'][$i]['total'] = array(
        '#theme' => 'uc_price', 
        '#price' => $display_item['#total'],
      );
      if (!empty($display_item['#suffixes'])) {
        $form['items'][$i]['total']['#suffixes'] = $display_item['#suffixes'];
      }
    }
    $i++;
  }

  $form['items'] = tapir_get_table('uc_cart_view_table', $form['items']);

  $form['actions'] = array('#type' => 'actions');

  // If the continue shopping element is enabled...
  if (($cs_type = variable_get('uc_continue_shopping_type', 'link')) !== 'none') {
    // Add the element to the form based on the element type.
    if (variable_get('uc_continue_shopping_type', 'link') == 'link') {
      $form['actions']['continue_shopping'] = array(
        '#markup' => l(t('Continue shopping'), uc_cart_continue_shopping_url()),
      );
    }
    elseif (variable_get('uc_continue_shopping_type', 'link') == 'button') {
      $form['actions']['continue_shopping'] = array(
        '#type' => 'submit', 
        '#value' => t('Continue shopping'), 
        '#submit' => array('uc_cart_view_form_submit', 'uc_cart_view_form_continue_shopping'),
      );
    }
  }

  // Add the empty cart button if enabled.
  if (variable_get('uc_cart_empty_button', FALSE)) {
    $form['actions']['empty'] = array(
      '#type' => 'submit', 
      '#value' => t('Empty cart'), 
      '#submit' => array('uc_cart_view_form_empty'),
    );
  }

  // Add the control buttons for updating and proceeding to checkout.
  $form['actions']['update'] = array(
    '#type' => 'submit', 
    '#name' => 'update-cart', 
    '#value' => t('Update cart'), 
    '#submit' => array('uc_cart_view_form_submit', 'uc_cart_view_form_update_message'),
  );
  $form['actions']['checkout'] = array(
    '#theme' => 'uc_cart_checkout_buttons',
  );
  if (variable_get('uc_checkout_enabled', TRUE)) {
    $form['actions']['checkout']['checkout'] = array(
      '#type' => 'submit', 
      '#value' => t('Checkout'), 
      '#submit' => array('uc_cart_view_form_submit', 'uc_cart_view_form_checkout'),
    );
  }

  return $form;
}