You are here

function uc_line_item_tax in Ubercart 5

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

Handle the tax line item.

1 call to uc_line_item_tax()
uc_taxes_order in uc_taxes/uc_taxes.module
Update and save tax line items to the order.
1 string reference to 'uc_line_item_tax'
uc_taxes_line_item in uc_taxes/uc_taxes.module
Implementation of Übercart's hook_line_item().

File

uc_taxes/uc_taxes.module, line 336

Code

function uc_line_item_tax($op, $order) {
  switch ($op) {
    case 'cart-preview':

      /* $items = $order;
         $order = new stdClass();
         $order->products = $items; */
      $taxes = module_invoke_all('calculate_tax', $order);
      $script = '';
      foreach ($taxes as $tax) {
        $script .= "set_line_item('tax_" . $tax['id'] . "', '" . $tax['name'] . "', " . $tax['amount'] . ", + " . variable_get('uc_li_tax_weight', 9) + $tax['weight'] / 10 . ", 1, false);\n";
      }
      if ($script) {
        uc_add_js("\$(document).ready(function() {\n          if (window.set_line_item) {\n            " . $script . ";\n            render_line_items();\n          }\n        });", 'inline');
      }
      break;
    case 'load':
      $lines = array();
      $taxes = module_invoke_all('calculate_tax', $order);
      foreach ($taxes as $tax) {
        $lines[] = array(
          'id' => 'tax',
          'title' => $tax['name'],
          'amount' => $tax['amount'],
          'weight' => variable_get('uc_li_tax_weight', 9) + $tax['weight'] / 10,
          'data' => $tax['data'],
        );
      }
      return $lines;
  }
}