You are here

function theme_uc_discounts_cart_checkout_table in Ubercart Discounts (Alternative) 6.2

1 theme call to theme_uc_discounts_cart_checkout_table()
uc_discounts_checkout_pane_content in uc_discounts/uc_discounts.module

File

uc_discounts/uc_discounts.module, line 778

Code

function theme_uc_discounts_cart_checkout_table($show_subtotal = TRUE) {
  $subtotal = 0;
  $discount_amount = uc_discounts_get_discount_amount_for_order('checkout');

  // 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 * $discount_amount,
      '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',
      ),
    );
  }
  if ($discount_amount > 0) {
    $rows[] = array(
      array(
        'data' => '',
      ),
      array(
        'data' => t('Discount:'),
        'align' => 'right',
      ),
      array(
        'data' => uc_price($discount_amount, $context),
        'class' => 'price',
      ),
    );
    $subtotal = $subtotal - $discount_amount;
  }

  // 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',
  ));
}