You are here

function uc_line_item_tax_subtotal in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_taxes/uc_taxes.module \uc_line_item_tax_subtotal()
  2. 6.2 uc_taxes/uc_taxes.module \uc_line_item_tax_subtotal()

Handles the line item subtotal before taxes.

1 string reference to 'uc_line_item_tax_subtotal'
uc_taxes_uc_line_item in uc_taxes/uc_taxes.module
Implements hook_uc_line_item().

File

uc_taxes/uc_taxes.module, line 296
Ubercart Taxes module.

Code

function uc_line_item_tax_subtotal($op, $order) {
  $amount = 0;
  switch ($op) {
    case 'display':
      $has_taxes = FALSE;
      $different = FALSE;
      if (is_array($order->products)) {
        foreach ($order->products as $item) {
          $amount += $item->price * $item->qty;
        }
      }
      if (is_array($order->line_items)) {
        foreach ($order->line_items as $key => $line_item) {
          if ($line_item['type'] == 'subtotal') {
            continue;
          }
          if (substr($line_item['type'], 0, 3) != 'tax') {
            $amount += $line_item['amount'];
            $different = TRUE;
          }
          else {
            $has_taxes = TRUE;
          }
        }
      }
      if (isset($order->taxes) && is_array($order->taxes) && count($order->taxes)) {
        $has_taxes = TRUE;
      }
      if ($different && $has_taxes) {
        return array(
          array(
            'id' => 'tax_subtotal',
            'title' => t('Subtotal excluding taxes'),
            'amount' => $amount,
            'weight' => variable_get('uc_li_tax_subtotal_weight', 7),
          ),
        );
      }
      break;
  }
}