It would be great to have a call to drupal_alter() in uc_taxes_calculate() to allow other modules to alter the tax calculations returned by other modules. I have a project (Ubercart Payment After Checkout) as well as some custom code at work that requires this patch in order to alter tax calculation for orders under certain circumstances.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stewart.adam’s picture

Status: Active » Needs review
FileSize
446 bytes

Patch attached.

TR’s picture

Can you describe a situation (the "certain circumstances") where this would be needed? Tax rates are set by regulation, and these regulations allow no discretion about what rates you charge. I think if you're not calculating the tax correctly the first time through then your taxes are configured wrong or the tax module you're using has a bug. If you're wanting to use an alter hook in lieu of properly setting up a tax-exempt customer role (or something along those lines), I think that's the wrong approach.

stewart.adam’s picture

Payment after checkout is a bit of a special case because it's a hack that effectively creates a second checkout process. I need to trigger tax calculation as if it were a fresh order, even though the order may be in a more advanced state in the order workflow. Thus I can't use the regular hooks; I need to use this alter hook to modify the existing algorithms and imitate tax calculation as if it were a order in checkout.

The other "certain circumstances" involves another stretch of the original intentions of uc_taxes: cases where you want something that behaves like tax but isn't in itself a government mandated tax. A sliding fee that is a percentage of an order, for example. The tax line items have configurable titles and can be applied to different types of line items easily through the UI, so they make a good candidate for getting the job done quickly and effectively even though that wasn't the use case they were designed for.

Although you are correct in saying for government taxes we have no lenience, this is not true if you're using the tax module as a means to an end. And certainly there it would be nice to have the possibility for other modules come in and alter the calculations a bit.

longwave’s picture

Status: Needs review » Needs work

The original hook_uc_calculate_tax() doesn't have the best name, but for consistency can we call this hook_uc_calculate_tax_alter() instead of hook_uc_tax_calculation_alter()? Also, documenting the hook and its parameters in uc_taxes.api.php would be good; we can use that to discourage people from using it in the wrong way, as TR mentions.

longwave’s picture

I also suggest the parameter order should be ($taxes, $order) as in drupal_alter the thing that you are altering generally comes first.