You are here

function uc_taxes_apply_item_tax in Ubercart 7.3

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

Calculates taxable amount for a single product.

2 calls to uc_taxes_apply_item_tax()
uc_taxes_apply_tax in uc_taxes/uc_taxes.module
Applies taxes to an order.
uc_taxes_get_included_tax in uc_taxes/uc_taxes.module
Calculates the taxes that should be included in a product's display price.

File

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

Code

function uc_taxes_apply_item_tax($item, $tax) {

  // Determine the product type.
  if (is_array($item->data) && isset($item->data['type'])) {

    // Saved in the order product data array.
    $type = $item->data['type'];
  }
  elseif (empty($item->nid)) {

    // "Blank-line" product.
    $type = 'blank-line';
  }
  elseif ($node = node_load($item->nid)) {

    // Use type of current node, if it exists.
    $type = $node->type;
  }
  else {

    // Default to generic product.
    $type = 'product';
  }

  // Determine whether this is a shippable product.
  if (is_array($item->data) && isset($item->data['shippable'])) {

    // Saved in the order product data array.
    $shippable = $item->data['shippable'];
  }
  elseif (empty($item->nid)) {

    // "Blank line" product.
    $shippable = $item->weight > 0;
  }
  elseif ($node = node_load($item->nid)) {

    // Use current node.
    $shippable = $node->shippable;
  }
  else {
    $shippable = variable_get('uc_product_shippable_' . $type);

    // Use default for this node type.
  }

  // Tax products if they are of a taxed type and if it is shippable if
  // the tax only applies to shippable products.
  if (in_array($type, $tax->taxed_product_types) && ($tax->shippable == 0 || $shippable == 1)) {
    return $item->price;
  }
  else {
    return FALSE;
  }
}