You are here

function uc_coupon_tax_adjustment in Ubercart Discount Coupons 6

Same name and namespace in other branches
  1. 7.3 uc_coupon.module \uc_coupon_tax_adjustment()
  2. 7.2 uc_coupon.module \uc_coupon_tax_adjustment()

Handle tax on coupons by calculating tax for individual discounted prices. This is currently only supported by the VAT module (uc_vat).

1 string reference to 'uc_coupon_tax_adjustment'
uc_coupon_line_item in ./uc_coupon.module
Implementation of hook_line_item().

File

./uc_coupon.module, line 1145
Provides discount coupons for Ubercart.

Code

function uc_coupon_tax_adjustment($price, $order, $tax) {
  if (isset($order->data['coupon'])) {
    $code = $order->data['coupon'];
  }
  else {
    if (isset($_SESSION['uc_coupon'])) {
      $code = $_SESSION['uc_coupon'];
    }
    else {
      return;
    }
  }
  $coupon = uc_coupon_find($code);
  $items = uc_coupon_calculate_discounts($coupon, $order);
  $amount = 0;
  if (is_array($items)) {
    foreach ($items as $item) {
      $node = node_load($item->nid);
      if (in_array($node->type, $tax->taxed_product_types) && ($tax->shippable == 0 || $node->shippable == 1)) {
        $amount += $item->discount * $tax->rate * ($price > 0 ? 1 : -1);
      }
    }
  }
  return $amount;
}