You are here

function uc_line_item_tax_subtotal in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_taxes/uc_taxes.module \uc_line_item_tax_subtotal()
  2. 7.3 uc_taxes/uc_taxes.module \uc_line_item_tax_subtotal()
1 call to uc_line_item_tax_subtotal()
uc_taxes_javascript in uc_taxes/uc_taxes.module
AJAX callback for order preview.
1 string reference to 'uc_line_item_tax_subtotal'
uc_taxes_line_item in uc_taxes/uc_taxes.module
Implementation of Übercart's hook_line_item().

File

uc_taxes/uc_taxes.module, line 372

Code

function uc_line_item_tax_subtotal($op, $order) {
  $amount = 0;
  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 (substr($line_item['type'], 0, 3) != 'tax') {
        $amount += $line_item['amount'];
        $different = true;
      }
      else {
        $has_taxes = true;
      }
    }
  }
  if (is_array($order->taxes)) {
    $has_taxes = true;
  }
  if ($different && $has_taxes) {
    switch ($op) {
      case 'cart-preview':
        uc_add_js("\$(document).ready(function() {\n          if (window.set_line_item) {\n            set_line_item('tax_subtotal', '" . t('Subtotal excluding taxes') . "', " . $amount . ", " . variable_get('uc_li_tax_subtotal_weight', 8) . ");\n          }\n        });", 'inline');
        break;
      case 'load':
        return array(
          array(
            'id' => 'tax_subtotal',
            'title' => t('Subtotal excluding taxes'),
            'amount' => $amount,
            'weight' => variable_get('uc_li_tax_subtotal_weight', 7),
          ),
        );
    }
  }
}