We have recently added non-taxable items to our store and found that the order total is incorrect with a Group Discount for an order consisting of all non-taxable items or a mixture of taxable and non-taxable items. The order total is correct for an order of all taxable items.

Looking through forum posts and the Zen Cart book revealed that this has been a problem in the past and the best advice is to experiment with settings. I think I have found a solution, at least for the business model of our store, and that may provide a clue to a possible bug in the code.

Our business model is to apply the group discount to the order subtotal, add shipping cost, and then tax on the result. So shipping is taxed, but the discount amount is not taxed. If an order includes non-taxable items, their discounted prices are excluded from tax. Group discount module settings are: (1) module installed – true, (2) sort order – 300, (3) include shipping – false, (4) include tax – false, (5) recalculate tax – Standard, and (6) Tax Class – none.

I tried changing various settings of the Group Discount module, but none gave correct results in all test cases. So I dug into the code of function calculate_deductions in includes/modules/order_total/ot_group_pricing.php and found that the array $od_amount[‘tax_groups’] had an item with a key of “0” with a value equal to the negative of the tax on an amount equal to the discount on the shipping. This value was exactly the error in the order total I was seeing. There was also an array item with a key equal to name of the tax. Further, when the order total was correct (for all taxable items in the cart), the array item $od_amount[tax_groups][0] was not present. Thinking that $od_amount[tax_groups][0] didn’t look right I boldly bypassed code in the Standard recalculate tax section if the key was “0”. Near the end of the function is a switch ($this->calculate_tax) statement with three Case statements for the three recalculate settings. Within the Standard case is a foreach statement and I bypassed the code within it if the $key was “0”.

Testing has shown that the module is now working correctly. Order totals are now correct for carts with all non-taxable items, all taxable items, and a mixture of taxable and non-taxable items. I can’t say whether this mod will work in other business models or in more complicated discount or tax situations, but it does work for me.

I did not track down where or how the $od_amount[tax_groups][0] is set but my findings might provide a clue to further debugging. I hope this helps others struggling with incorrect order totals with a group discount and mixture of taxable and non-taxable items.

Many thanks to the development team for their tireless efforts!

Dave