This is indeed a nightmare. I really need the help of your collective minds on this one:
In Canada, taxes are calculated differently from province to province:
Alberta - 5%
British Columbia - 5% GST and 7% PST
Calculating the straight tax on the price of each product is easy ... I loop over all of the items within the my cart and calculate the tax per the product price. Even when items are PST exempt, I can check for that...
The tricky part is when I have to apply a coupon code with a discount!
Obviously any discounts need to be applied to the pre-tax amounts... but I need to process each item separately to calculate the tax. I can't deduct say, $20 off of the cart total, because each item has it's own set price... which means while I'm processing each item, I need to know what the prices are AFTER the discount.
But remember how some products are PST exempt? Well, that weighs into the complication here:
Item 1 - $24.99 - GST (5%) and PST (7%)
Item 2 - $11.99 - GST (5%)
Discount - $20.00
How on earth can I apply the cart discount, but keep the integrity of the taxes?