Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#1 | uc_taxes-calculate_alter-2323681-1.patch | 446 bytes | stewart.adam |
Comments
Comment #1
stewart.adam CreditAttribution: stewart.adam commentedPatch attached.
Comment #2
TR CreditAttribution: TR commentedCan 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.
Comment #3
stewart.adam CreditAttribution: stewart.adam commentedPayment 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.
Comment #4
longwaveThe 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.
Comment #5
longwaveI also suggest the parameter order should be ($taxes, $order) as in drupal_alter the thing that you are altering generally comes first.