You are here

function theme_cart_review_table in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_cart/uc_cart_checkout_pane.inc \theme_cart_review_table()

Formats the cart contents table on the checkout page.

Parameters

$show_subtotal: TRUE or FALSE indicating if you want a subtotal row displayed in the table.

Return value

The HTML output for the cart review table.

2 theme calls to theme_cart_review_table()
uc_checkout_pane_cart in uc_cart/uc_cart_checkout_pane.inc
Displays the cart contents for review during checkout.
uc_paypal_ec_submit in payment/uc_paypal/uc_paypal.pages.inc

File

uc_cart/uc_cart_checkout_pane.inc, line 586
Callbacks for the default Ubercart checkout panes and their corresponding helper functions.

Code

function theme_cart_review_table($show_subtotal = TRUE) {
  $subtotal = 0;

  // Set up table header.
  $header = array(
    array(
      'data' => t('Qty'),
      'class' => 'qty',
    ),
    array(
      'data' => t('Products'),
      'class' => 'products',
    ),
    array(
      'data' => t('Price'),
      'class' => 'price',
    ),
  );
  $context = array();

  // Set up table rows.
  $contents = uc_cart_get_contents();
  foreach ($contents as $item) {
    $price_info = array(
      'price' => $item->price,
      'qty' => $item->qty,
    );
    $context['revision'] = 'altered';
    $context['type'] = 'cart_item';
    $context['subject'] = array(
      'cart' => $contents,
      'cart_item' => $item,
      'node' => node_load($item->nid),
    );
    $total = uc_price($price_info, $context);
    $subtotal += $total;
    $description = check_plain($item->title) . uc_product_get_description($item);

    // Remove node from context to prevent the price from being altered.
    $context['revision'] = 'themed-original';
    $context['type'] = 'amount';
    unset($context['subject']);
    $rows[] = array(
      array(
        'data' => t('@qty×', array(
          '@qty' => $item->qty,
        )),
        'class' => 'qty',
      ),
      array(
        'data' => $description,
        'class' => 'products',
      ),
      array(
        'data' => uc_price($total, $context),
        'class' => 'price',
      ),
    );
  }

  // Add the subtotal as the final row.
  if ($show_subtotal) {
    $context = array(
      'revision' => 'themed-original',
      'type' => 'amount',
    );
    $rows[] = array(
      'data' => array(
        array(
          'data' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ' . uc_price($subtotal, $context),
          'colspan' => 3,
          'class' => 'subtotal',
        ),
      ),
      'class' => 'subtotal',
    );
  }
  return theme('table', $header, $rows, array(
    'class' => 'cart-review',
  ));
}