diff --git a/uc_taxes/uc_taxes.module b/uc_taxes/uc_taxes.module index a1d8322..38224cd 100644 --- a/uc_taxes/uc_taxes.module +++ b/uc_taxes/uc_taxes.module @@ -238,50 +238,59 @@ function uc_line_item_tax($op, $order) { /** * Handles the line item subtotal before taxes. */ -function uc_line_item_tax_subtotal($op, $order) { +function uc_line_item_tax_subtotal($op, $arg1) { $amount = 0; - $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; + switch ($op) { + case 'cart-preview': + if (!empty($arg1)) { + foreach ($arg1 as $item) { + $amount += $item->price * $item->qty; + } } - } - } - if (isset($order->taxes) && is_array($order->taxes)) { - $has_taxes = TRUE; - } - if ($different && $has_taxes) { - switch ($op) { - case 'cart-preview': + if (!empty($amount)) { drupal_add_js("if (Drupal.jsEnabled) { \$(document).ready(function() { if (window.set_line_item) { set_line_item('tax_subtotal', '". t('Subtotal excluding taxes') ."', ". $amount .", ". variable_get('uc_li_tax_subtotal_weight', 8) ."); } })};", 'inline'); + } break; - case 'load': + + case 'load': + $order = $arg1; + $has_taxes = FALSE; + $different = FALSE; + if (!empty($order->taxes) && is_array($order->taxes)) { + $has_taxes = TRUE; + } + if (is_array($order->products)) { + foreach ($order->products as $item) { + $amount += $item->price * $item->qty; + } + } + if (!empty($order->line_items) && 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 ($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), )); - } + } } }