You are here

function theme_uc_discounts_uc_cart_review_table in Ubercart Discounts (Alternative) 7.2

Theme shopping cart checkout table.

Parameters

array $variables:

Return value

string

1 theme call to theme_uc_discounts_uc_cart_review_table()
uc_discounts_uc_checkout_pane_cart in uc_discounts/uc_discounts.module
Callback that replaces the stock ubercart checkout cart pane.

File

uc_discounts/uc_discounts.module, line 747

Code

function theme_uc_discounts_uc_cart_review_table($variables) {
  $items = $variables['items'];
  $show_subtotal = $variables['show_subtotal'];
  $discount_amount = $variables['discount'];
  $subtotal = 0;

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

  // Set up table rows.
  $display_items = uc_order_product_view_multiple($items);
  if (!empty($display_items['uc_order_product'])) {
    foreach (element_children($display_items['uc_order_product']) as $key) {
      $display_item = $display_items['uc_order_product'][$key];
      $subtotal += $display_item['total']['#price'];
      $rows[] = array(
        array(
          'data' => $display_item['qty'],
          'class' => array(
            'qty',
          ),
        ),
        array(
          'data' => $display_item['product'],
          'class' => array(
            'products',
          ),
        ),
        array(
          'data' => $display_item['total'],
          'class' => array(
            'price',
          ),
        ),
      );
    }
  }

  // Add the subtotal as the final row.
  if ($show_subtotal) {
    $rows[] = array(
      'data' => array(
        // One cell.
        array(
          'data' => array(
            '#theme' => 'uc_price',
            '#prefix' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ',
            '#price' => $subtotal,
          ),
          // Cell attributes.
          'colspan' => 3,
          'class' => array(
            'subtotal',
          ),
        ),
      ),
      // Row attributes.
      'class' => array(
        'subtotal',
      ),
    );
    if ($discount_amount > 0) {

      // Add the discounts row.
      $rows[] = array(
        'data' => array(
          // One cell.
          array(
            'data' => array(
              '#theme' => 'uc_price',
              '#prefix' => '<span id="discount-amount-title">' . t('Total discounts:') . '</span> ',
              '#price' => -$discount_amount,
            ),
            // Cell attributes.
            'colspan' => 3,
            'class' => array(
              'subtotal',
            ),
          ),
        ),
        // Row attributes.
        'class' => array(
          'discount',
        ),
      );

      // Add the subtital with discounts row.
      $rows[] = array(
        'data' => array(
          // One cell.
          array(
            'data' => array(
              '#theme' => 'uc_price',
              '#prefix' => '<span id="discount-subtotal-title">' . t('Subtotal with discounts:') . '</span> ',
              '#price' => $subtotal - $discount_amount,
            ),
            // Cell attributes.
            'colspan' => 3,
            'class' => array(
              'subtotal',
            ),
          ),
        ),
        // Row attributes.
        'class' => array(
          'discount',
        ),
      );
    }
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'cart-review',
      ),
    ),
  ));
}